Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Peter P Waskiewicz Jr | 3efac5a | 2009-02-01 01:19:20 -0800 | [diff] [blame] | 4 | Copyright(c) 1999 - 2009 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/vmalloc.h> |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/in.h> |
| 35 | #include <linux/ip.h> |
| 36 | #include <linux/tcp.h> |
| 37 | #include <linux/ipv6.h> |
| 38 | #include <net/checksum.h> |
| 39 | #include <net/ip6_checksum.h> |
| 40 | #include <linux/ethtool.h> |
| 41 | #include <linux/if_vlan.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 42 | #include <scsi/fc/fc_fcoe.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 43 | |
| 44 | #include "ixgbe.h" |
| 45 | #include "ixgbe_common.h" |
| 46 | |
| 47 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 48 | static const char ixgbe_driver_string[] = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 49 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 50 | |
Peter P Waskiewicz Jr | ba98898 | 2009-05-17 20:58:21 +0000 | [diff] [blame] | 51 | #define DRV_VERSION "2.0.24-k2" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 52 | const char ixgbe_driver_version[] = DRV_VERSION; |
Peter P Waskiewicz Jr | 3efac5a | 2009-02-01 01:19:20 -0800 | [diff] [blame] | 53 | static char ixgbe_copyright[] = "Copyright (c) 1999-2009 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 54 | |
| 55 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 56 | [board_82598] = &ixgbe_82598_info, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 57 | [board_82599] = &ixgbe_82599_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 61 | * |
| 62 | * Wildcard entries (PCI_ANY_ID) should come last |
| 63 | * Last entry must be all 0s |
| 64 | * |
| 65 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 66 | * Class, Class Mask, private data (not used) } |
| 67 | */ |
| 68 | static struct pci_device_id ixgbe_pci_tbl[] = { |
Don Skidmore | 1e336d0 | 2009-01-26 20:57:51 -0800 | [diff] [blame] | 69 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), |
| 70 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 71 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 72 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 73 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 74 | board_82598 }, |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 75 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), |
| 76 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 77 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 78 | board_82598 }, |
Jesse Brandeburg | 8d792cd | 2008-08-08 16:24:19 -0700 | [diff] [blame] | 79 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), |
| 80 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 81 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), |
| 82 | board_82598 }, |
| 83 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), |
| 84 | board_82598 }, |
Jesse Brandeburg | b95f5fc | 2008-09-11 19:58:59 -0700 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), |
| 86 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), |
| 88 | board_82598 }, |
Don Skidmore | 2f21bdd | 2009-02-01 01:18:23 -0800 | [diff] [blame] | 89 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), |
| 90 | board_82598 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 91 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), |
| 92 | board_82599 }, |
Peter P Waskiewicz Jr | 1fcf03e | 2009-05-17 20:58:04 +0000 | [diff] [blame] | 93 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), |
| 94 | board_82599 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 95 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), |
| 96 | board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 97 | |
| 98 | /* required last entry */ |
| 99 | {0, } |
| 100 | }; |
| 101 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 102 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 103 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 104 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 105 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 106 | static struct notifier_block dca_notifier = { |
| 107 | .notifier_call = ixgbe_notify_dca, |
| 108 | .next = NULL, |
| 109 | .priority = 0 |
| 110 | }; |
| 111 | #endif |
| 112 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 113 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 114 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 115 | MODULE_LICENSE("GPL"); |
| 116 | MODULE_VERSION(DRV_VERSION); |
| 117 | |
| 118 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 119 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 120 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 121 | { |
| 122 | u32 ctrl_ext; |
| 123 | |
| 124 | /* Let firmware take over control of h/w */ |
| 125 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 126 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 127 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 131 | { |
| 132 | u32 ctrl_ext; |
| 133 | |
| 134 | /* Let firmware know the driver has taken over */ |
| 135 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 136 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 137 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 138 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 139 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 140 | /* |
| 141 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 142 | * @adapter: pointer to adapter struct |
| 143 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 144 | * @queue: queue to map the corresponding interrupt to |
| 145 | * @msix_vector: the vector to map to the corresponding queue |
| 146 | * |
| 147 | */ |
| 148 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
| 149 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 150 | { |
| 151 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 152 | struct ixgbe_hw *hw = &adapter->hw; |
| 153 | switch (hw->mac.type) { |
| 154 | case ixgbe_mac_82598EB: |
| 155 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 156 | if (direction == -1) |
| 157 | direction = 0; |
| 158 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 159 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 160 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 161 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 162 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 163 | break; |
| 164 | case ixgbe_mac_82599EB: |
| 165 | if (direction == -1) { |
| 166 | /* other causes */ |
| 167 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 168 | index = ((queue & 1) * 8); |
| 169 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 170 | ivar &= ~(0xFF << index); |
| 171 | ivar |= (msix_vector << index); |
| 172 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 173 | break; |
| 174 | } else { |
| 175 | /* tx or rx causes */ |
| 176 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 177 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 178 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 179 | ivar &= ~(0xFF << index); |
| 180 | ivar |= (msix_vector << index); |
| 181 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 182 | break; |
| 183 | } |
| 184 | default: |
| 185 | break; |
| 186 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 189 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
| 190 | u64 qmask) |
| 191 | { |
| 192 | u32 mask; |
| 193 | |
| 194 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 195 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 196 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
| 197 | } else { |
| 198 | mask = (qmask & 0xFFFFFFFF); |
| 199 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 200 | mask = (qmask >> 32); |
| 201 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
| 202 | } |
| 203 | } |
| 204 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 205 | static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 206 | struct ixgbe_tx_buffer |
| 207 | *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 208 | { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 209 | tx_buffer_info->dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 210 | if (tx_buffer_info->skb) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 211 | skb_dma_unmap(&adapter->pdev->dev, tx_buffer_info->skb, |
| 212 | DMA_TO_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 213 | dev_kfree_skb_any(tx_buffer_info->skb); |
| 214 | tx_buffer_info->skb = NULL; |
| 215 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 216 | tx_buffer_info->time_stamp = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 217 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 218 | } |
| 219 | |
| 220 | static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 221 | struct ixgbe_ring *tx_ring, |
| 222 | unsigned int eop) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 223 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 224 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 225 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 226 | /* Detect a transmit hang in hardware, this serializes the |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 227 | * check with the clearing of time_stamp and movement of eop */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 228 | adapter->detect_tx_hung = false; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 229 | if (tx_ring->tx_buffer_info[eop].time_stamp && |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 230 | time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) && |
| 231 | !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) { |
| 232 | /* detected Tx unit hang */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 233 | union ixgbe_adv_tx_desc *tx_desc; |
| 234 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 235 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 236 | " Tx Queue <%d>\n" |
| 237 | " TDH, TDT <%x>, <%x>\n" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 238 | " next_to_use <%x>\n" |
| 239 | " next_to_clean <%x>\n" |
| 240 | "tx_buffer_info[next_to_clean]\n" |
| 241 | " time_stamp <%lx>\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 242 | " jiffies <%lx>\n", |
| 243 | tx_ring->queue_index, |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 244 | IXGBE_READ_REG(hw, tx_ring->head), |
| 245 | IXGBE_READ_REG(hw, tx_ring->tail), |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 246 | tx_ring->next_to_use, eop, |
| 247 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 248 | return true; |
| 249 | } |
| 250 | |
| 251 | return false; |
| 252 | } |
| 253 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 254 | #define IXGBE_MAX_TXD_PWR 14 |
| 255 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 256 | |
| 257 | /* Tx Descriptors needed, worst case */ |
| 258 | #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \ |
| 259 | (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) |
| 260 | #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 261 | MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 262 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 263 | static void ixgbe_tx_timeout(struct net_device *netdev); |
| 264 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 265 | /** |
| 266 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 267 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 268 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 269 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 270 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 271 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 272 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 273 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 274 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 275 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 276 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 277 | unsigned int i, eop, count = 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 278 | unsigned int total_bytes = 0, total_packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 279 | |
| 280 | i = tx_ring->next_to_clean; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 281 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 282 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 283 | |
| 284 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 285 | (count < tx_ring->work_limit)) { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 286 | bool cleaned = false; |
| 287 | for ( ; !cleaned; count++) { |
| 288 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 289 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 290 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 291 | cleaned = (i == eop); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 292 | skb = tx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 293 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 294 | if (cleaned && skb) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 295 | unsigned int segs, bytecount; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 296 | |
| 297 | /* gso_segs is currently only valid for tcp */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 298 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
| 299 | /* multiply data chunks by size of headers */ |
| 300 | bytecount = ((segs - 1) * skb_headlen(skb)) + |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 301 | skb->len; |
| 302 | total_packets += segs; |
| 303 | total_bytes += bytecount; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 304 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 305 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 306 | ixgbe_unmap_and_free_tx_resource(adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 307 | tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 308 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 309 | tx_desc->wb.status = 0; |
| 310 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 311 | i++; |
| 312 | if (i == tx_ring->count) |
| 313 | i = 0; |
| 314 | } |
| 315 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 316 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 317 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 318 | } |
| 319 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 320 | tx_ring->next_to_clean = i; |
| 321 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 322 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 323 | if (unlikely(count && netif_carrier_ok(netdev) && |
| 324 | (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 325 | /* Make sure that anybody stopping the queue after this |
| 326 | * sees the new next_to_clean. |
| 327 | */ |
| 328 | smp_mb(); |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 329 | if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) && |
| 330 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 331 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 332 | ++adapter->restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 333 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 334 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 335 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 336 | if (adapter->detect_tx_hung) { |
| 337 | if (ixgbe_check_tx_hang(adapter, tx_ring, i)) { |
| 338 | /* schedule immediate reset if we believe we hung */ |
| 339 | DPRINTK(PROBE, INFO, |
| 340 | "tx hang %d detected, resetting adapter\n", |
| 341 | adapter->tx_timeout_count + 1); |
| 342 | ixgbe_tx_timeout(adapter->netdev); |
| 343 | } |
| 344 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 345 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 346 | /* re-arm the interrupt */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 347 | if (count >= tx_ring->work_limit) |
| 348 | ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 349 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 350 | tx_ring->total_bytes += total_bytes; |
| 351 | tx_ring->total_packets += total_packets; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 352 | tx_ring->stats.packets += total_packets; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 353 | tx_ring->stats.bytes += total_bytes; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 354 | adapter->net_stats.tx_bytes += total_bytes; |
| 355 | adapter->net_stats.tx_packets += total_packets; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 356 | return (count < tx_ring->work_limit); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 359 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 360 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 361 | struct ixgbe_ring *rx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 362 | { |
| 363 | u32 rxctrl; |
| 364 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 365 | int q = rx_ring - adapter->rx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 366 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 367 | if (rx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 368 | rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 369 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 370 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 371 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 372 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 373 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 374 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 375 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 376 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 377 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 378 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
Don Skidmore | 15005a3 | 2009-01-19 16:54:13 -0800 | [diff] [blame] | 379 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
| 380 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 381 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 382 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 383 | rx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 384 | } |
| 385 | put_cpu(); |
| 386 | } |
| 387 | |
| 388 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 389 | struct ixgbe_ring *tx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 390 | { |
| 391 | u32 txctrl; |
| 392 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 393 | int q = tx_ring - adapter->tx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 394 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 395 | if (tx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 396 | txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 397 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 398 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 399 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 400 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 401 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 402 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 403 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 404 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 405 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 406 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 407 | tx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 408 | } |
| 409 | put_cpu(); |
| 410 | } |
| 411 | |
| 412 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 413 | { |
| 414 | int i; |
| 415 | |
| 416 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 417 | return; |
| 418 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 419 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 420 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 421 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 422 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 423 | adapter->tx_ring[i].cpu = -1; |
| 424 | ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]); |
| 425 | } |
| 426 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 427 | adapter->rx_ring[i].cpu = -1; |
| 428 | ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]); |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 433 | { |
| 434 | struct net_device *netdev = dev_get_drvdata(dev); |
| 435 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 436 | unsigned long event = *(unsigned long *)data; |
| 437 | |
| 438 | switch (event) { |
| 439 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 440 | /* if we're already enabled, don't do it again */ |
| 441 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 442 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 443 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 444 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 445 | ixgbe_setup_dca(adapter); |
| 446 | break; |
| 447 | } |
| 448 | /* Fall Through since DCA is disabled. */ |
| 449 | case DCA_PROVIDER_REMOVE: |
| 450 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 451 | dca_remove_requester(dev); |
| 452 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 453 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 454 | } |
| 455 | break; |
| 456 | } |
| 457 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 458 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 459 | } |
| 460 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 461 | #endif /* CONFIG_IXGBE_DCA */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 462 | /** |
| 463 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 464 | * @adapter: board private structure |
| 465 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 466 | * @status: hardware indication of status of receive |
| 467 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 468 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 469 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 470 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 471 | struct sk_buff *skb, u8 status, |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 472 | struct ixgbe_ring *ring, |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 473 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 474 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 475 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 476 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 477 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 478 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 479 | |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 480 | skb_record_rx_queue(skb, ring->queue_index); |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 481 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 482 | if (adapter->vlgrp && is_vlan && (tag != 0)) |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 483 | vlan_gro_receive(napi, adapter->vlgrp, tag, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 484 | else |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 485 | napi_gro_receive(napi, skb); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 486 | } else { |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 487 | if (adapter->vlgrp && is_vlan && (tag != 0)) |
| 488 | vlan_hwaccel_rx(skb, adapter->vlgrp, tag); |
| 489 | else |
| 490 | netif_rx(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 494 | /** |
| 495 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 496 | * @adapter: address of board private structure |
| 497 | * @status_err: hardware indication of status of receive |
| 498 | * @skb: skb currently being received and modified |
| 499 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 500 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 501 | u32 status_err, struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 502 | { |
| 503 | skb->ip_summed = CHECKSUM_NONE; |
| 504 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 505 | /* Rx csum disabled */ |
| 506 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 507 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 508 | |
| 509 | /* if IP and error */ |
| 510 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 511 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 512 | adapter->hw_csum_rx_error++; |
| 513 | return; |
| 514 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 515 | |
| 516 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 517 | return; |
| 518 | |
| 519 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
| 520 | adapter->hw_csum_rx_error++; |
| 521 | return; |
| 522 | } |
| 523 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 524 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 525 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 526 | adapter->hw_csum_rx_good++; |
| 527 | } |
| 528 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 529 | static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw, |
| 530 | struct ixgbe_ring *rx_ring, u32 val) |
| 531 | { |
| 532 | /* |
| 533 | * Force memory writes to complete before letting h/w |
| 534 | * know there are new descriptors to fetch. (Only |
| 535 | * applicable for weak-ordered memory model archs, |
| 536 | * such as IA-64). |
| 537 | */ |
| 538 | wmb(); |
| 539 | IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val); |
| 540 | } |
| 541 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 542 | /** |
| 543 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
| 544 | * @adapter: address of board private structure |
| 545 | **/ |
| 546 | static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 547 | struct ixgbe_ring *rx_ring, |
| 548 | int cleaned_count) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 549 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 550 | struct pci_dev *pdev = adapter->pdev; |
| 551 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 552 | struct ixgbe_rx_buffer *bi; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 553 | unsigned int i; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 554 | unsigned int bufsz = rx_ring->rx_buf_len + NET_IP_ALIGN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 555 | |
| 556 | i = rx_ring->next_to_use; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 557 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 558 | |
| 559 | while (cleaned_count--) { |
| 560 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 561 | |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 562 | if (!bi->page_dma && |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 563 | (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 564 | if (!bi->page) { |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 565 | bi->page = alloc_page(GFP_ATOMIC); |
| 566 | if (!bi->page) { |
| 567 | adapter->alloc_rx_page_failed++; |
| 568 | goto no_buffers; |
| 569 | } |
| 570 | bi->page_offset = 0; |
| 571 | } else { |
| 572 | /* use a half page if we're re-using */ |
| 573 | bi->page_offset ^= (PAGE_SIZE / 2); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 574 | } |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 575 | |
| 576 | bi->page_dma = pci_map_page(pdev, bi->page, |
| 577 | bi->page_offset, |
| 578 | (PAGE_SIZE / 2), |
| 579 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 582 | if (!bi->skb) { |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 583 | struct sk_buff *skb; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 584 | skb = netdev_alloc_skb(adapter->netdev, bufsz); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 585 | |
| 586 | if (!skb) { |
| 587 | adapter->alloc_rx_buff_failed++; |
| 588 | goto no_buffers; |
| 589 | } |
| 590 | |
| 591 | /* |
| 592 | * Make buffer alignment 2 beyond a 16 byte boundary |
| 593 | * this will result in a 16 byte aligned IP header after |
| 594 | * the 14 byte MAC header is removed |
| 595 | */ |
| 596 | skb_reserve(skb, NET_IP_ALIGN); |
| 597 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 598 | bi->skb = skb; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 599 | bi->dma = pci_map_single(pdev, skb->data, bufsz, |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 600 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 601 | } |
| 602 | /* Refresh the desc even if buffer_addrs didn't change because |
| 603 | * each write-back erases this info. */ |
| 604 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 605 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 606 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 607 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 608 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | i++; |
| 612 | if (i == rx_ring->count) |
| 613 | i = 0; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 614 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 615 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 616 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 617 | no_buffers: |
| 618 | if (rx_ring->next_to_use != i) { |
| 619 | rx_ring->next_to_use = i; |
| 620 | if (i-- == 0) |
| 621 | i = (rx_ring->count - 1); |
| 622 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 623 | ixgbe_release_rx_desc(&adapter->hw, rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 627 | static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc) |
| 628 | { |
| 629 | return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 630 | } |
| 631 | |
| 632 | static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc) |
| 633 | { |
| 634 | return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 635 | } |
| 636 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 637 | static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc) |
| 638 | { |
| 639 | return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & |
| 640 | IXGBE_RXDADV_RSCCNT_MASK) >> |
| 641 | IXGBE_RXDADV_RSCCNT_SHIFT; |
| 642 | } |
| 643 | |
| 644 | /** |
| 645 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet |
| 646 | * @skb: pointer to the last skb in the rsc queue |
| 647 | * |
| 648 | * This function changes a queue full of hw rsc buffers into a completed |
| 649 | * packet. It uses the ->prev pointers to find the first packet and then |
| 650 | * turns it into the frag list owner. |
| 651 | **/ |
| 652 | static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb) |
| 653 | { |
| 654 | unsigned int frag_list_size = 0; |
| 655 | |
| 656 | while (skb->prev) { |
| 657 | struct sk_buff *prev = skb->prev; |
| 658 | frag_list_size += skb->len; |
| 659 | skb->prev = NULL; |
| 660 | skb = prev; |
| 661 | } |
| 662 | |
| 663 | skb_shinfo(skb)->frag_list = skb->next; |
| 664 | skb->next = NULL; |
| 665 | skb->len += frag_list_size; |
| 666 | skb->data_len += frag_list_size; |
| 667 | skb->truesize += frag_list_size; |
| 668 | return skb; |
| 669 | } |
| 670 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 671 | static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 672 | struct ixgbe_ring *rx_ring, |
| 673 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 674 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 675 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 676 | struct pci_dev *pdev = adapter->pdev; |
| 677 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 678 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 679 | struct sk_buff *skb; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 680 | unsigned int i, rsc_count = 0; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 681 | u32 len, staterr; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 682 | u16 hdr_info; |
| 683 | bool cleaned = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 684 | int cleaned_count = 0; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 685 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 686 | |
| 687 | i = rx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 688 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 689 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 690 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 691 | |
| 692 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 693 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 694 | if (*work_done >= work_to_do) |
| 695 | break; |
| 696 | (*work_done)++; |
| 697 | |
| 698 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 699 | hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc)); |
| 700 | len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 701 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 702 | if (hdr_info & IXGBE_RXDADV_SPH) |
| 703 | adapter->rx_hdr_split++; |
| 704 | if (len > IXGBE_RX_HDR_SIZE) |
| 705 | len = IXGBE_RX_HDR_SIZE; |
| 706 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 707 | } else { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 708 | len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 709 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 710 | |
| 711 | cleaned = true; |
| 712 | skb = rx_buffer_info->skb; |
| 713 | prefetch(skb->data - NET_IP_ALIGN); |
| 714 | rx_buffer_info->skb = NULL; |
| 715 | |
Alexander Duyck | 21fa4e6 | 2009-06-04 15:59:49 +0000 | [diff] [blame] | 716 | if (rx_buffer_info->dma) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 717 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 718 | rx_ring->rx_buf_len, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 719 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 720 | skb_put(skb, len); |
| 721 | } |
| 722 | |
| 723 | if (upper_len) { |
| 724 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 725 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 726 | rx_buffer_info->page_dma = 0; |
| 727 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 728 | rx_buffer_info->page, |
| 729 | rx_buffer_info->page_offset, |
| 730 | upper_len); |
| 731 | |
| 732 | if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) || |
| 733 | (page_count(rx_buffer_info->page) != 1)) |
| 734 | rx_buffer_info->page = NULL; |
| 735 | else |
| 736 | get_page(rx_buffer_info->page); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 737 | |
| 738 | skb->len += upper_len; |
| 739 | skb->data_len += upper_len; |
| 740 | skb->truesize += upper_len; |
| 741 | } |
| 742 | |
| 743 | i++; |
| 744 | if (i == rx_ring->count) |
| 745 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 746 | |
| 747 | next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 748 | prefetch(next_rxd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 749 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 750 | |
Peter P Waskiewicz Jr | df647b5 | 2009-06-04 16:00:47 +0000 | [diff] [blame] | 751 | if (adapter->flags & IXGBE_FLAG2_RSC_CAPABLE) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 752 | rsc_count = ixgbe_get_rsc_count(rx_desc); |
| 753 | |
| 754 | if (rsc_count) { |
| 755 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> |
| 756 | IXGBE_RXDADV_NEXTP_SHIFT; |
| 757 | next_buffer = &rx_ring->rx_buffer_info[nextp]; |
| 758 | rx_ring->rsc_count += (rsc_count - 1); |
| 759 | } else { |
| 760 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 761 | } |
| 762 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 763 | if (staterr & IXGBE_RXD_STAT_EOP) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 764 | if (skb->prev) |
| 765 | skb = ixgbe_transform_rsc_queue(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 766 | rx_ring->stats.packets++; |
| 767 | rx_ring->stats.bytes += skb->len; |
| 768 | } else { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 769 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
| 770 | rx_buffer_info->skb = next_buffer->skb; |
| 771 | rx_buffer_info->dma = next_buffer->dma; |
| 772 | next_buffer->skb = skb; |
| 773 | next_buffer->dma = 0; |
| 774 | } else { |
| 775 | skb->next = next_buffer->skb; |
| 776 | skb->next->prev = skb; |
| 777 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 778 | adapter->non_eop_descs++; |
| 779 | goto next_desc; |
| 780 | } |
| 781 | |
| 782 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { |
| 783 | dev_kfree_skb_irq(skb); |
| 784 | goto next_desc; |
| 785 | } |
| 786 | |
| 787 | ixgbe_rx_checksum(adapter, staterr, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 788 | |
| 789 | /* probably a little skewed due to removing CRC */ |
| 790 | total_rx_bytes += skb->len; |
| 791 | total_rx_packets++; |
| 792 | |
Jesse Brandeburg | 74ce8dd | 2008-09-11 20:03:23 -0700 | [diff] [blame] | 793 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 794 | #ifdef IXGBE_FCOE |
| 795 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
| 796 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 797 | if (!ixgbe_fcoe_ddp(adapter, rx_desc, skb)) |
| 798 | goto next_desc; |
| 799 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 800 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 801 | |
| 802 | next_desc: |
| 803 | rx_desc->wb.upper.status_error = 0; |
| 804 | |
| 805 | /* return some buffers to hardware, one at a time is too slow */ |
| 806 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 807 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 808 | cleaned_count = 0; |
| 809 | } |
| 810 | |
| 811 | /* use prefetched values */ |
| 812 | rx_desc = next_rxd; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 813 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 814 | |
| 815 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 818 | rx_ring->next_to_clean = i; |
| 819 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); |
| 820 | |
| 821 | if (cleaned_count) |
| 822 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 823 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 824 | rx_ring->total_packets += total_rx_packets; |
| 825 | rx_ring->total_bytes += total_rx_bytes; |
| 826 | adapter->net_stats.rx_bytes += total_rx_bytes; |
| 827 | adapter->net_stats.rx_packets += total_rx_packets; |
| 828 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 829 | return cleaned; |
| 830 | } |
| 831 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 832 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 833 | /** |
| 834 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 835 | * @adapter: board private structure |
| 836 | * |
| 837 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 838 | * interrupts. |
| 839 | **/ |
| 840 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 841 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 842 | struct ixgbe_q_vector *q_vector; |
| 843 | int i, j, q_vectors, v_idx, r_idx; |
| 844 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 845 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 846 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 847 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 848 | /* |
| 849 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 850 | * corresponding register. |
| 851 | */ |
| 852 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 853 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 854 | /* XXX for_each_bit(...) */ |
| 855 | r_idx = find_first_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 856 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 857 | |
| 858 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 859 | j = adapter->rx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 860 | ixgbe_set_ivar(adapter, 0, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 861 | r_idx = find_next_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 862 | adapter->num_rx_queues, |
| 863 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 864 | } |
| 865 | r_idx = find_first_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 866 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 867 | |
| 868 | for (i = 0; i < q_vector->txr_count; i++) { |
| 869 | j = adapter->tx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 870 | ixgbe_set_ivar(adapter, 1, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 871 | r_idx = find_next_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 872 | adapter->num_tx_queues, |
| 873 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 874 | } |
| 875 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 876 | /* if this is a tx only vector halve the interrupt rate */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 877 | if (q_vector->txr_count && !q_vector->rxr_count) |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 878 | q_vector->eitr = (adapter->eitr_param >> 1); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 879 | else if (q_vector->rxr_count) |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 880 | /* rx only */ |
| 881 | q_vector->eitr = adapter->eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 882 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 883 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 884 | } |
| 885 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 886 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 887 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
| 888 | v_idx); |
| 889 | else if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 890 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 891 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 892 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 893 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 894 | mask = IXGBE_EIMS_ENABLE_MASK; |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 895 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 896 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 899 | enum latency_range { |
| 900 | lowest_latency = 0, |
| 901 | low_latency = 1, |
| 902 | bulk_latency = 2, |
| 903 | latency_invalid = 255 |
| 904 | }; |
| 905 | |
| 906 | /** |
| 907 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
| 908 | * @adapter: pointer to adapter |
| 909 | * @eitr: eitr setting (ints per sec) to give last timeslice |
| 910 | * @itr_setting: current throttle rate in ints/second |
| 911 | * @packets: the number of packets during this measurement interval |
| 912 | * @bytes: the number of bytes during this measurement interval |
| 913 | * |
| 914 | * Stores a new ITR value based on packets and byte |
| 915 | * counts during the last interrupt. The advantage of per interrupt |
| 916 | * computation is faster updates and more accurate ITR for the current |
| 917 | * traffic pattern. Constants in this function were computed |
| 918 | * based on theoretical maximum wire speed and thresholds were set based |
| 919 | * on testing data as well as attempting to minimize response time |
| 920 | * while increasing bulk throughput. |
| 921 | * this functionality is controlled by the InterruptThrottleRate module |
| 922 | * parameter (see ixgbe_param.c) |
| 923 | **/ |
| 924 | static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 925 | u32 eitr, u8 itr_setting, |
| 926 | int packets, int bytes) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 927 | { |
| 928 | unsigned int retval = itr_setting; |
| 929 | u32 timepassed_us; |
| 930 | u64 bytes_perint; |
| 931 | |
| 932 | if (packets == 0) |
| 933 | goto update_itr_done; |
| 934 | |
| 935 | |
| 936 | /* simple throttlerate management |
| 937 | * 0-20MB/s lowest (100000 ints/s) |
| 938 | * 20-100MB/s low (20000 ints/s) |
| 939 | * 100-1249MB/s bulk (8000 ints/s) |
| 940 | */ |
| 941 | /* what was last interrupt timeslice? */ |
| 942 | timepassed_us = 1000000/eitr; |
| 943 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 944 | |
| 945 | switch (itr_setting) { |
| 946 | case lowest_latency: |
| 947 | if (bytes_perint > adapter->eitr_low) |
| 948 | retval = low_latency; |
| 949 | break; |
| 950 | case low_latency: |
| 951 | if (bytes_perint > adapter->eitr_high) |
| 952 | retval = bulk_latency; |
| 953 | else if (bytes_perint <= adapter->eitr_low) |
| 954 | retval = lowest_latency; |
| 955 | break; |
| 956 | case bulk_latency: |
| 957 | if (bytes_perint <= adapter->eitr_high) |
| 958 | retval = low_latency; |
| 959 | break; |
| 960 | } |
| 961 | |
| 962 | update_itr_done: |
| 963 | return retval; |
| 964 | } |
| 965 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 966 | /** |
| 967 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 968 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 969 | * |
| 970 | * This function is made to be called by ethtool and by the driver |
| 971 | * when it needs to update EITR registers at runtime. Hardware |
| 972 | * specific quirks/differences are taken care of here. |
| 973 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 974 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 975 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 976 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 977 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 978 | int v_idx = q_vector->v_idx; |
| 979 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); |
| 980 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 981 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 982 | /* must write high and low 16 bits to reset counter */ |
| 983 | itr_reg |= (itr_reg << 16); |
| 984 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 985 | /* |
| 986 | * set the WDIS bit to not clear the timer bits and cause an |
| 987 | * immediate assertion of the interrupt |
| 988 | */ |
| 989 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
| 990 | } |
| 991 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 992 | } |
| 993 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 994 | static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector) |
| 995 | { |
| 996 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 997 | u32 new_itr; |
| 998 | u8 current_itr, ret_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 999 | int i, r_idx; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1000 | struct ixgbe_ring *rx_ring, *tx_ring; |
| 1001 | |
| 1002 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1003 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1004 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1005 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1006 | q_vector->tx_itr, |
| 1007 | tx_ring->total_packets, |
| 1008 | tx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1009 | /* if the result for this queue would decrease interrupt |
| 1010 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1011 | q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1012 | q_vector->tx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1013 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1014 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1018 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1019 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1020 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1021 | q_vector->rx_itr, |
| 1022 | rx_ring->total_packets, |
| 1023 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1024 | /* if the result for this queue would decrease interrupt |
| 1025 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1026 | q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1027 | q_vector->rx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1028 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1029 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1030 | } |
| 1031 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1032 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1033 | |
| 1034 | switch (current_itr) { |
| 1035 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1036 | case lowest_latency: |
| 1037 | new_itr = 100000; |
| 1038 | break; |
| 1039 | case low_latency: |
| 1040 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1041 | break; |
| 1042 | case bulk_latency: |
| 1043 | default: |
| 1044 | new_itr = 8000; |
| 1045 | break; |
| 1046 | } |
| 1047 | |
| 1048 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1049 | /* do an exponential smoothing */ |
| 1050 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1051 | |
| 1052 | /* save the algorithm value here, not the smoothed one */ |
| 1053 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1054 | |
| 1055 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | return; |
| 1059 | } |
| 1060 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1061 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 1062 | { |
| 1063 | struct ixgbe_hw *hw = &adapter->hw; |
| 1064 | |
| 1065 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 1066 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
| 1067 | DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n"); |
| 1068 | /* write to clear the interrupt */ |
| 1069 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1070 | } |
| 1071 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1072 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1073 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 1074 | { |
| 1075 | struct ixgbe_hw *hw = &adapter->hw; |
| 1076 | |
| 1077 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 1078 | /* Clear the interrupt */ |
| 1079 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1080 | schedule_work(&adapter->multispeed_fiber_task); |
| 1081 | } else if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 1082 | /* Clear the interrupt */ |
| 1083 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
| 1084 | schedule_work(&adapter->sfp_config_module_task); |
| 1085 | } else { |
| 1086 | /* Interrupt isn't for us... */ |
| 1087 | return; |
| 1088 | } |
| 1089 | } |
| 1090 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1091 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 1092 | { |
| 1093 | struct ixgbe_hw *hw = &adapter->hw; |
| 1094 | |
| 1095 | adapter->lsc_int++; |
| 1096 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 1097 | adapter->link_check_timeout = jiffies; |
| 1098 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1099 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
| 1100 | schedule_work(&adapter->watchdog_task); |
| 1101 | } |
| 1102 | } |
| 1103 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1104 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 1105 | { |
| 1106 | struct net_device *netdev = data; |
| 1107 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1108 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1109 | u32 eicr; |
| 1110 | |
| 1111 | /* |
| 1112 | * Workaround for Silicon errata. Use clear-by-write instead |
| 1113 | * of clear-by-read. Reading with EICS will return the |
| 1114 | * interrupt causes without clearing, which later be done |
| 1115 | * with the write to EICR. |
| 1116 | */ |
| 1117 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 1118 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1119 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1120 | if (eicr & IXGBE_EICR_LSC) |
| 1121 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1122 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1123 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 1124 | ixgbe_check_fan_failure(adapter, eicr); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1125 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 1126 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1127 | ixgbe_check_sfp_event(adapter, eicr); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 1128 | |
| 1129 | /* Handle Flow Director Full threshold interrupt */ |
| 1130 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 1131 | int i; |
| 1132 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR); |
| 1133 | /* Disable transmits before FDIR Re-initialization */ |
| 1134 | netif_tx_stop_all_queues(netdev); |
| 1135 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1136 | struct ixgbe_ring *tx_ring = |
| 1137 | &adapter->tx_ring[i]; |
| 1138 | if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE, |
| 1139 | &tx_ring->reinit_state)) |
| 1140 | schedule_work(&adapter->fdir_reinit_task); |
| 1141 | } |
| 1142 | } |
| 1143 | } |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1144 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1145 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1146 | |
| 1147 | return IRQ_HANDLED; |
| 1148 | } |
| 1149 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1150 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 1151 | u64 qmask) |
| 1152 | { |
| 1153 | u32 mask; |
| 1154 | |
| 1155 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1156 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1157 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 1158 | } else { |
| 1159 | mask = (qmask & 0xFFFFFFFF); |
| 1160 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask); |
| 1161 | mask = (qmask >> 32); |
| 1162 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask); |
| 1163 | } |
| 1164 | /* skip the flush */ |
| 1165 | } |
| 1166 | |
| 1167 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
| 1168 | u64 qmask) |
| 1169 | { |
| 1170 | u32 mask; |
| 1171 | |
| 1172 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1173 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1174 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask); |
| 1175 | } else { |
| 1176 | mask = (qmask & 0xFFFFFFFF); |
| 1177 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask); |
| 1178 | mask = (qmask >> 32); |
| 1179 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask); |
| 1180 | } |
| 1181 | /* skip the flush */ |
| 1182 | } |
| 1183 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1184 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 1185 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1186 | struct ixgbe_q_vector *q_vector = data; |
| 1187 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1188 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1189 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1190 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1191 | if (!q_vector->txr_count) |
| 1192 | return IRQ_HANDLED; |
| 1193 | |
| 1194 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1195 | for (i = 0; i < q_vector->txr_count; i++) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1196 | tx_ring = &(adapter->tx_ring[r_idx]); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1197 | tx_ring->total_bytes = 0; |
| 1198 | tx_ring->total_packets = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1199 | 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] | 1200 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1201 | } |
| 1202 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1203 | /* disable interrupts on this vector only */ |
| 1204 | ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1205 | napi_schedule(&q_vector->napi); |
| 1206 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1207 | return IRQ_HANDLED; |
| 1208 | } |
| 1209 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1210 | /** |
| 1211 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 1212 | * @irq: unused |
| 1213 | * @data: pointer to our q_vector struct for this interrupt vector |
| 1214 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1215 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 1216 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1217 | struct ixgbe_q_vector *q_vector = data; |
| 1218 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1219 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1220 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1221 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1222 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1223 | 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] | 1224 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1225 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1226 | rx_ring->total_bytes = 0; |
| 1227 | rx_ring->total_packets = 0; |
| 1228 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1229 | r_idx + 1); |
| 1230 | } |
| 1231 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1232 | if (!q_vector->rxr_count) |
| 1233 | return IRQ_HANDLED; |
| 1234 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1235 | 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] | 1236 | rx_ring = &(adapter->rx_ring[r_idx]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1237 | /* disable interrupts on this vector only */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1238 | ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1239 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1240 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1241 | return IRQ_HANDLED; |
| 1242 | } |
| 1243 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1244 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 1245 | { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1246 | struct ixgbe_q_vector *q_vector = data; |
| 1247 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1248 | struct ixgbe_ring *ring; |
| 1249 | int r_idx; |
| 1250 | int i; |
| 1251 | |
| 1252 | if (!q_vector->txr_count && !q_vector->rxr_count) |
| 1253 | return IRQ_HANDLED; |
| 1254 | |
| 1255 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1256 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1257 | ring = &(adapter->tx_ring[r_idx]); |
| 1258 | ring->total_bytes = 0; |
| 1259 | ring->total_packets = 0; |
| 1260 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1261 | r_idx + 1); |
| 1262 | } |
| 1263 | |
| 1264 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1265 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1266 | ring = &(adapter->rx_ring[r_idx]); |
| 1267 | ring->total_bytes = 0; |
| 1268 | ring->total_packets = 0; |
| 1269 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1270 | r_idx + 1); |
| 1271 | } |
| 1272 | |
| 1273 | /* disable interrupts on this vector only */ |
| 1274 | ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1275 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1276 | |
| 1277 | return IRQ_HANDLED; |
| 1278 | } |
| 1279 | |
| 1280 | /** |
| 1281 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 1282 | * @napi: napi struct with our devices info in it |
| 1283 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1284 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1285 | * This function is optimized for cleaning one queue only on a single |
| 1286 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1287 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1288 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 1289 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1290 | struct ixgbe_q_vector *q_vector = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1291 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1292 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1293 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1294 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1295 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1296 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1297 | 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] | 1298 | rx_ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1299 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1300 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1301 | ixgbe_update_rx_dca(adapter, rx_ring); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1302 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1303 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1304 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1305 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1306 | /* If all Rx work done, exit the polling mode */ |
| 1307 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1308 | napi_complete(napi); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1309 | if (adapter->itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1310 | ixgbe_set_itr_msix(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1311 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1312 | ixgbe_irq_enable_queues(adapter, |
| 1313 | ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | return work_done; |
| 1317 | } |
| 1318 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1319 | /** |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1320 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1321 | * @napi: napi struct with our devices info in it |
| 1322 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1323 | * |
| 1324 | * This function will clean more than one rx queue associated with a |
| 1325 | * q_vector. |
| 1326 | **/ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1327 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1328 | { |
| 1329 | struct ixgbe_q_vector *q_vector = |
| 1330 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1331 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1332 | struct ixgbe_ring *ring = NULL; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1333 | int work_done = 0, i; |
| 1334 | long r_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1335 | bool tx_clean_complete = true; |
| 1336 | |
| 1337 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1338 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1339 | ring = &(adapter->tx_ring[r_idx]); |
| 1340 | #ifdef CONFIG_IXGBE_DCA |
| 1341 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1342 | ixgbe_update_tx_dca(adapter, ring); |
| 1343 | #endif |
| 1344 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); |
| 1345 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1346 | r_idx + 1); |
| 1347 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1348 | |
| 1349 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 1350 | * the budget to go below 1 because we'll exit polling */ |
| 1351 | budget /= (q_vector->rxr_count ?: 1); |
| 1352 | budget = max(budget, 1); |
| 1353 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1354 | for (i = 0; i < q_vector->rxr_count; i++) { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1355 | ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1356 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1357 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1358 | ixgbe_update_rx_dca(adapter, ring); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1359 | #endif |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1360 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1361 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1362 | r_idx + 1); |
| 1363 | } |
| 1364 | |
| 1365 | 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] | 1366 | ring = &(adapter->rx_ring[r_idx]); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1367 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 1368 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1369 | napi_complete(napi); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1370 | if (adapter->itr_setting & 1) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1371 | ixgbe_set_itr_msix(q_vector); |
| 1372 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1373 | ixgbe_irq_enable_queues(adapter, |
| 1374 | ((u64)1 << q_vector->v_idx)); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1375 | return 0; |
| 1376 | } |
| 1377 | |
| 1378 | return work_done; |
| 1379 | } |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1380 | |
| 1381 | /** |
| 1382 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine |
| 1383 | * @napi: napi struct with our devices info in it |
| 1384 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1385 | * |
| 1386 | * This function is optimized for cleaning one queue only on a single |
| 1387 | * q_vector!!! |
| 1388 | **/ |
| 1389 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) |
| 1390 | { |
| 1391 | struct ixgbe_q_vector *q_vector = |
| 1392 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1393 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1394 | struct ixgbe_ring *tx_ring = NULL; |
| 1395 | int work_done = 0; |
| 1396 | long r_idx; |
| 1397 | |
| 1398 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1399 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1400 | #ifdef CONFIG_IXGBE_DCA |
| 1401 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1402 | ixgbe_update_tx_dca(adapter, tx_ring); |
| 1403 | #endif |
| 1404 | |
| 1405 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) |
| 1406 | work_done = budget; |
| 1407 | |
| 1408 | /* If all Rx work done, exit the polling mode */ |
| 1409 | if (work_done < budget) { |
| 1410 | napi_complete(napi); |
| 1411 | if (adapter->itr_setting & 1) |
| 1412 | ixgbe_set_itr_msix(q_vector); |
| 1413 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1414 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1415 | } |
| 1416 | |
| 1417 | return work_done; |
| 1418 | } |
| 1419 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1420 | 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] | 1421 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1422 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1423 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1424 | |
| 1425 | set_bit(r_idx, q_vector->rxr_idx); |
| 1426 | q_vector->rxr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1427 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1428 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1429 | 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] | 1430 | int t_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1431 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1432 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1433 | |
| 1434 | set_bit(t_idx, q_vector->txr_idx); |
| 1435 | q_vector->txr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1436 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1437 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1438 | /** |
| 1439 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 1440 | * @adapter: board private structure to initialize |
| 1441 | * @vectors: allotted vector count for descriptor rings |
| 1442 | * |
| 1443 | * This function maps descriptor rings to the queue-specific vectors |
| 1444 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 1445 | * one vector per ring/queue, but on a constrained vector budget, we |
| 1446 | * group the rings as "efficiently" as possible. You would add new |
| 1447 | * mapping configurations in here. |
| 1448 | **/ |
| 1449 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1450 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1451 | { |
| 1452 | int v_start = 0; |
| 1453 | int rxr_idx = 0, txr_idx = 0; |
| 1454 | int rxr_remaining = adapter->num_rx_queues; |
| 1455 | int txr_remaining = adapter->num_tx_queues; |
| 1456 | int i, j; |
| 1457 | int rqpv, tqpv; |
| 1458 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1459 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1460 | /* No mapping required if MSI-X is disabled. */ |
| 1461 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1462 | goto out; |
| 1463 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1464 | /* |
| 1465 | * The ideal configuration... |
| 1466 | * We have enough vectors to map one per queue. |
| 1467 | */ |
| 1468 | if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
| 1469 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 1470 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 1471 | |
| 1472 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 1473 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 1474 | |
| 1475 | goto out; |
| 1476 | } |
| 1477 | |
| 1478 | /* |
| 1479 | * If we don't have enough vectors for a 1-to-1 |
| 1480 | * mapping, we'll have to group them so there are |
| 1481 | * multiple queues per vector. |
| 1482 | */ |
| 1483 | /* Re-adjusting *qpv takes care of the remainder. */ |
| 1484 | for (i = v_start; i < vectors; i++) { |
| 1485 | rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i); |
| 1486 | for (j = 0; j < rqpv; j++) { |
| 1487 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 1488 | rxr_idx++; |
| 1489 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1490 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1491 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1492 | for (i = v_start; i < vectors; i++) { |
| 1493 | tqpv = DIV_ROUND_UP(txr_remaining, vectors - i); |
| 1494 | for (j = 0; j < tqpv; j++) { |
| 1495 | map_vector_to_txq(adapter, i, txr_idx); |
| 1496 | txr_idx++; |
| 1497 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1498 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1501 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1502 | return err; |
| 1503 | } |
| 1504 | |
| 1505 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1506 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 1507 | * @adapter: board private structure |
| 1508 | * |
| 1509 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 1510 | * interrupts from the kernel. |
| 1511 | **/ |
| 1512 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 1513 | { |
| 1514 | struct net_device *netdev = adapter->netdev; |
| 1515 | irqreturn_t (*handler)(int, void *); |
| 1516 | int i, vector, q_vectors, err; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1517 | int ri=0, ti=0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1518 | |
| 1519 | /* Decrement for Other and TCP Timer vectors */ |
| 1520 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1521 | |
| 1522 | /* Map the Tx/Rx rings to the vectors we were allotted. */ |
| 1523 | err = ixgbe_map_rings_to_vectors(adapter, q_vectors); |
| 1524 | if (err) |
| 1525 | goto out; |
| 1526 | |
| 1527 | #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1528 | (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \ |
| 1529 | &ixgbe_msix_clean_many) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1530 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1531 | handler = SET_HANDLER(adapter->q_vector[vector]); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1532 | |
| 1533 | if(handler == &ixgbe_msix_clean_rx) { |
| 1534 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1535 | netdev->name, "rx", ri++); |
| 1536 | } |
| 1537 | else if(handler == &ixgbe_msix_clean_tx) { |
| 1538 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1539 | netdev->name, "tx", ti++); |
| 1540 | } |
| 1541 | else |
| 1542 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1543 | netdev->name, "TxRx", vector); |
| 1544 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1545 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1546 | handler, 0, adapter->name[vector], |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1547 | adapter->q_vector[vector]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1548 | if (err) { |
| 1549 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1550 | "request_irq failed for MSIX interrupt " |
| 1551 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1552 | goto free_queue_irqs; |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | sprintf(adapter->name[vector], "%s:lsc", netdev->name); |
| 1557 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1558 | &ixgbe_msix_lsc, 0, adapter->name[vector], netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1559 | if (err) { |
| 1560 | DPRINTK(PROBE, ERR, |
| 1561 | "request_irq for msix_lsc failed: %d\n", err); |
| 1562 | goto free_queue_irqs; |
| 1563 | } |
| 1564 | |
| 1565 | return 0; |
| 1566 | |
| 1567 | free_queue_irqs: |
| 1568 | for (i = vector - 1; i >= 0; i--) |
| 1569 | free_irq(adapter->msix_entries[--vector].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1570 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1571 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 1572 | pci_disable_msix(adapter->pdev); |
| 1573 | kfree(adapter->msix_entries); |
| 1574 | adapter->msix_entries = NULL; |
| 1575 | out: |
| 1576 | return err; |
| 1577 | } |
| 1578 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1579 | static void ixgbe_set_itr(struct ixgbe_adapter *adapter) |
| 1580 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1581 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1582 | u8 current_itr; |
| 1583 | u32 new_itr = q_vector->eitr; |
| 1584 | struct ixgbe_ring *rx_ring = &adapter->rx_ring[0]; |
| 1585 | struct ixgbe_ring *tx_ring = &adapter->tx_ring[0]; |
| 1586 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1587 | q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1588 | q_vector->tx_itr, |
| 1589 | tx_ring->total_packets, |
| 1590 | tx_ring->total_bytes); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1591 | q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1592 | q_vector->rx_itr, |
| 1593 | rx_ring->total_packets, |
| 1594 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1595 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1596 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1597 | |
| 1598 | switch (current_itr) { |
| 1599 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1600 | case lowest_latency: |
| 1601 | new_itr = 100000; |
| 1602 | break; |
| 1603 | case low_latency: |
| 1604 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1605 | break; |
| 1606 | case bulk_latency: |
| 1607 | new_itr = 8000; |
| 1608 | break; |
| 1609 | default: |
| 1610 | break; |
| 1611 | } |
| 1612 | |
| 1613 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1614 | /* do an exponential smoothing */ |
| 1615 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1616 | |
| 1617 | /* save the algorithm value here, not the smoothed one */ |
| 1618 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1619 | |
| 1620 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | return; |
| 1624 | } |
| 1625 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1626 | /** |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1627 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 1628 | * @adapter: board private structure |
| 1629 | **/ |
| 1630 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter) |
| 1631 | { |
| 1632 | u32 mask; |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1633 | |
| 1634 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 1635 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 1636 | mask |= IXGBE_EIMS_GPI_SDP1; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1637 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 1638 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1639 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 1640 | mask |= IXGBE_EIMS_GPI_SDP2; |
| 1641 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 1642 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 1643 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 1644 | mask |= IXGBE_EIMS_FLOW_DIR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1645 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1646 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1647 | ixgbe_irq_enable_queues(adapter, ~0); |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1648 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1649 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1650 | |
| 1651 | /** |
| 1652 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1653 | * @irq: interrupt number |
| 1654 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1655 | **/ |
| 1656 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 1657 | { |
| 1658 | struct net_device *netdev = data; |
| 1659 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1660 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1661 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1662 | u32 eicr; |
| 1663 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1664 | /* |
| 1665 | * Workaround for silicon errata. Mask the interrupts |
| 1666 | * before the read of EICR. |
| 1667 | */ |
| 1668 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 1669 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1670 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 1671 | * therefore no explict interrupt disable is necessary */ |
| 1672 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1673 | if (!eicr) { |
| 1674 | /* shared interrupt alert! |
| 1675 | * make sure interrupts are enabled because the read will |
| 1676 | * have disabled interrupts due to EIAM */ |
| 1677 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1678 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1679 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1680 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1681 | if (eicr & IXGBE_EICR_LSC) |
| 1682 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1683 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1684 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 1685 | ixgbe_check_sfp_event(adapter, eicr); |
| 1686 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1687 | ixgbe_check_fan_failure(adapter, eicr); |
| 1688 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1689 | if (napi_schedule_prep(&(q_vector->napi))) { |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1690 | adapter->tx_ring[0].total_packets = 0; |
| 1691 | adapter->tx_ring[0].total_bytes = 0; |
| 1692 | adapter->rx_ring[0].total_packets = 0; |
| 1693 | adapter->rx_ring[0].total_bytes = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1694 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1695 | __napi_schedule(&(q_vector->napi)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | return IRQ_HANDLED; |
| 1699 | } |
| 1700 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1701 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 1702 | { |
| 1703 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1704 | |
| 1705 | for (i = 0; i < q_vectors; i++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1706 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1707 | bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES); |
| 1708 | bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES); |
| 1709 | q_vector->rxr_count = 0; |
| 1710 | q_vector->txr_count = 0; |
| 1711 | } |
| 1712 | } |
| 1713 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1714 | /** |
| 1715 | * ixgbe_request_irq - initialize interrupts |
| 1716 | * @adapter: board private structure |
| 1717 | * |
| 1718 | * Attempts to configure interrupts using the best available |
| 1719 | * capabilities of the hardware and kernel. |
| 1720 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1721 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1722 | { |
| 1723 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1724 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1725 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1726 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1727 | err = ixgbe_request_msix_irqs(adapter); |
| 1728 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 1729 | err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1730 | netdev->name, netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1731 | } else { |
| 1732 | err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1733 | netdev->name, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1734 | } |
| 1735 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1736 | if (err) |
| 1737 | DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err); |
| 1738 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1739 | return err; |
| 1740 | } |
| 1741 | |
| 1742 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 1743 | { |
| 1744 | struct net_device *netdev = adapter->netdev; |
| 1745 | |
| 1746 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1747 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1748 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1749 | q_vectors = adapter->num_msix_vectors; |
| 1750 | |
| 1751 | i = q_vectors - 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1752 | free_irq(adapter->msix_entries[i].vector, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1753 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1754 | i--; |
| 1755 | for (; i >= 0; i--) { |
| 1756 | free_irq(adapter->msix_entries[i].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1757 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | ixgbe_reset_q_vectors(adapter); |
| 1761 | } else { |
| 1762 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1763 | } |
| 1764 | } |
| 1765 | |
| 1766 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1767 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 1768 | * @adapter: board private structure |
| 1769 | **/ |
| 1770 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 1771 | { |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1772 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1773 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
| 1774 | } else { |
| 1775 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 1776 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1777 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1778 | } |
| 1779 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1780 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1781 | int i; |
| 1782 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 1783 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1784 | } else { |
| 1785 | synchronize_irq(adapter->pdev->irq); |
| 1786 | } |
| 1787 | } |
| 1788 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1789 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1790 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 1791 | * |
| 1792 | **/ |
| 1793 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 1794 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1795 | struct ixgbe_hw *hw = &adapter->hw; |
| 1796 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1797 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1798 | EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1799 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1800 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 1801 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1802 | |
| 1803 | map_vector_to_rxq(adapter, 0, 0); |
| 1804 | map_vector_to_txq(adapter, 0, 0); |
| 1805 | |
| 1806 | DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1810 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1811 | * @adapter: board private structure |
| 1812 | * |
| 1813 | * Configure the Tx unit of the MAC after a reset. |
| 1814 | **/ |
| 1815 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 1816 | { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1817 | u64 tdba; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1818 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1819 | u32 i, j, tdlen, txctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1820 | |
| 1821 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1822 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1823 | struct ixgbe_ring *ring = &adapter->tx_ring[i]; |
| 1824 | j = ring->reg_idx; |
| 1825 | tdba = ring->dma; |
| 1826 | tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1827 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j), |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1828 | (tdba & DMA_BIT_MASK(32))); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1829 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32)); |
| 1830 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen); |
| 1831 | IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0); |
| 1832 | IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0); |
| 1833 | adapter->tx_ring[i].head = IXGBE_TDH(j); |
| 1834 | adapter->tx_ring[i].tail = IXGBE_TDT(j); |
| 1835 | /* Disable Tx Head Writeback RO bit, since this hoses |
| 1836 | * bookkeeping if things aren't delivered in order. |
| 1837 | */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1838 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1839 | txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1840 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1841 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1842 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 1843 | /* We enable 8 traffic classes, DCB only */ |
| 1844 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 1845 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA | |
| 1846 | IXGBE_MTQC_8TC_8TQ)); |
| 1847 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1850 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1851 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1852 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index) |
| 1853 | { |
| 1854 | struct ixgbe_ring *rx_ring; |
| 1855 | u32 srrctl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1856 | int queue0 = 0; |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1857 | unsigned long mask; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 1858 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1859 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1860 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Alexander Duyck | 163de42 | 2009-05-07 10:39:16 +0000 | [diff] [blame] | 1861 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 1862 | int dcb_i = feature[RING_F_DCB].indices; |
Alexander Duyck | 163de42 | 2009-05-07 10:39:16 +0000 | [diff] [blame] | 1863 | if (dcb_i == 8) |
| 1864 | queue0 = index >> 4; |
| 1865 | else if (dcb_i == 4) |
| 1866 | queue0 = index >> 5; |
| 1867 | else |
| 1868 | dev_err(&adapter->pdev->dev, "Invalid DCB " |
| 1869 | "configuration\n"); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 1870 | #ifdef IXGBE_FCOE |
| 1871 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 1872 | struct ixgbe_ring_feature *f; |
| 1873 | |
| 1874 | rx_ring = &adapter->rx_ring[queue0]; |
| 1875 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 1876 | if ((queue0 == 0) && (index > rx_ring->reg_idx)) |
| 1877 | queue0 = f->mask + index - |
| 1878 | rx_ring->reg_idx - 1; |
| 1879 | } |
| 1880 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 163de42 | 2009-05-07 10:39:16 +0000 | [diff] [blame] | 1881 | } else { |
| 1882 | queue0 = index; |
| 1883 | } |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1884 | } else { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 1885 | mask = (unsigned long) feature[RING_F_RSS].mask; |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1886 | queue0 = index & mask; |
| 1887 | index = index & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1888 | } |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1889 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1890 | rx_ring = &adapter->rx_ring[queue0]; |
| 1891 | |
| 1892 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index)); |
| 1893 | |
| 1894 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 1895 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
| 1896 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 1897 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 1898 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 1899 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1900 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 1901 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
| 1902 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1903 | #else |
| 1904 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1905 | #endif |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1906 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1907 | } else { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 1908 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 1909 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1910 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1911 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1912 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1913 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl); |
| 1914 | } |
| 1915 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 1916 | static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 1917 | { |
| 1918 | u32 mrqc = 0; |
| 1919 | int mask; |
| 1920 | |
| 1921 | if (!(adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 1922 | return mrqc; |
| 1923 | |
| 1924 | mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 1925 | #ifdef CONFIG_IXGBE_DCB |
| 1926 | | IXGBE_FLAG_DCB_ENABLED |
| 1927 | #endif |
| 1928 | ); |
| 1929 | |
| 1930 | switch (mask) { |
| 1931 | case (IXGBE_FLAG_RSS_ENABLED): |
| 1932 | mrqc = IXGBE_MRQC_RSSEN; |
| 1933 | break; |
| 1934 | #ifdef CONFIG_IXGBE_DCB |
| 1935 | case (IXGBE_FLAG_DCB_ENABLED): |
| 1936 | mrqc = IXGBE_MRQC_RT8TCEN; |
| 1937 | break; |
| 1938 | #endif /* CONFIG_IXGBE_DCB */ |
| 1939 | default: |
| 1940 | break; |
| 1941 | } |
| 1942 | |
| 1943 | return mrqc; |
| 1944 | } |
| 1945 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1946 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1947 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1948 | * @adapter: board private structure |
| 1949 | * |
| 1950 | * Configure the Rx unit of the MAC after a reset. |
| 1951 | **/ |
| 1952 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 1953 | { |
| 1954 | u64 rdba; |
| 1955 | struct ixgbe_hw *hw = &adapter->hw; |
| 1956 | struct net_device *netdev = adapter->netdev; |
| 1957 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1958 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1959 | u32 rdlen, rxctrl, rxcsum; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1960 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
| 1961 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 1962 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1963 | u32 fctrl, hlreg0; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1964 | u32 reta = 0, mrqc = 0; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1965 | u32 rdrxctl; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1966 | u32 rscctrl; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1967 | int rx_buf_len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1968 | |
| 1969 | /* Decide whether to use packet split mode or not */ |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 1970 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1971 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 1972 | #ifdef IXGBE_FCOE |
| 1973 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 1974 | adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED; |
| 1975 | #endif /* IXGBE_FCOE */ |
| 1976 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1977 | /* Set the RX buffer length according to the mode */ |
| 1978 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1979 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1980 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 1981 | /* PSRTYPE must be initialized in 82599 */ |
| 1982 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 1983 | IXGBE_PSRTYPE_UDPHDR | |
| 1984 | IXGBE_PSRTYPE_IPV4HDR | |
Yi Zou | dfa12f0 | 2009-05-07 10:39:35 +0000 | [diff] [blame] | 1985 | IXGBE_PSRTYPE_IPV6HDR | |
| 1986 | IXGBE_PSRTYPE_L2HDR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1987 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype); |
| 1988 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1989 | } else { |
Peter P Waskiewicz Jr | df647b5 | 2009-06-04 16:00:47 +0000 | [diff] [blame] | 1990 | if (!(adapter->flags & IXGBE_FLAG2_RSC_ENABLED) && |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 1991 | (netdev->mtu <= ETH_DATA_LEN)) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1992 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1993 | else |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1994 | rx_buf_len = ALIGN(max_frame, 1024); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); |
| 1998 | fctrl |= IXGBE_FCTRL_BAM; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1999 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2000 | fctrl |= IXGBE_FCTRL_PMCF; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2001 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl); |
| 2002 | |
| 2003 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
| 2004 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2005 | hlreg0 &= ~IXGBE_HLREG0_JUMBOEN; |
| 2006 | else |
| 2007 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2008 | #ifdef IXGBE_FCOE |
| 2009 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 2010 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
| 2011 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2012 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 2013 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2014 | rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc); |
| 2015 | /* disable receives while setting up the descriptors */ |
| 2016 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2017 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 2018 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2019 | /* |
| 2020 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2021 | * the Base and Length of the Rx Descriptor Ring |
| 2022 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2023 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2024 | rdba = adapter->rx_ring[i].dma; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2025 | j = adapter->rx_ring[i].reg_idx; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2026 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32))); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2027 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32)); |
| 2028 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen); |
| 2029 | IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0); |
| 2030 | IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0); |
| 2031 | adapter->rx_ring[i].head = IXGBE_RDH(j); |
| 2032 | adapter->rx_ring[i].tail = IXGBE_RDT(j); |
| 2033 | adapter->rx_ring[i].rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2034 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2035 | #ifdef IXGBE_FCOE |
| 2036 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 2037 | struct ixgbe_ring_feature *f; |
| 2038 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 2039 | if ((rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 2040 | (i >= f->mask) && (i < f->mask + f->indices)) |
| 2041 | adapter->rx_ring[i].rx_buf_len = |
| 2042 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2043 | } |
| 2044 | |
| 2045 | #endif /* IXGBE_FCOE */ |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2046 | ixgbe_configure_srrctl(adapter, j); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2047 | } |
| 2048 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2049 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2050 | /* |
| 2051 | * For VMDq support of different descriptor types or |
| 2052 | * buffer sizes through the use of multiple SRRCTL |
| 2053 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 2054 | * |
| 2055 | * also, the manual doesn't mention it clearly but DCA hints |
| 2056 | * will only use queue 0's tags unless this bit is set. Side |
| 2057 | * effects of setting this bit are only that SRRCTL must be |
| 2058 | * fully programmed [0..15] |
| 2059 | */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2060 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2061 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 2062 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2063 | } |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2064 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2065 | /* Program MRQC for the distribution of queues */ |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2066 | mrqc = ixgbe_setup_mrqc(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2067 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2068 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2069 | /* Fill out redirection table */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2070 | for (i = 0, j = 0; i < 128; i++, j++) { |
| 2071 | if (j == adapter->ring_feature[RING_F_RSS].indices) |
| 2072 | j = 0; |
| 2073 | /* reta = 4-byte sliding window of |
| 2074 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2075 | reta = (reta << 8) | (j * 0x11); |
| 2076 | if ((i & 3) == 3) |
| 2077 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | /* Fill out hash function seeds */ |
| 2081 | for (i = 0; i < 10; i++) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2082 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2083 | |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2084 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2085 | mrqc |= IXGBE_MRQC_RSSEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2086 | /* Perform hash on these packet types */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2087 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2088 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2089 | | IXGBE_MRQC_RSS_FIELD_IPV4_UDP |
| 2090 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2091 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP |
| 2092 | | IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2093 | } |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2094 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2095 | |
| 2096 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2097 | |
| 2098 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED || |
| 2099 | adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) { |
| 2100 | /* Disable indicating checksum in descriptor, enables |
| 2101 | * RSS hash */ |
| 2102 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2103 | } |
| 2104 | if (!(rxcsum & IXGBE_RXCSUM_PCSD)) { |
| 2105 | /* Enable IPv4 payload checksum for UDP fragments |
| 2106 | * if PCSD is not set */ |
| 2107 | rxcsum |= IXGBE_RXCSUM_IPPCSE; |
| 2108 | } |
| 2109 | |
| 2110 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2111 | |
| 2112 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2113 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2114 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2115 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2116 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 2117 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2118 | |
Peter P Waskiewicz Jr | df647b5 | 2009-06-04 16:00:47 +0000 | [diff] [blame] | 2119 | if (adapter->flags & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2120 | /* Enable 82599 HW-RSC */ |
| 2121 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2122 | j = adapter->rx_ring[i].reg_idx; |
| 2123 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j)); |
| 2124 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2125 | /* |
Alexander Duyck | e76678d | 2009-05-17 20:57:47 +0000 | [diff] [blame] | 2126 | * we must limit the number of descriptors so that the |
| 2127 | * total size of max desc * buf_len is not greater |
| 2128 | * than 65535 |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2129 | */ |
Alexander Duyck | e76678d | 2009-05-17 20:57:47 +0000 | [diff] [blame] | 2130 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
| 2131 | #if (MAX_SKB_FRAGS > 16) |
| 2132 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2133 | #elif (MAX_SKB_FRAGS > 8) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2134 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
Alexander Duyck | e76678d | 2009-05-17 20:57:47 +0000 | [diff] [blame] | 2135 | #elif (MAX_SKB_FRAGS > 4) |
| 2136 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2137 | #else |
Alexander Duyck | e76678d | 2009-05-17 20:57:47 +0000 | [diff] [blame] | 2138 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2139 | #endif |
Alexander Duyck | e76678d | 2009-05-17 20:57:47 +0000 | [diff] [blame] | 2140 | } else { |
| 2141 | if (rx_buf_len < IXGBE_RXBUFFER_4096) |
| 2142 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2143 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) |
| 2144 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2145 | else |
| 2146 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2147 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2148 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl); |
| 2149 | } |
| 2150 | /* Disable RSC for ACK packets */ |
| 2151 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 2152 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 2153 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2156 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 2157 | { |
| 2158 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2159 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2160 | |
| 2161 | /* add VID to filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2162 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 2166 | { |
| 2167 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2168 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2169 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2170 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2171 | ixgbe_irq_disable(adapter); |
| 2172 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2173 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2174 | |
| 2175 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2176 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2177 | |
| 2178 | /* remove VID from filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2179 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2182 | static void ixgbe_vlan_rx_register(struct net_device *netdev, |
| 2183 | struct vlan_group *grp) |
| 2184 | { |
| 2185 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2186 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2187 | int i, j; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2188 | |
| 2189 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2190 | ixgbe_irq_disable(adapter); |
| 2191 | adapter->vlgrp = grp; |
| 2192 | |
| 2193 | /* |
| 2194 | * For a DCB driver, always enable VLAN tag stripping so we can |
| 2195 | * still receive traffic from a DCB-enabled host even if we're |
| 2196 | * not in DCB mode. |
| 2197 | */ |
| 2198 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2199 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 2200 | ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2201 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2202 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2203 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 2204 | ctrl |= IXGBE_VLNCTRL_VFE; |
| 2205 | /* enable VLAN tag insert/strip */ |
| 2206 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
| 2207 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2208 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
| 2209 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2210 | j = adapter->rx_ring[i].reg_idx; |
| 2211 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j)); |
| 2212 | ctrl |= IXGBE_RXDCTL_VME; |
| 2213 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl); |
| 2214 | } |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2215 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2216 | ixgbe_vlan_rx_add_vid(netdev, 0); |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2217 | |
| 2218 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2219 | ixgbe_irq_enable(adapter); |
| 2220 | } |
| 2221 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2222 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 2223 | { |
| 2224 | ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 2225 | |
| 2226 | if (adapter->vlgrp) { |
| 2227 | u16 vid; |
| 2228 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 2229 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 2230 | continue; |
| 2231 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
| 2232 | } |
| 2233 | } |
| 2234 | } |
| 2235 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2236 | static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq) |
| 2237 | { |
| 2238 | struct dev_mc_list *mc_ptr; |
| 2239 | u8 *addr = *mc_addr_ptr; |
| 2240 | *vmdq = 0; |
| 2241 | |
| 2242 | mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]); |
| 2243 | if (mc_ptr->next) |
| 2244 | *mc_addr_ptr = mc_ptr->next->dmi_addr; |
| 2245 | else |
| 2246 | *mc_addr_ptr = NULL; |
| 2247 | |
| 2248 | return addr; |
| 2249 | } |
| 2250 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2251 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2252 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2253 | * @netdev: network interface device structure |
| 2254 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2255 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 2256 | * address list or the network interface flags are updated. This routine is |
| 2257 | * responsible for configuring the hardware for proper unicast, multicast and |
| 2258 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2259 | **/ |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2260 | static void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2261 | { |
| 2262 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2263 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2264 | u32 fctrl, vlnctrl; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2265 | u8 *addr_list = NULL; |
| 2266 | int addr_count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2267 | |
| 2268 | /* Check for Promiscuous and All Multicast modes */ |
| 2269 | |
| 2270 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2271 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2272 | |
| 2273 | if (netdev->flags & IFF_PROMISC) { |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2274 | hw->addr_ctrl.user_set_promisc = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2275 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2276 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2277 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2278 | if (netdev->flags & IFF_ALLMULTI) { |
| 2279 | fctrl |= IXGBE_FCTRL_MPE; |
| 2280 | fctrl &= ~IXGBE_FCTRL_UPE; |
| 2281 | } else { |
| 2282 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 2283 | } |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2284 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2285 | hw->addr_ctrl.user_set_promisc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2289 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2290 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2291 | /* reprogram secondary unicast list */ |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 2292 | hw->mac.ops.update_uc_addr_list(hw, &netdev->uc_list); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2293 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2294 | /* reprogram multicast list */ |
| 2295 | addr_count = netdev->mc_count; |
| 2296 | if (addr_count) |
| 2297 | addr_list = netdev->mc_list->dmi_addr; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2298 | hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count, |
| 2299 | ixgbe_addr_list_itr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2300 | } |
| 2301 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2302 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 2303 | { |
| 2304 | int q_idx; |
| 2305 | struct ixgbe_q_vector *q_vector; |
| 2306 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2307 | |
| 2308 | /* legacy and MSI only use one vector */ |
| 2309 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2310 | q_vectors = 1; |
| 2311 | |
| 2312 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2313 | struct napi_struct *napi; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2314 | q_vector = adapter->q_vector[q_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2315 | napi = &q_vector->napi; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2316 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2317 | if (!q_vector->rxr_count || !q_vector->txr_count) { |
| 2318 | if (q_vector->txr_count == 1) |
| 2319 | napi->poll = &ixgbe_clean_txonly; |
| 2320 | else if (q_vector->rxr_count == 1) |
| 2321 | napi->poll = &ixgbe_clean_rxonly; |
| 2322 | } |
| 2323 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2324 | |
| 2325 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2326 | } |
| 2327 | } |
| 2328 | |
| 2329 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 2330 | { |
| 2331 | int q_idx; |
| 2332 | struct ixgbe_q_vector *q_vector; |
| 2333 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2334 | |
| 2335 | /* legacy and MSI only use one vector */ |
| 2336 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2337 | q_vectors = 1; |
| 2338 | |
| 2339 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2340 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2341 | napi_disable(&q_vector->napi); |
| 2342 | } |
| 2343 | } |
| 2344 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2345 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2346 | /* |
| 2347 | * ixgbe_configure_dcb - Configure DCB hardware |
| 2348 | * @adapter: ixgbe adapter struct |
| 2349 | * |
| 2350 | * This is called by the driver on open to configure the DCB hardware. |
| 2351 | * This is also called by the gennetlink interface when reconfiguring |
| 2352 | * the DCB state. |
| 2353 | */ |
| 2354 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 2355 | { |
| 2356 | struct ixgbe_hw *hw = &adapter->hw; |
| 2357 | u32 txdctl, vlnctrl; |
| 2358 | int i, j; |
| 2359 | |
| 2360 | ixgbe_dcb_check_config(&adapter->dcb_cfg); |
| 2361 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG); |
| 2362 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG); |
| 2363 | |
| 2364 | /* reconfigure the hardware */ |
| 2365 | ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg); |
| 2366 | |
| 2367 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2368 | j = adapter->tx_ring[i].reg_idx; |
| 2369 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2370 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2371 | txdctl |= 32; |
| 2372 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2373 | } |
| 2374 | /* Enable VLAN tag insert/strip */ |
| 2375 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2376 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2377 | vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
| 2378 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2379 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2380 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2381 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 2382 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2383 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2384 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2385 | j = adapter->rx_ring[i].reg_idx; |
| 2386 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2387 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 2388 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 2389 | } |
| 2390 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2391 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
| 2392 | } |
| 2393 | |
| 2394 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2395 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 2396 | { |
| 2397 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 2398 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2399 | int i; |
| 2400 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2401 | ixgbe_set_rx_mode(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2402 | |
| 2403 | ixgbe_restore_vlan(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2404 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2405 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 2406 | netif_set_gso_max_size(netdev, 32768); |
| 2407 | ixgbe_configure_dcb(adapter); |
| 2408 | } else { |
| 2409 | netif_set_gso_max_size(netdev, 65536); |
| 2410 | } |
| 2411 | #else |
| 2412 | netif_set_gso_max_size(netdev, 65536); |
| 2413 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2414 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 2415 | #ifdef IXGBE_FCOE |
| 2416 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 2417 | ixgbe_configure_fcoe(adapter); |
| 2418 | |
| 2419 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 2420 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2421 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2422 | adapter->tx_ring[i].atr_sample_rate = |
| 2423 | adapter->atr_sample_rate; |
| 2424 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); |
| 2425 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 2426 | ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc); |
| 2427 | } |
| 2428 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2429 | ixgbe_configure_tx(adapter); |
| 2430 | ixgbe_configure_rx(adapter); |
| 2431 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2432 | ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i], |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2433 | (adapter->rx_ring[i].count - 1)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2436 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2437 | { |
| 2438 | switch (hw->phy.type) { |
| 2439 | case ixgbe_phy_sfp_avago: |
| 2440 | case ixgbe_phy_sfp_ftl: |
| 2441 | case ixgbe_phy_sfp_intel: |
| 2442 | case ixgbe_phy_sfp_unknown: |
| 2443 | case ixgbe_phy_tw_tyco: |
| 2444 | case ixgbe_phy_tw_unknown: |
| 2445 | return true; |
| 2446 | default: |
| 2447 | return false; |
| 2448 | } |
| 2449 | } |
| 2450 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2451 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2452 | * ixgbe_sfp_link_config - set up SFP+ link |
| 2453 | * @adapter: pointer to private adapter struct |
| 2454 | **/ |
| 2455 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 2456 | { |
| 2457 | struct ixgbe_hw *hw = &adapter->hw; |
| 2458 | |
| 2459 | if (hw->phy.multispeed_fiber) { |
| 2460 | /* |
| 2461 | * In multispeed fiber setups, the device may not have |
| 2462 | * had a physical connection when the driver loaded. |
| 2463 | * If that's the case, the initial link configuration |
| 2464 | * couldn't get the MAC into 10G or 1G mode, so we'll |
| 2465 | * never have a link status change interrupt fire. |
| 2466 | * We need to try and force an autonegotiation |
| 2467 | * session, then bring up link. |
| 2468 | */ |
| 2469 | hw->mac.ops.setup_sfp(hw); |
| 2470 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
| 2471 | schedule_work(&adapter->multispeed_fiber_task); |
| 2472 | } else { |
| 2473 | /* |
| 2474 | * Direct Attach Cu and non-multispeed fiber modules |
| 2475 | * still need to be configured properly prior to |
| 2476 | * attempting link. |
| 2477 | */ |
| 2478 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK)) |
| 2479 | schedule_work(&adapter->sfp_config_module_task); |
| 2480 | } |
| 2481 | } |
| 2482 | |
| 2483 | /** |
| 2484 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2485 | * @hw: pointer to private hardware struct |
| 2486 | * |
| 2487 | * Returns 0 on success, negative on failure |
| 2488 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2489 | 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] | 2490 | { |
| 2491 | u32 autoneg; |
| 2492 | bool link_up = false; |
| 2493 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 2494 | |
| 2495 | if (hw->mac.ops.check_link) |
| 2496 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2497 | |
| 2498 | if (ret) |
| 2499 | goto link_cfg_out; |
| 2500 | |
| 2501 | if (hw->mac.ops.get_link_capabilities) |
| 2502 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 2503 | &hw->mac.autoneg); |
| 2504 | if (ret) |
| 2505 | goto link_cfg_out; |
| 2506 | |
| 2507 | if (hw->mac.ops.setup_link_speed) |
| 2508 | 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] | 2509 | link_cfg_out: |
| 2510 | return ret; |
| 2511 | } |
| 2512 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2513 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2514 | static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2515 | int rxr) |
| 2516 | { |
| 2517 | int j = adapter->rx_ring[rxr].reg_idx; |
| 2518 | int k; |
| 2519 | |
| 2520 | for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) { |
| 2521 | if (IXGBE_READ_REG(&adapter->hw, |
| 2522 | IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE) |
| 2523 | break; |
| 2524 | else |
| 2525 | msleep(1); |
| 2526 | } |
| 2527 | if (k >= IXGBE_MAX_RX_DESC_POLL) { |
| 2528 | DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d " |
| 2529 | "not set within the polling period\n", rxr); |
| 2530 | } |
| 2531 | ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr], |
| 2532 | (adapter->rx_ring[rxr].count - 1)); |
| 2533 | } |
| 2534 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2535 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 2536 | { |
| 2537 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2538 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2539 | int i, j = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2540 | int num_rx_rings = adapter->num_rx_queues; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2541 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2542 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2543 | u32 txdctl, rxdctl, mhadd; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2544 | u32 dmatxctl; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2545 | u32 gpie; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2546 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 2547 | ixgbe_get_hw_control(adapter); |
| 2548 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2549 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) || |
| 2550 | (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2551 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2552 | gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2553 | IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2554 | } else { |
| 2555 | /* MSI only */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2556 | gpie = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2557 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2558 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 2559 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 2560 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2561 | } |
| 2562 | |
| 2563 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 2564 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 2565 | * specifically only auto mask tx and rx interrupts */ |
| 2566 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2567 | } |
| 2568 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2569 | /* Enable fan failure interrupt if media type is copper */ |
| 2570 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2571 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2572 | gpie |= IXGBE_SDP1_GPIEN; |
| 2573 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2574 | } |
| 2575 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2576 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2577 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2578 | gpie |= IXGBE_SDP1_GPIEN; |
| 2579 | gpie |= IXGBE_SDP2_GPIEN; |
| 2580 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2581 | } |
| 2582 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2583 | #ifdef IXGBE_FCOE |
| 2584 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 2585 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 2586 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 2587 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2588 | |
| 2589 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2590 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2591 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 2592 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 2593 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 2594 | |
| 2595 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
| 2596 | } |
| 2597 | |
| 2598 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2599 | j = adapter->tx_ring[i].reg_idx; |
| 2600 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2601 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2602 | txdctl |= (8 << 16); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2603 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2604 | } |
| 2605 | |
| 2606 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2607 | /* DMATXCTL.EN must be set after all Tx queue config is done */ |
| 2608 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2609 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2610 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2611 | } |
| 2612 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2613 | j = adapter->tx_ring[i].reg_idx; |
| 2614 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2615 | txdctl |= IXGBE_TXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2616 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2617 | } |
| 2618 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2619 | for (i = 0; i < num_rx_rings; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2620 | j = adapter->rx_ring[i].reg_idx; |
| 2621 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2622 | /* enable PTHRESH=32 descriptors (half the internal cache) |
| 2623 | * and HTHRESH=0 descriptors (to minimize latency on fetch), |
| 2624 | * this also removes a pesky rx_no_buffer_count increment */ |
| 2625 | rxdctl |= 0x0020; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2626 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2627 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2628 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 2629 | ixgbe_rx_desc_queue_enable(adapter, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2630 | } |
| 2631 | /* enable all receives */ |
| 2632 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2633 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2634 | rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN); |
| 2635 | else |
| 2636 | rxdctl |= IXGBE_RXCTRL_RXEN; |
| 2637 | hw->mac.ops.enable_rx_dma(hw, rxdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2638 | |
| 2639 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 2640 | ixgbe_configure_msix(adapter); |
| 2641 | else |
| 2642 | ixgbe_configure_msi_and_legacy(adapter); |
| 2643 | |
| 2644 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2645 | ixgbe_napi_enable_all(adapter); |
| 2646 | |
| 2647 | /* clear any pending interrupts, may auto mask */ |
| 2648 | IXGBE_READ_REG(hw, IXGBE_EICR); |
| 2649 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2650 | ixgbe_irq_enable(adapter); |
| 2651 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2652 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 2653 | * If this adapter has a fan, check to see if we had a failure |
| 2654 | * before we enabled the interrupt. |
| 2655 | */ |
| 2656 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2657 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 2658 | if (esdp & IXGBE_ESDP_SDP1) |
| 2659 | DPRINTK(DRV, CRIT, |
| 2660 | "Fan has stopped, replace the adapter\n"); |
| 2661 | } |
| 2662 | |
| 2663 | /* |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2664 | * For hot-pluggable SFP+ devices, a new SFP+ module may have |
| 2665 | * arrived before interrupts were enabled. We need to kick off |
| 2666 | * the SFP+ module setup first, then try to bring up link. |
| 2667 | * If we're not hot-pluggable SFP+, we just need to configure link |
| 2668 | * and bring it up. |
| 2669 | */ |
| 2670 | err = hw->phy.ops.identify(hw); |
| 2671 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
| 2672 | DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err); |
| 2673 | ixgbe_down(adapter); |
| 2674 | return err; |
| 2675 | } |
| 2676 | |
| 2677 | if (ixgbe_is_sfp(hw)) { |
| 2678 | ixgbe_sfp_link_config(adapter); |
| 2679 | } else { |
| 2680 | err = ixgbe_non_sfp_link_config(hw); |
| 2681 | if (err) |
| 2682 | DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err); |
| 2683 | } |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2684 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 2685 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2686 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 2687 | &(adapter->tx_ring[i].reinit_state)); |
| 2688 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 2689 | /* enable transmits */ |
| 2690 | netif_tx_start_all_queues(netdev); |
| 2691 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2692 | /* bring the link up in the watchdog, this could race with our first |
| 2693 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2694 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2695 | adapter->link_check_timeout = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2696 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 2697 | return 0; |
| 2698 | } |
| 2699 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2700 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 2701 | { |
| 2702 | WARN_ON(in_interrupt()); |
| 2703 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
| 2704 | msleep(1); |
| 2705 | ixgbe_down(adapter); |
| 2706 | ixgbe_up(adapter); |
| 2707 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 2708 | } |
| 2709 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2710 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 2711 | { |
| 2712 | /* hardware has been reset, we need to reload some things */ |
| 2713 | ixgbe_configure(adapter); |
| 2714 | |
| 2715 | return ixgbe_up_complete(adapter); |
| 2716 | } |
| 2717 | |
| 2718 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 2719 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2720 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 2721 | int err; |
| 2722 | |
| 2723 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2724 | switch (err) { |
| 2725 | case 0: |
| 2726 | case IXGBE_ERR_SFP_NOT_PRESENT: |
| 2727 | break; |
| 2728 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
| 2729 | dev_err(&adapter->pdev->dev, "master disable timed out\n"); |
| 2730 | break; |
| 2731 | default: |
| 2732 | dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err); |
| 2733 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2734 | |
| 2735 | /* reprogram the RAR[0] in case user changed it. */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2736 | 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] | 2737 | } |
| 2738 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2739 | /** |
| 2740 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 2741 | * @adapter: board private structure |
| 2742 | * @rx_ring: ring to free buffers from |
| 2743 | **/ |
| 2744 | static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2745 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2746 | { |
| 2747 | struct pci_dev *pdev = adapter->pdev; |
| 2748 | unsigned long size; |
| 2749 | unsigned int i; |
| 2750 | |
| 2751 | /* Free all the Rx ring sk_buffs */ |
| 2752 | |
| 2753 | for (i = 0; i < rx_ring->count; i++) { |
| 2754 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 2755 | |
| 2756 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 2757 | if (rx_buffer_info->dma) { |
| 2758 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2759 | rx_ring->rx_buf_len, |
| 2760 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2761 | rx_buffer_info->dma = 0; |
| 2762 | } |
| 2763 | if (rx_buffer_info->skb) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2764 | struct sk_buff *skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2765 | rx_buffer_info->skb = NULL; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2766 | do { |
| 2767 | struct sk_buff *this = skb; |
| 2768 | skb = skb->prev; |
| 2769 | dev_kfree_skb(this); |
| 2770 | } while (skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2771 | } |
| 2772 | if (!rx_buffer_info->page) |
| 2773 | continue; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2774 | pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2, |
| 2775 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2776 | rx_buffer_info->page_dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2777 | put_page(rx_buffer_info->page); |
| 2778 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2779 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 2783 | memset(rx_ring->rx_buffer_info, 0, size); |
| 2784 | |
| 2785 | /* Zero out the descriptor ring */ |
| 2786 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2787 | |
| 2788 | rx_ring->next_to_clean = 0; |
| 2789 | rx_ring->next_to_use = 0; |
| 2790 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 2791 | if (rx_ring->head) |
| 2792 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 2793 | if (rx_ring->tail) |
| 2794 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | /** |
| 2798 | * ixgbe_clean_tx_ring - Free Tx Buffers |
| 2799 | * @adapter: board private structure |
| 2800 | * @tx_ring: ring to be cleaned |
| 2801 | **/ |
| 2802 | static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2803 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2804 | { |
| 2805 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 2806 | unsigned long size; |
| 2807 | unsigned int i; |
| 2808 | |
| 2809 | /* Free all the Tx ring sk_buffs */ |
| 2810 | |
| 2811 | for (i = 0; i < tx_ring->count; i++) { |
| 2812 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 2813 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 2814 | } |
| 2815 | |
| 2816 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 2817 | memset(tx_ring->tx_buffer_info, 0, size); |
| 2818 | |
| 2819 | /* Zero out the descriptor ring */ |
| 2820 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2821 | |
| 2822 | tx_ring->next_to_use = 0; |
| 2823 | tx_ring->next_to_clean = 0; |
| 2824 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 2825 | if (tx_ring->head) |
| 2826 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 2827 | if (tx_ring->tail) |
| 2828 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2832 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2833 | * @adapter: board private structure |
| 2834 | **/ |
| 2835 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 2836 | { |
| 2837 | int i; |
| 2838 | |
| 2839 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2840 | ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
| 2841 | } |
| 2842 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2843 | /** |
| 2844 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2845 | * @adapter: board private structure |
| 2846 | **/ |
| 2847 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 2848 | { |
| 2849 | int i; |
| 2850 | |
| 2851 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2852 | ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
| 2853 | } |
| 2854 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2855 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 2856 | { |
| 2857 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2858 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2859 | u32 rxctrl; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2860 | u32 txdctl; |
| 2861 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2862 | |
| 2863 | /* signal that we are down to the interrupt handler */ |
| 2864 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 2865 | |
| 2866 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2867 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2868 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2869 | |
| 2870 | netif_tx_disable(netdev); |
| 2871 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2872 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2873 | msleep(10); |
| 2874 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2875 | netif_tx_stop_all_queues(netdev); |
| 2876 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2877 | ixgbe_irq_disable(adapter); |
| 2878 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2879 | ixgbe_napi_disable_all(adapter); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2880 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2881 | del_timer_sync(&adapter->watchdog_timer); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2882 | cancel_work_sync(&adapter->watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2883 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 2884 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 2885 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 2886 | cancel_work_sync(&adapter->fdir_reinit_task); |
| 2887 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2888 | /* disable transmits in the hardware now that interrupts are off */ |
| 2889 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2890 | j = adapter->tx_ring[i].reg_idx; |
| 2891 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2892 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), |
| 2893 | (txdctl & ~IXGBE_TXDCTL_ENABLE)); |
| 2894 | } |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 2895 | /* Disable the Tx DMA engine on 82599 */ |
| 2896 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 2897 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
| 2898 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 2899 | ~IXGBE_DMATXCTL_TE)); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2900 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2901 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2902 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 2903 | if (!pci_channel_offline(adapter->pdev)) |
| 2904 | ixgbe_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2905 | ixgbe_clean_all_tx_rings(adapter); |
| 2906 | ixgbe_clean_all_rx_rings(adapter); |
| 2907 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2908 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 2909 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 2910 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 2911 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2912 | } |
| 2913 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2914 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2915 | * ixgbe_poll - NAPI Rx polling callback |
| 2916 | * @napi: structure for representing this polling device |
| 2917 | * @budget: how many packets driver is allowed to clean |
| 2918 | * |
| 2919 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2920 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2921 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2922 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 2923 | struct ixgbe_q_vector *q_vector = |
| 2924 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2925 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 2926 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2927 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2928 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 2929 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 2930 | ixgbe_update_tx_dca(adapter, adapter->tx_ring); |
| 2931 | ixgbe_update_rx_dca(adapter, adapter->rx_ring); |
| 2932 | } |
| 2933 | #endif |
| 2934 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2935 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 2936 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2937 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 2938 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2939 | work_done = budget; |
| 2940 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 2941 | /* If budget not fully consumed, exit the polling mode */ |
| 2942 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2943 | napi_complete(napi); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2944 | if (adapter->itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2945 | ixgbe_set_itr(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2946 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2947 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2948 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2949 | return work_done; |
| 2950 | } |
| 2951 | |
| 2952 | /** |
| 2953 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 2954 | * @netdev: network interface device structure |
| 2955 | **/ |
| 2956 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 2957 | { |
| 2958 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2959 | |
| 2960 | /* Do the reset outside of interrupt context */ |
| 2961 | schedule_work(&adapter->reset_task); |
| 2962 | } |
| 2963 | |
| 2964 | static void ixgbe_reset_task(struct work_struct *work) |
| 2965 | { |
| 2966 | struct ixgbe_adapter *adapter; |
| 2967 | adapter = container_of(work, struct ixgbe_adapter, reset_task); |
| 2968 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2969 | /* If we're already down or resetting, just bail */ |
| 2970 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 2971 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 2972 | return; |
| 2973 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2974 | adapter->tx_timeout_count++; |
| 2975 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2976 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2979 | #ifdef CONFIG_IXGBE_DCB |
| 2980 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2981 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2982 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2983 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB]; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2984 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2985 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 2986 | return ret; |
| 2987 | |
| 2988 | f->mask = 0x7 << 3; |
| 2989 | adapter->num_rx_queues = f->indices; |
| 2990 | adapter->num_tx_queues = f->indices; |
| 2991 | ret = true; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2992 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2993 | return ret; |
| 2994 | } |
| 2995 | #endif |
| 2996 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 2997 | /** |
| 2998 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 2999 | * @adapter: board private structure to initialize |
| 3000 | * |
| 3001 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 3002 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 3003 | * |
| 3004 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3005 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 3006 | { |
| 3007 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3008 | 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] | 3009 | |
| 3010 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3011 | f->mask = 0xF; |
| 3012 | adapter->num_rx_queues = f->indices; |
| 3013 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3014 | ret = true; |
| 3015 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3016 | ret = false; |
| 3017 | } |
| 3018 | |
| 3019 | return ret; |
| 3020 | } |
| 3021 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 3022 | /** |
| 3023 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 3024 | * @adapter: board private structure to initialize |
| 3025 | * |
| 3026 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 3027 | * to the original CPU that initiated the Tx session. This runs in addition |
| 3028 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 3029 | * Rx load across CPUs using RSS. |
| 3030 | * |
| 3031 | **/ |
| 3032 | static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter) |
| 3033 | { |
| 3034 | bool ret = false; |
| 3035 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 3036 | |
| 3037 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 3038 | f_fdir->mask = 0; |
| 3039 | |
| 3040 | /* Flow Director must have RSS enabled */ |
| 3041 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3042 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3043 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) { |
| 3044 | adapter->num_tx_queues = f_fdir->indices; |
| 3045 | adapter->num_rx_queues = f_fdir->indices; |
| 3046 | ret = true; |
| 3047 | } else { |
| 3048 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3049 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3050 | } |
| 3051 | return ret; |
| 3052 | } |
| 3053 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3054 | #ifdef IXGBE_FCOE |
| 3055 | /** |
| 3056 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 3057 | * @adapter: board private structure to initialize |
| 3058 | * |
| 3059 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 3060 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 3061 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 3062 | * index of the first rx queue used by FCoE. |
| 3063 | * |
| 3064 | **/ |
| 3065 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 3066 | { |
| 3067 | bool ret = false; |
| 3068 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3069 | |
| 3070 | f->indices = min((int)num_online_cpus(), f->indices); |
| 3071 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 3072 | #ifdef CONFIG_IXGBE_DCB |
| 3073 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3074 | DPRINTK(PROBE, INFO, "FCOE enabled with DCB \n"); |
| 3075 | ixgbe_set_dcb_queues(adapter); |
| 3076 | } |
| 3077 | #endif |
| 3078 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 3079 | DPRINTK(PROBE, INFO, "FCOE enabled with RSS \n"); |
| 3080 | ixgbe_set_rss_queues(adapter); |
| 3081 | } |
| 3082 | /* adding FCoE rx rings to the end */ |
| 3083 | f->mask = adapter->num_rx_queues; |
| 3084 | adapter->num_rx_queues += f->indices; |
| 3085 | if (adapter->num_tx_queues == 0) |
| 3086 | adapter->num_tx_queues = f->indices; |
| 3087 | |
| 3088 | ret = true; |
| 3089 | } |
| 3090 | |
| 3091 | return ret; |
| 3092 | } |
| 3093 | |
| 3094 | #endif /* IXGBE_FCOE */ |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3095 | /* |
| 3096 | * ixgbe_set_num_queues: Allocate queues for device, feature dependant |
| 3097 | * @adapter: board private structure to initialize |
| 3098 | * |
| 3099 | * This is the top level queue allocation routine. The order here is very |
| 3100 | * important, starting with the "most" number of features turned on at once, |
| 3101 | * and ending with the smallest set of features. This way large combinations |
| 3102 | * can be allocated if they're turned on, and smaller combinations are the |
| 3103 | * fallthrough conditions. |
| 3104 | * |
| 3105 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3106 | static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
| 3107 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3108 | #ifdef IXGBE_FCOE |
| 3109 | if (ixgbe_set_fcoe_queues(adapter)) |
| 3110 | goto done; |
| 3111 | |
| 3112 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3113 | #ifdef CONFIG_IXGBE_DCB |
| 3114 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3115 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3116 | |
| 3117 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 3118 | if (ixgbe_set_fdir_queues(adapter)) |
| 3119 | goto done; |
| 3120 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3121 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3122 | goto done; |
| 3123 | |
| 3124 | /* fallback to base case */ |
| 3125 | adapter->num_rx_queues = 1; |
| 3126 | adapter->num_tx_queues = 1; |
| 3127 | |
| 3128 | done: |
| 3129 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ |
| 3130 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3131 | } |
| 3132 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3133 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3134 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3135 | { |
| 3136 | int err, vector_threshold; |
| 3137 | |
| 3138 | /* We'll want at least 3 (vector_threshold): |
| 3139 | * 1) TxQ[0] Cleanup |
| 3140 | * 2) RxQ[0] Cleanup |
| 3141 | * 3) Other (Link Status Change, etc.) |
| 3142 | * 4) TCP Timer (optional) |
| 3143 | */ |
| 3144 | vector_threshold = MIN_MSIX_COUNT; |
| 3145 | |
| 3146 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 3147 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 3148 | * Right now, we simply care about how many we'll get; we'll |
| 3149 | * set them up later while requesting irq's. |
| 3150 | */ |
| 3151 | while (vectors >= vector_threshold) { |
| 3152 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3153 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3154 | if (!err) /* Success in acquiring all requested vectors. */ |
| 3155 | break; |
| 3156 | else if (err < 0) |
| 3157 | vectors = 0; /* Nasty failure, quit now */ |
| 3158 | else /* err == number of vectors we should try again with */ |
| 3159 | vectors = err; |
| 3160 | } |
| 3161 | |
| 3162 | if (vectors < vector_threshold) { |
| 3163 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 3164 | * This just means we'll go with either a single MSI |
| 3165 | * vector or fall back to legacy interrupts. |
| 3166 | */ |
| 3167 | DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n"); |
| 3168 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3169 | kfree(adapter->msix_entries); |
| 3170 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3171 | } else { |
| 3172 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 3173 | /* |
| 3174 | * Adjust for only the vectors we'll use, which is minimum |
| 3175 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 3176 | * vectors we were allocated. |
| 3177 | */ |
| 3178 | adapter->num_msix_vectors = min(vectors, |
| 3179 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3180 | } |
| 3181 | } |
| 3182 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3183 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3184 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3185 | * @adapter: board private structure to initialize |
| 3186 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3187 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 3188 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3189 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3190 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3191 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3192 | int i; |
| 3193 | bool ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3194 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3195 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 3196 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3197 | adapter->rx_ring[i].reg_idx = i; |
| 3198 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3199 | adapter->tx_ring[i].reg_idx = i; |
| 3200 | ret = true; |
| 3201 | } else { |
| 3202 | ret = false; |
| 3203 | } |
| 3204 | |
| 3205 | return ret; |
| 3206 | } |
| 3207 | |
| 3208 | #ifdef CONFIG_IXGBE_DCB |
| 3209 | /** |
| 3210 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 3211 | * @adapter: board private structure to initialize |
| 3212 | * |
| 3213 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 3214 | * |
| 3215 | **/ |
| 3216 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 3217 | { |
| 3218 | int i; |
| 3219 | bool ret = false; |
| 3220 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 3221 | |
| 3222 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3223 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3224 | /* the number of queues is assumed to be symmetric */ |
| 3225 | for (i = 0; i < dcb_i; i++) { |
| 3226 | adapter->rx_ring[i].reg_idx = i << 3; |
| 3227 | adapter->tx_ring[i].reg_idx = i << 2; |
| 3228 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3229 | ret = true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3230 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3231 | if (dcb_i == 8) { |
| 3232 | /* |
| 3233 | * Tx TC0 starts at: descriptor queue 0 |
| 3234 | * Tx TC1 starts at: descriptor queue 32 |
| 3235 | * Tx TC2 starts at: descriptor queue 64 |
| 3236 | * Tx TC3 starts at: descriptor queue 80 |
| 3237 | * Tx TC4 starts at: descriptor queue 96 |
| 3238 | * Tx TC5 starts at: descriptor queue 104 |
| 3239 | * Tx TC6 starts at: descriptor queue 112 |
| 3240 | * Tx TC7 starts at: descriptor queue 120 |
| 3241 | * |
| 3242 | * Rx TC0-TC7 are offset by 16 queues each |
| 3243 | */ |
| 3244 | for (i = 0; i < 3; i++) { |
| 3245 | adapter->tx_ring[i].reg_idx = i << 5; |
| 3246 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3247 | } |
| 3248 | for ( ; i < 5; i++) { |
| 3249 | adapter->tx_ring[i].reg_idx = |
| 3250 | ((i + 2) << 4); |
| 3251 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3252 | } |
| 3253 | for ( ; i < dcb_i; i++) { |
| 3254 | adapter->tx_ring[i].reg_idx = |
| 3255 | ((i + 8) << 3); |
| 3256 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3257 | } |
| 3258 | |
| 3259 | ret = true; |
| 3260 | } else if (dcb_i == 4) { |
| 3261 | /* |
| 3262 | * Tx TC0 starts at: descriptor queue 0 |
| 3263 | * Tx TC1 starts at: descriptor queue 64 |
| 3264 | * Tx TC2 starts at: descriptor queue 96 |
| 3265 | * Tx TC3 starts at: descriptor queue 112 |
| 3266 | * |
| 3267 | * Rx TC0-TC3 are offset by 32 queues each |
| 3268 | */ |
| 3269 | adapter->tx_ring[0].reg_idx = 0; |
| 3270 | adapter->tx_ring[1].reg_idx = 64; |
| 3271 | adapter->tx_ring[2].reg_idx = 96; |
| 3272 | adapter->tx_ring[3].reg_idx = 112; |
| 3273 | for (i = 0 ; i < dcb_i; i++) |
| 3274 | adapter->rx_ring[i].reg_idx = i << 5; |
| 3275 | |
| 3276 | ret = true; |
| 3277 | } else { |
| 3278 | ret = false; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3279 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3280 | } else { |
| 3281 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3282 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3283 | } else { |
| 3284 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3285 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3286 | |
| 3287 | return ret; |
| 3288 | } |
| 3289 | #endif |
| 3290 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 3291 | /** |
| 3292 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 3293 | * @adapter: board private structure to initialize |
| 3294 | * |
| 3295 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 3296 | * |
| 3297 | **/ |
| 3298 | static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter) |
| 3299 | { |
| 3300 | int i; |
| 3301 | bool ret = false; |
| 3302 | |
| 3303 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3304 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3305 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) { |
| 3306 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3307 | adapter->rx_ring[i].reg_idx = i; |
| 3308 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3309 | adapter->tx_ring[i].reg_idx = i; |
| 3310 | ret = true; |
| 3311 | } |
| 3312 | |
| 3313 | return ret; |
| 3314 | } |
| 3315 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3316 | #ifdef IXGBE_FCOE |
| 3317 | /** |
| 3318 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 3319 | * @adapter: board private structure to initialize |
| 3320 | * |
| 3321 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 3322 | * |
| 3323 | */ |
| 3324 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 3325 | { |
| 3326 | int i, fcoe_i = 0; |
| 3327 | bool ret = false; |
| 3328 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3329 | |
| 3330 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 3331 | #ifdef CONFIG_IXGBE_DCB |
| 3332 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3333 | ixgbe_cache_ring_dcb(adapter); |
| 3334 | fcoe_i = adapter->rx_ring[0].reg_idx + 1; |
| 3335 | } |
| 3336 | #endif /* CONFIG_IXGBE_DCB */ |
| 3337 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 3338 | ixgbe_cache_ring_rss(adapter); |
| 3339 | fcoe_i = f->mask; |
| 3340 | } |
| 3341 | for (i = 0; i < f->indices; i++, fcoe_i++) |
| 3342 | adapter->rx_ring[f->mask + i].reg_idx = fcoe_i; |
| 3343 | ret = true; |
| 3344 | } |
| 3345 | return ret; |
| 3346 | } |
| 3347 | |
| 3348 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3349 | /** |
| 3350 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 3351 | * @adapter: board private structure to initialize |
| 3352 | * |
| 3353 | * Once we know the feature-set enabled for the device, we'll cache |
| 3354 | * the register offset the descriptor ring is assigned to. |
| 3355 | * |
| 3356 | * Note, the order the various feature calls is important. It must start with |
| 3357 | * the "most" features enabled at the same time, then trickle down to the |
| 3358 | * least amount of features turned on at once. |
| 3359 | **/ |
| 3360 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 3361 | { |
| 3362 | /* start with default case */ |
| 3363 | adapter->rx_ring[0].reg_idx = 0; |
| 3364 | adapter->tx_ring[0].reg_idx = 0; |
| 3365 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3366 | #ifdef IXGBE_FCOE |
| 3367 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 3368 | return; |
| 3369 | |
| 3370 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3371 | #ifdef CONFIG_IXGBE_DCB |
| 3372 | if (ixgbe_cache_ring_dcb(adapter)) |
| 3373 | return; |
| 3374 | |
| 3375 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 3376 | if (ixgbe_cache_ring_fdir(adapter)) |
| 3377 | return; |
| 3378 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3379 | if (ixgbe_cache_ring_rss(adapter)) |
| 3380 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3381 | } |
| 3382 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3383 | /** |
| 3384 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 3385 | * @adapter: board private structure to initialize |
| 3386 | * |
| 3387 | * 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] | 3388 | * number of queues at compile-time. The polling_netdev array is |
| 3389 | * intended for Multiqueue, but should work fine with a single queue. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3390 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3391 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3392 | { |
| 3393 | int i; |
| 3394 | |
| 3395 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3396 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3397 | if (!adapter->tx_ring) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3398 | goto err_tx_ring_allocation; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3399 | |
| 3400 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3401 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3402 | if (!adapter->rx_ring) |
| 3403 | goto err_rx_ring_allocation; |
| 3404 | |
| 3405 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3406 | adapter->tx_ring[i].count = adapter->tx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3407 | adapter->tx_ring[i].queue_index = i; |
| 3408 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3409 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3410 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3411 | adapter->rx_ring[i].count = adapter->rx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3412 | adapter->rx_ring[i].queue_index = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3413 | } |
| 3414 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3415 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3416 | |
| 3417 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3418 | |
| 3419 | err_rx_ring_allocation: |
| 3420 | kfree(adapter->tx_ring); |
| 3421 | err_tx_ring_allocation: |
| 3422 | return -ENOMEM; |
| 3423 | } |
| 3424 | |
| 3425 | /** |
| 3426 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 3427 | * @adapter: board private structure to initialize |
| 3428 | * |
| 3429 | * Attempt to configure the interrupts using the best available |
| 3430 | * capabilities of the hardware and the kernel. |
| 3431 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 3432 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3433 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3434 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3435 | int err = 0; |
| 3436 | int vector, v_budget; |
| 3437 | |
| 3438 | /* |
| 3439 | * It's easy to be greedy for MSI-X vectors, but it really |
| 3440 | * doesn't do us much good if we have a lot more vectors |
| 3441 | * than CPU's. So let's be conservative and only ask for |
| 3442 | * (roughly) twice the number of vectors as there are CPU's. |
| 3443 | */ |
| 3444 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3445 | (int)(num_online_cpus() * 2)) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3446 | |
| 3447 | /* |
| 3448 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3449 | * hw.mac->max_msix_vectors vectors. With features |
| 3450 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 3451 | * descriptor queues supported by our device. Thus, we cap it off in |
| 3452 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3453 | */ |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3454 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3455 | |
| 3456 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 3457 | * mean we disable MSI-X capabilities of the adapter. */ |
| 3458 | adapter->msix_entries = kcalloc(v_budget, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3459 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3460 | if (adapter->msix_entries) { |
| 3461 | for (vector = 0; vector < v_budget; vector++) |
| 3462 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3463 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3464 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 3465 | |
| 3466 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3467 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3468 | } |
| 3469 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3470 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 3471 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 3472 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3473 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3474 | adapter->atr_sample_rate = 0; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3475 | ixgbe_set_num_queues(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3476 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3477 | err = pci_enable_msi(adapter->pdev); |
| 3478 | if (!err) { |
| 3479 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 3480 | } else { |
| 3481 | DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3482 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3483 | /* reset err */ |
| 3484 | err = 0; |
| 3485 | } |
| 3486 | |
| 3487 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3488 | return err; |
| 3489 | } |
| 3490 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3491 | /** |
| 3492 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 3493 | * @adapter: board private structure to initialize |
| 3494 | * |
| 3495 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 3496 | * return -ENOMEM. |
| 3497 | **/ |
| 3498 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 3499 | { |
| 3500 | int q_idx, num_q_vectors; |
| 3501 | struct ixgbe_q_vector *q_vector; |
| 3502 | int napi_vectors; |
| 3503 | int (*poll)(struct napi_struct *, int); |
| 3504 | |
| 3505 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3506 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3507 | napi_vectors = adapter->num_rx_queues; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3508 | poll = &ixgbe_clean_rxtx_many; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3509 | } else { |
| 3510 | num_q_vectors = 1; |
| 3511 | napi_vectors = 1; |
| 3512 | poll = &ixgbe_poll; |
| 3513 | } |
| 3514 | |
| 3515 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3516 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL); |
| 3517 | if (!q_vector) |
| 3518 | goto err_out; |
| 3519 | q_vector->adapter = adapter; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3520 | q_vector->eitr = adapter->eitr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3521 | q_vector->v_idx = q_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3522 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3523 | adapter->q_vector[q_idx] = q_vector; |
| 3524 | } |
| 3525 | |
| 3526 | return 0; |
| 3527 | |
| 3528 | err_out: |
| 3529 | while (q_idx) { |
| 3530 | q_idx--; |
| 3531 | q_vector = adapter->q_vector[q_idx]; |
| 3532 | netif_napi_del(&q_vector->napi); |
| 3533 | kfree(q_vector); |
| 3534 | adapter->q_vector[q_idx] = NULL; |
| 3535 | } |
| 3536 | return -ENOMEM; |
| 3537 | } |
| 3538 | |
| 3539 | /** |
| 3540 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 3541 | * @adapter: board private structure to initialize |
| 3542 | * |
| 3543 | * This function frees the memory allocated to the q_vectors. In addition if |
| 3544 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 3545 | * to freeing the q_vector. |
| 3546 | **/ |
| 3547 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 3548 | { |
| 3549 | int q_idx, num_q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3550 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3551 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3552 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3553 | else |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3554 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3555 | |
| 3556 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3557 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3558 | adapter->q_vector[q_idx] = NULL; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3559 | netif_napi_del(&q_vector->napi); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3560 | kfree(q_vector); |
| 3561 | } |
| 3562 | } |
| 3563 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3564 | void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3565 | { |
| 3566 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3567 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3568 | pci_disable_msix(adapter->pdev); |
| 3569 | kfree(adapter->msix_entries); |
| 3570 | adapter->msix_entries = NULL; |
| 3571 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 3572 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 3573 | pci_disable_msi(adapter->pdev); |
| 3574 | } |
| 3575 | return; |
| 3576 | } |
| 3577 | |
| 3578 | /** |
| 3579 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 3580 | * @adapter: board private structure to initialize |
| 3581 | * |
| 3582 | * We determine which interrupt scheme to use based on... |
| 3583 | * - Kernel support (MSI, MSI-X) |
| 3584 | * - which can be user-defined (via MODULE_PARAM) |
| 3585 | * - Hardware queue count (num_*_queues) |
| 3586 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 3587 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3588 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3589 | { |
| 3590 | int err; |
| 3591 | |
| 3592 | /* Number of supported queues */ |
| 3593 | ixgbe_set_num_queues(adapter); |
| 3594 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3595 | err = ixgbe_set_interrupt_capability(adapter); |
| 3596 | if (err) { |
| 3597 | DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n"); |
| 3598 | goto err_set_interrupt; |
| 3599 | } |
| 3600 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3601 | err = ixgbe_alloc_q_vectors(adapter); |
| 3602 | if (err) { |
| 3603 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queue " |
| 3604 | "vectors\n"); |
| 3605 | goto err_alloc_q_vectors; |
| 3606 | } |
| 3607 | |
| 3608 | err = ixgbe_alloc_queues(adapter); |
| 3609 | if (err) { |
| 3610 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 3611 | goto err_alloc_queues; |
| 3612 | } |
| 3613 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3614 | DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3615 | "Tx Queue count = %u\n", |
| 3616 | (adapter->num_rx_queues > 1) ? "Enabled" : |
| 3617 | "Disabled", adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3618 | |
| 3619 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3620 | |
| 3621 | return 0; |
| 3622 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3623 | err_alloc_queues: |
| 3624 | ixgbe_free_q_vectors(adapter); |
| 3625 | err_alloc_q_vectors: |
| 3626 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3627 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3628 | return err; |
| 3629 | } |
| 3630 | |
| 3631 | /** |
| 3632 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 3633 | * @adapter: board private structure to clear interrupt scheme on |
| 3634 | * |
| 3635 | * We go through and clear interrupt specific resources and reset the structure |
| 3636 | * to pre-load conditions |
| 3637 | **/ |
| 3638 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 3639 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3640 | kfree(adapter->tx_ring); |
| 3641 | kfree(adapter->rx_ring); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3642 | adapter->tx_ring = NULL; |
| 3643 | adapter->rx_ring = NULL; |
| 3644 | |
| 3645 | ixgbe_free_q_vectors(adapter); |
| 3646 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | /** |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3650 | * ixgbe_sfp_timer - worker thread to find a missing module |
| 3651 | * @data: pointer to our adapter struct |
| 3652 | **/ |
| 3653 | static void ixgbe_sfp_timer(unsigned long data) |
| 3654 | { |
| 3655 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 3656 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3657 | /* |
| 3658 | * Do the sfp_timer outside of interrupt context due to the |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3659 | * delays that sfp+ detection requires |
| 3660 | */ |
| 3661 | schedule_work(&adapter->sfp_task); |
| 3662 | } |
| 3663 | |
| 3664 | /** |
| 3665 | * ixgbe_sfp_task - worker thread to find a missing module |
| 3666 | * @work: pointer to work_struct containing our data |
| 3667 | **/ |
| 3668 | static void ixgbe_sfp_task(struct work_struct *work) |
| 3669 | { |
| 3670 | struct ixgbe_adapter *adapter = container_of(work, |
| 3671 | struct ixgbe_adapter, |
| 3672 | sfp_task); |
| 3673 | struct ixgbe_hw *hw = &adapter->hw; |
| 3674 | |
| 3675 | if ((hw->phy.type == ixgbe_phy_nl) && |
| 3676 | (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) { |
| 3677 | s32 ret = hw->phy.ops.identify_sfp(hw); |
| 3678 | if (ret) |
| 3679 | goto reschedule; |
| 3680 | ret = hw->phy.ops.reset(hw); |
| 3681 | if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
| 3682 | DPRINTK(PROBE, ERR, "failed to initialize because an " |
| 3683 | "unsupported SFP+ module type was detected.\n" |
| 3684 | "Reload the driver after installing a " |
| 3685 | "supported module.\n"); |
| 3686 | unregister_netdev(adapter->netdev); |
| 3687 | } else { |
| 3688 | DPRINTK(PROBE, INFO, "detected SFP+: %d\n", |
| 3689 | hw->phy.sfp_type); |
| 3690 | } |
| 3691 | /* don't need this routine any more */ |
| 3692 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3693 | } |
| 3694 | return; |
| 3695 | reschedule: |
| 3696 | if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state)) |
| 3697 | mod_timer(&adapter->sfp_timer, |
| 3698 | round_jiffies(jiffies + (2 * HZ))); |
| 3699 | } |
| 3700 | |
| 3701 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3702 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 3703 | * @adapter: board private structure to initialize |
| 3704 | * |
| 3705 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 3706 | * Fields are initialized based on PCI device information and |
| 3707 | * OS network device settings (MTU size). |
| 3708 | **/ |
| 3709 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 3710 | { |
| 3711 | struct ixgbe_hw *hw = &adapter->hw; |
| 3712 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3713 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3714 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3715 | int j; |
| 3716 | struct tc_configuration *tc; |
| 3717 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3718 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3719 | /* PCI config space info */ |
| 3720 | |
| 3721 | hw->vendor_id = pdev->vendor; |
| 3722 | hw->device_id = pdev->device; |
| 3723 | hw->revision_id = pdev->revision; |
| 3724 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 3725 | hw->subsystem_device_id = pdev->subsystem_device; |
| 3726 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3727 | /* Set capability flags */ |
| 3728 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 3729 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 3730 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3731 | adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3732 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3733 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 3734 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3735 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3736 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3737 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | df647b5 | 2009-06-04 16:00:47 +0000 | [diff] [blame] | 3738 | adapter->flags |= IXGBE_FLAG2_RSC_CAPABLE; |
| 3739 | adapter->flags |= IXGBE_FLAG2_RSC_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 3740 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3741 | adapter->ring_feature[RING_F_FDIR].indices = |
| 3742 | IXGBE_MAX_FDIR_INDICES; |
| 3743 | adapter->atr_sample_rate = 20; |
| 3744 | adapter->fdir_pballoc = 0; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3745 | #ifdef IXGBE_FCOE |
| 3746 | adapter->flags |= IXGBE_FLAG_FCOE_ENABLED; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3747 | adapter->ring_feature[RING_F_FCOE].indices = IXGBE_FCRETA_SIZE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3748 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3749 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3750 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3751 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3752 | /* Configure DCB traffic classes */ |
| 3753 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 3754 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 3755 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 3756 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3757 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 3758 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3759 | tc->dcb_pfc = pfc_disabled; |
| 3760 | } |
| 3761 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 3762 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 3763 | adapter->dcb_cfg.rx_pba_cfg = pba_equal; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 3764 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3765 | adapter->dcb_cfg.round_robin_enable = false; |
| 3766 | adapter->dcb_set_bitmap = 0x00; |
| 3767 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
| 3768 | adapter->ring_feature[RING_F_DCB].indices); |
| 3769 | |
| 3770 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3771 | |
| 3772 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 3773 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 3774 | 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] | 3775 | #ifdef CONFIG_DCB |
| 3776 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 3777 | #endif |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 3778 | hw->fc.high_water = IXGBE_DEFAULT_FCRTH; |
| 3779 | hw->fc.low_water = IXGBE_DEFAULT_FCRTL; |
| 3780 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 3781 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 3782 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3783 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 3784 | /* enable itr by default in dynamic mode */ |
| 3785 | adapter->itr_setting = 1; |
| 3786 | adapter->eitr_param = 20000; |
| 3787 | |
| 3788 | /* set defaults for eitr in MegaBytes */ |
| 3789 | adapter->eitr_low = 10; |
| 3790 | adapter->eitr_high = 20; |
| 3791 | |
| 3792 | /* set default ring sizes */ |
| 3793 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 3794 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 3795 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3796 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3797 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3798 | dev_err(&pdev->dev, "EEPROM initialization failed\n"); |
| 3799 | return -EIO; |
| 3800 | } |
| 3801 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3802 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3803 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 3804 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3805 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3806 | |
| 3807 | return 0; |
| 3808 | } |
| 3809 | |
| 3810 | /** |
| 3811 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
| 3812 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3813 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3814 | * |
| 3815 | * Return 0 on success, negative on failure |
| 3816 | **/ |
| 3817 | int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3818 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3819 | { |
| 3820 | struct pci_dev *pdev = adapter->pdev; |
| 3821 | int size; |
| 3822 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3823 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 3824 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3825 | if (!tx_ring->tx_buffer_info) |
| 3826 | goto err; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3827 | memset(tx_ring->tx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3828 | |
| 3829 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 3830 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3831 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3832 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3833 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, |
| 3834 | &tx_ring->dma); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3835 | if (!tx_ring->desc) |
| 3836 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3837 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3838 | tx_ring->next_to_use = 0; |
| 3839 | tx_ring->next_to_clean = 0; |
| 3840 | tx_ring->work_limit = tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3841 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3842 | |
| 3843 | err: |
| 3844 | vfree(tx_ring->tx_buffer_info); |
| 3845 | tx_ring->tx_buffer_info = NULL; |
| 3846 | DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit " |
| 3847 | "descriptor ring\n"); |
| 3848 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 3852 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 3853 | * @adapter: board private structure |
| 3854 | * |
| 3855 | * If this function returns with an error, then it's possible one or |
| 3856 | * more of the rings is populated (while the rest are not). It is the |
| 3857 | * callers duty to clean those orphaned rings. |
| 3858 | * |
| 3859 | * Return 0 on success, negative on failure |
| 3860 | **/ |
| 3861 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 3862 | { |
| 3863 | int i, err = 0; |
| 3864 | |
| 3865 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3866 | err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 3867 | if (!err) |
| 3868 | continue; |
| 3869 | DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i); |
| 3870 | break; |
| 3871 | } |
| 3872 | |
| 3873 | return err; |
| 3874 | } |
| 3875 | |
| 3876 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3877 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
| 3878 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3879 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3880 | * |
| 3881 | * Returns 0 on success, negative on failure |
| 3882 | **/ |
| 3883 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3884 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3885 | { |
| 3886 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3887 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3888 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3889 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 3890 | rx_ring->rx_buffer_info = vmalloc(size); |
| 3891 | if (!rx_ring->rx_buffer_info) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3892 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3893 | "vmalloc allocation failed for the rx desc ring\n"); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3894 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3895 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3896 | memset(rx_ring->rx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3897 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3898 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3899 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 3900 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3901 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3902 | 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] | 3903 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3904 | if (!rx_ring->desc) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3905 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3906 | "Memory allocation failed for the rx desc ring\n"); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3907 | vfree(rx_ring->rx_buffer_info); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3908 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3909 | } |
| 3910 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3911 | rx_ring->next_to_clean = 0; |
| 3912 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3913 | |
| 3914 | return 0; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3915 | |
| 3916 | alloc_failed: |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3917 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3918 | } |
| 3919 | |
| 3920 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 3921 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 3922 | * @adapter: board private structure |
| 3923 | * |
| 3924 | * If this function returns with an error, then it's possible one or |
| 3925 | * more of the rings is populated (while the rest are not). It is the |
| 3926 | * callers duty to clean those orphaned rings. |
| 3927 | * |
| 3928 | * Return 0 on success, negative on failure |
| 3929 | **/ |
| 3930 | |
| 3931 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 3932 | { |
| 3933 | int i, err = 0; |
| 3934 | |
| 3935 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3936 | err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 3937 | if (!err) |
| 3938 | continue; |
| 3939 | DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i); |
| 3940 | break; |
| 3941 | } |
| 3942 | |
| 3943 | return err; |
| 3944 | } |
| 3945 | |
| 3946 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3947 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
| 3948 | * @adapter: board private structure |
| 3949 | * @tx_ring: Tx descriptor ring for a specific queue |
| 3950 | * |
| 3951 | * Free all transmit software resources |
| 3952 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 3953 | void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter, |
| 3954 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3955 | { |
| 3956 | struct pci_dev *pdev = adapter->pdev; |
| 3957 | |
| 3958 | ixgbe_clean_tx_ring(adapter, tx_ring); |
| 3959 | |
| 3960 | vfree(tx_ring->tx_buffer_info); |
| 3961 | tx_ring->tx_buffer_info = NULL; |
| 3962 | |
| 3963 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 3964 | |
| 3965 | tx_ring->desc = NULL; |
| 3966 | } |
| 3967 | |
| 3968 | /** |
| 3969 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 3970 | * @adapter: board private structure |
| 3971 | * |
| 3972 | * Free all transmit software resources |
| 3973 | **/ |
| 3974 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 3975 | { |
| 3976 | int i; |
| 3977 | |
| 3978 | for (i = 0; i < adapter->num_tx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 3979 | if (adapter->tx_ring[i].desc) |
| 3980 | ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3984 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3985 | * @adapter: board private structure |
| 3986 | * @rx_ring: ring to clean the resources from |
| 3987 | * |
| 3988 | * Free all receive software resources |
| 3989 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 3990 | void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter, |
| 3991 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3992 | { |
| 3993 | struct pci_dev *pdev = adapter->pdev; |
| 3994 | |
| 3995 | ixgbe_clean_rx_ring(adapter, rx_ring); |
| 3996 | |
| 3997 | vfree(rx_ring->rx_buffer_info); |
| 3998 | rx_ring->rx_buffer_info = NULL; |
| 3999 | |
| 4000 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 4001 | |
| 4002 | rx_ring->desc = NULL; |
| 4003 | } |
| 4004 | |
| 4005 | /** |
| 4006 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 4007 | * @adapter: board private structure |
| 4008 | * |
| 4009 | * Free all receive software resources |
| 4010 | **/ |
| 4011 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4012 | { |
| 4013 | int i; |
| 4014 | |
| 4015 | for (i = 0; i < adapter->num_rx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4016 | if (adapter->rx_ring[i].desc) |
| 4017 | ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4018 | } |
| 4019 | |
| 4020 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4021 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 4022 | * @netdev: network interface device structure |
| 4023 | * @new_mtu: new value for maximum frame size |
| 4024 | * |
| 4025 | * Returns 0 on success, negative on failure |
| 4026 | **/ |
| 4027 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 4028 | { |
| 4029 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4030 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4031 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 4032 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 4033 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4034 | return -EINVAL; |
| 4035 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4036 | DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n", |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4037 | netdev->mtu, new_mtu); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4038 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4039 | netdev->mtu = new_mtu; |
| 4040 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4041 | if (netif_running(netdev)) |
| 4042 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4043 | |
| 4044 | return 0; |
| 4045 | } |
| 4046 | |
| 4047 | /** |
| 4048 | * ixgbe_open - Called when a network interface is made active |
| 4049 | * @netdev: network interface device structure |
| 4050 | * |
| 4051 | * Returns 0 on success, negative value on failure |
| 4052 | * |
| 4053 | * The open entry point is called when a network interface is made |
| 4054 | * active by the system (IFF_UP). At this point all resources needed |
| 4055 | * for transmit and receive operations are allocated, the interrupt |
| 4056 | * handler is registered with the OS, the watchdog timer is started, |
| 4057 | * and the stack is notified that the interface is ready. |
| 4058 | **/ |
| 4059 | static int ixgbe_open(struct net_device *netdev) |
| 4060 | { |
| 4061 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4062 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4063 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 4064 | /* disallow open during test */ |
| 4065 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 4066 | return -EBUSY; |
| 4067 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 4068 | netif_carrier_off(netdev); |
| 4069 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4070 | /* allocate transmit descriptors */ |
| 4071 | err = ixgbe_setup_all_tx_resources(adapter); |
| 4072 | if (err) |
| 4073 | goto err_setup_tx; |
| 4074 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4075 | /* allocate receive descriptors */ |
| 4076 | err = ixgbe_setup_all_rx_resources(adapter); |
| 4077 | if (err) |
| 4078 | goto err_setup_rx; |
| 4079 | |
| 4080 | ixgbe_configure(adapter); |
| 4081 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4082 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4083 | if (err) |
| 4084 | goto err_req_irq; |
| 4085 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4086 | err = ixgbe_up_complete(adapter); |
| 4087 | if (err) |
| 4088 | goto err_up; |
| 4089 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 4090 | netif_tx_start_all_queues(netdev); |
| 4091 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4092 | return 0; |
| 4093 | |
| 4094 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4095 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4096 | ixgbe_free_irq(adapter); |
| 4097 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4098 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4099 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4100 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4101 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4102 | ixgbe_reset(adapter); |
| 4103 | |
| 4104 | return err; |
| 4105 | } |
| 4106 | |
| 4107 | /** |
| 4108 | * ixgbe_close - Disables a network interface |
| 4109 | * @netdev: network interface device structure |
| 4110 | * |
| 4111 | * Returns 0, this is not allowed to fail |
| 4112 | * |
| 4113 | * The close entry point is called when an interface is de-activated |
| 4114 | * by the OS. The hardware is still under the drivers control, but |
| 4115 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4116 | * hardware, and all transmit and receive resources are freed. |
| 4117 | **/ |
| 4118 | static int ixgbe_close(struct net_device *netdev) |
| 4119 | { |
| 4120 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4121 | |
| 4122 | ixgbe_down(adapter); |
| 4123 | ixgbe_free_irq(adapter); |
| 4124 | |
| 4125 | ixgbe_free_all_tx_resources(adapter); |
| 4126 | ixgbe_free_all_rx_resources(adapter); |
| 4127 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4128 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4129 | |
| 4130 | return 0; |
| 4131 | } |
| 4132 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4133 | #ifdef CONFIG_PM |
| 4134 | static int ixgbe_resume(struct pci_dev *pdev) |
| 4135 | { |
| 4136 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4137 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4138 | u32 err; |
| 4139 | |
| 4140 | pci_set_power_state(pdev, PCI_D0); |
| 4141 | pci_restore_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 4142 | |
| 4143 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4144 | if (err) { |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4145 | printk(KERN_ERR "ixgbe: Cannot enable PCI device from " |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4146 | "suspend\n"); |
| 4147 | return err; |
| 4148 | } |
| 4149 | pci_set_master(pdev); |
| 4150 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4151 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4152 | |
| 4153 | err = ixgbe_init_interrupt_scheme(adapter); |
| 4154 | if (err) { |
| 4155 | printk(KERN_ERR "ixgbe: Cannot initialize interrupts for " |
| 4156 | "device\n"); |
| 4157 | return err; |
| 4158 | } |
| 4159 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4160 | ixgbe_reset(adapter); |
| 4161 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 4162 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 4163 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4164 | if (netif_running(netdev)) { |
| 4165 | err = ixgbe_open(adapter->netdev); |
| 4166 | if (err) |
| 4167 | return err; |
| 4168 | } |
| 4169 | |
| 4170 | netif_device_attach(netdev); |
| 4171 | |
| 4172 | return 0; |
| 4173 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4174 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4175 | |
| 4176 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4177 | { |
| 4178 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4179 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4180 | struct ixgbe_hw *hw = &adapter->hw; |
| 4181 | u32 ctrl, fctrl; |
| 4182 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4183 | #ifdef CONFIG_PM |
| 4184 | int retval = 0; |
| 4185 | #endif |
| 4186 | |
| 4187 | netif_device_detach(netdev); |
| 4188 | |
| 4189 | if (netif_running(netdev)) { |
| 4190 | ixgbe_down(adapter); |
| 4191 | ixgbe_free_irq(adapter); |
| 4192 | ixgbe_free_all_tx_resources(adapter); |
| 4193 | ixgbe_free_all_rx_resources(adapter); |
| 4194 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4195 | ixgbe_clear_interrupt_scheme(adapter); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4196 | |
| 4197 | #ifdef CONFIG_PM |
| 4198 | retval = pci_save_state(pdev); |
| 4199 | if (retval) |
| 4200 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4201 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4202 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4203 | if (wufc) { |
| 4204 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4205 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4206 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 4207 | if (wufc & IXGBE_WUFC_MC) { |
| 4208 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4209 | fctrl |= IXGBE_FCTRL_MPE; |
| 4210 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 4211 | } |
| 4212 | |
| 4213 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 4214 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 4215 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 4216 | |
| 4217 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 4218 | } else { |
| 4219 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 4220 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 4221 | } |
| 4222 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4223 | if (wufc && hw->mac.type == ixgbe_mac_82599EB) |
| 4224 | pci_wake_from_d3(pdev, true); |
| 4225 | else |
| 4226 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4227 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4228 | *enable_wake = !!wufc; |
| 4229 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4230 | ixgbe_release_hw_control(adapter); |
| 4231 | |
| 4232 | pci_disable_device(pdev); |
| 4233 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4234 | return 0; |
| 4235 | } |
| 4236 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4237 | #ifdef CONFIG_PM |
| 4238 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4239 | { |
| 4240 | int retval; |
| 4241 | bool wake; |
| 4242 | |
| 4243 | retval = __ixgbe_shutdown(pdev, &wake); |
| 4244 | if (retval) |
| 4245 | return retval; |
| 4246 | |
| 4247 | if (wake) { |
| 4248 | pci_prepare_to_sleep(pdev); |
| 4249 | } else { |
| 4250 | pci_wake_from_d3(pdev, false); |
| 4251 | pci_set_power_state(pdev, PCI_D3hot); |
| 4252 | } |
| 4253 | |
| 4254 | return 0; |
| 4255 | } |
| 4256 | #endif /* CONFIG_PM */ |
| 4257 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4258 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 4259 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4260 | bool wake; |
| 4261 | |
| 4262 | __ixgbe_shutdown(pdev, &wake); |
| 4263 | |
| 4264 | if (system_state == SYSTEM_POWER_OFF) { |
| 4265 | pci_wake_from_d3(pdev, wake); |
| 4266 | pci_set_power_state(pdev, PCI_D3hot); |
| 4267 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4268 | } |
| 4269 | |
| 4270 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4271 | * ixgbe_update_stats - Update the board statistics counters. |
| 4272 | * @adapter: board private structure |
| 4273 | **/ |
| 4274 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 4275 | { |
| 4276 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4277 | u64 total_mpc = 0; |
| 4278 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4279 | |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4280 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4281 | u64 rsc_count = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4282 | for (i = 0; i < 16; i++) |
| 4283 | adapter->hw_rx_no_dma_resources += |
| 4284 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4285 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4286 | rsc_count += adapter->rx_ring[i].rsc_count; |
| 4287 | adapter->rsc_count = rsc_count; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4288 | } |
| 4289 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4290 | adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4291 | for (i = 0; i < 8; i++) { |
| 4292 | /* for packet buffers not used, the register should read 0 */ |
| 4293 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 4294 | missed_rx += mpc; |
| 4295 | adapter->stats.mpc[i] += mpc; |
| 4296 | total_mpc += adapter->stats.mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4297 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4298 | adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4299 | adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 4300 | adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 4301 | adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 4302 | adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4303 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4304 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4305 | IXGBE_PXONRXCNT(i)); |
| 4306 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4307 | IXGBE_PXOFFRXCNT(i)); |
| 4308 | adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4309 | } else { |
| 4310 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4311 | IXGBE_PXONRXC(i)); |
| 4312 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4313 | IXGBE_PXOFFRXC(i)); |
| 4314 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4315 | adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw, |
| 4316 | IXGBE_PXONTXC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4317 | adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4318 | IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4319 | } |
| 4320 | adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
| 4321 | /* work around hardware counting issue */ |
| 4322 | adapter->stats.gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4323 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4324 | /* 82598 hardware only has a 32 bit counter in the high register */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4325 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4326 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
| 4327 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
| 4328 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
| 4329 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
| 4330 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
| 4331 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
| 4332 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
| 4333 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 4334 | adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 4335 | adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 4336 | #ifdef IXGBE_FCOE |
| 4337 | adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 4338 | adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 4339 | adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 4340 | adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 4341 | adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 4342 | adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
| 4343 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4344 | } else { |
| 4345 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
| 4346 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 4347 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 4348 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 4349 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 4350 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4351 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
| 4352 | adapter->stats.bprc += bprc; |
| 4353 | adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4354 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4355 | adapter->stats.mprc -= bprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4356 | adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 4357 | adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 4358 | adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 4359 | adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 4360 | adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 4361 | adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 4362 | adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4363 | adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4364 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
| 4365 | adapter->stats.lxontxc += lxon; |
| 4366 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
| 4367 | adapter->stats.lxofftxc += lxoff; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4368 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4369 | adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4370 | adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
| 4371 | /* |
| 4372 | * 82598 errata - tx of flow control packets is included in tx counters |
| 4373 | */ |
| 4374 | xon_off_tot = lxon + lxoff; |
| 4375 | adapter->stats.gptc -= xon_off_tot; |
| 4376 | adapter->stats.mptc -= xon_off_tot; |
| 4377 | adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4378 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4379 | adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 4380 | adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4381 | adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 4382 | adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4383 | adapter->stats.ptc64 -= xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4384 | adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 4385 | adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 4386 | adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 4387 | adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 4388 | adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4389 | adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
| 4390 | |
| 4391 | /* Fill out the OS statistics structure */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4392 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 4393 | |
| 4394 | /* Rx Errors */ |
| 4395 | adapter->net_stats.rx_errors = adapter->stats.crcerrs + |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4396 | adapter->stats.rlec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4397 | adapter->net_stats.rx_dropped = 0; |
| 4398 | adapter->net_stats.rx_length_errors = adapter->stats.rlec; |
| 4399 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4400 | adapter->net_stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | /** |
| 4404 | * ixgbe_watchdog - Timer Call-back |
| 4405 | * @data: pointer to adapter cast into an unsigned long |
| 4406 | **/ |
| 4407 | static void ixgbe_watchdog(unsigned long data) |
| 4408 | { |
| 4409 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4410 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4411 | u64 eics = 0; |
| 4412 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4413 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4414 | /* |
| 4415 | * Do the watchdog outside of interrupt context due to the lovely |
| 4416 | * delays that some of the newer hardware requires |
| 4417 | */ |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4418 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4419 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 4420 | goto watchdog_short_circuit; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4421 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4422 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 4423 | /* |
| 4424 | * for legacy and MSI interrupts don't set any bits |
| 4425 | * that are enabled for EIAM, because this operation |
| 4426 | * would set *both* EIMS and EICS for any bit in EIAM |
| 4427 | */ |
| 4428 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 4429 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
| 4430 | goto watchdog_reschedule; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4431 | } |
| 4432 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4433 | /* get one bit for every active tx/rx interrupt vector */ |
| 4434 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 4435 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
| 4436 | if (qv->rxr_count || qv->txr_count) |
| 4437 | eics |= ((u64)1 << i); |
| 4438 | } |
| 4439 | |
| 4440 | /* Cause software interrupt to ensure rx rings are cleaned */ |
| 4441 | ixgbe_irq_rearm_queues(adapter, eics); |
| 4442 | |
| 4443 | watchdog_reschedule: |
| 4444 | /* Reset the timer */ |
| 4445 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
| 4446 | |
| 4447 | watchdog_short_circuit: |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4448 | schedule_work(&adapter->watchdog_task); |
| 4449 | } |
| 4450 | |
| 4451 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4452 | * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber |
| 4453 | * @work: pointer to work_struct containing our data |
| 4454 | **/ |
| 4455 | static void ixgbe_multispeed_fiber_task(struct work_struct *work) |
| 4456 | { |
| 4457 | struct ixgbe_adapter *adapter = container_of(work, |
| 4458 | struct ixgbe_adapter, |
| 4459 | multispeed_fiber_task); |
| 4460 | struct ixgbe_hw *hw = &adapter->hw; |
| 4461 | u32 autoneg; |
| 4462 | |
| 4463 | adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK; |
| 4464 | if (hw->mac.ops.get_link_capabilities) |
| 4465 | hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 4466 | &hw->mac.autoneg); |
| 4467 | if (hw->mac.ops.setup_link_speed) |
| 4468 | hw->mac.ops.setup_link_speed(hw, autoneg, true, true); |
| 4469 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4470 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK; |
| 4471 | } |
| 4472 | |
| 4473 | /** |
| 4474 | * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module |
| 4475 | * @work: pointer to work_struct containing our data |
| 4476 | **/ |
| 4477 | static void ixgbe_sfp_config_module_task(struct work_struct *work) |
| 4478 | { |
| 4479 | struct ixgbe_adapter *adapter = container_of(work, |
| 4480 | struct ixgbe_adapter, |
| 4481 | sfp_config_module_task); |
| 4482 | struct ixgbe_hw *hw = &adapter->hw; |
| 4483 | u32 err; |
| 4484 | |
| 4485 | adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK; |
| 4486 | err = hw->phy.ops.identify_sfp(hw); |
| 4487 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
| 4488 | DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err); |
| 4489 | ixgbe_down(adapter); |
| 4490 | return; |
| 4491 | } |
| 4492 | hw->mac.ops.setup_sfp(hw); |
| 4493 | |
Tony Breeds | 8d1c3c0 | 2009-04-09 22:29:10 +0000 | [diff] [blame] | 4494 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4495 | /* This will also work for DA Twinax connections */ |
| 4496 | schedule_work(&adapter->multispeed_fiber_task); |
| 4497 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK; |
| 4498 | } |
| 4499 | |
| 4500 | /** |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 4501 | * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table |
| 4502 | * @work: pointer to work_struct containing our data |
| 4503 | **/ |
| 4504 | static void ixgbe_fdir_reinit_task(struct work_struct *work) |
| 4505 | { |
| 4506 | struct ixgbe_adapter *adapter = container_of(work, |
| 4507 | struct ixgbe_adapter, |
| 4508 | fdir_reinit_task); |
| 4509 | struct ixgbe_hw *hw = &adapter->hw; |
| 4510 | int i; |
| 4511 | |
| 4512 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 4513 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4514 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 4515 | &(adapter->tx_ring[i].reinit_state)); |
| 4516 | } else { |
| 4517 | DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, " |
| 4518 | "ignored adding FDIR ATR filters \n"); |
| 4519 | } |
| 4520 | /* Done FDIR Re-initialization, enable transmits */ |
| 4521 | netif_tx_start_all_queues(adapter->netdev); |
| 4522 | } |
| 4523 | |
| 4524 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4525 | * ixgbe_watchdog_task - worker thread to bring link up |
| 4526 | * @work: pointer to work_struct containing our data |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4527 | **/ |
| 4528 | static void ixgbe_watchdog_task(struct work_struct *work) |
| 4529 | { |
| 4530 | struct ixgbe_adapter *adapter = container_of(work, |
| 4531 | struct ixgbe_adapter, |
| 4532 | watchdog_task); |
| 4533 | struct net_device *netdev = adapter->netdev; |
| 4534 | struct ixgbe_hw *hw = &adapter->hw; |
| 4535 | u32 link_speed = adapter->link_speed; |
| 4536 | bool link_up = adapter->link_up; |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4537 | int i; |
| 4538 | struct ixgbe_ring *tx_ring; |
| 4539 | int some_tx_pending = 0; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4540 | |
| 4541 | adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK; |
| 4542 | |
| 4543 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) { |
| 4544 | 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] | 4545 | if (link_up) { |
| 4546 | #ifdef CONFIG_DCB |
| 4547 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 4548 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4549 | hw->mac.ops.fc_enable(hw, i); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4550 | } else { |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4551 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4552 | } |
| 4553 | #else |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4554 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4555 | #endif |
| 4556 | } |
| 4557 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4558 | if (link_up || |
| 4559 | time_after(jiffies, (adapter->link_check_timeout + |
| 4560 | IXGBE_TRY_LINK_TIMEOUT))) { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4561 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4562 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4563 | } |
| 4564 | adapter->link_up = link_up; |
| 4565 | adapter->link_speed = link_speed; |
| 4566 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4567 | |
| 4568 | if (link_up) { |
| 4569 | if (!netif_carrier_ok(netdev)) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4570 | bool flow_rx, flow_tx; |
| 4571 | |
| 4572 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4573 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 4574 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 4575 | flow_rx = (mflcn & IXGBE_MFLCN_RFCE); |
| 4576 | flow_tx = (fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 4577 | } else { |
| 4578 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4579 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 4580 | flow_rx = (frctl & IXGBE_FCTRL_RFCE); |
| 4581 | flow_tx = (rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 4582 | } |
| 4583 | |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4584 | printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, " |
| 4585 | "Flow Control: %s\n", |
| 4586 | netdev->name, |
| 4587 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 4588 | "10 Gbps" : |
| 4589 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 4590 | "1 Gbps" : "unknown speed")), |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4591 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 4592 | (flow_rx ? "RX" : |
| 4593 | (flow_tx ? "TX" : "None")))); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4594 | |
| 4595 | netif_carrier_on(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4596 | } else { |
| 4597 | /* Force detection of hung controller */ |
| 4598 | adapter->detect_tx_hung = true; |
| 4599 | } |
| 4600 | } else { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4601 | adapter->link_up = false; |
| 4602 | adapter->link_speed = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4603 | if (netif_carrier_ok(netdev)) { |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4604 | printk(KERN_INFO "ixgbe: %s NIC Link is Down\n", |
| 4605 | netdev->name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4606 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4607 | } |
| 4608 | } |
| 4609 | |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4610 | if (!netif_carrier_ok(netdev)) { |
| 4611 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4612 | tx_ring = &adapter->tx_ring[i]; |
| 4613 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 4614 | some_tx_pending = 1; |
| 4615 | break; |
| 4616 | } |
| 4617 | } |
| 4618 | |
| 4619 | if (some_tx_pending) { |
| 4620 | /* We've lost link, so the controller stops DMA, |
| 4621 | * but we've got queued Tx work that's never going |
| 4622 | * to get done, so reset controller to flush Tx. |
| 4623 | * (Do the reset outside of interrupt context). |
| 4624 | */ |
| 4625 | schedule_work(&adapter->reset_task); |
| 4626 | } |
| 4627 | } |
| 4628 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4629 | ixgbe_update_stats(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4630 | adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4631 | } |
| 4632 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4633 | static int ixgbe_tso(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4634 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 4635 | u32 tx_flags, u8 *hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4636 | { |
| 4637 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4638 | unsigned int i; |
| 4639 | int err; |
| 4640 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4641 | u32 vlan_macip_lens = 0, type_tucmd_mlhl; |
| 4642 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4643 | |
| 4644 | if (skb_is_gso(skb)) { |
| 4645 | if (skb_header_cloned(skb)) { |
| 4646 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4647 | if (err) |
| 4648 | return err; |
| 4649 | } |
| 4650 | l4len = tcp_hdrlen(skb); |
| 4651 | *hdr_len += l4len; |
| 4652 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4653 | if (skb->protocol == htons(ETH_P_IP)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4654 | struct iphdr *iph = ip_hdr(skb); |
| 4655 | iph->tot_len = 0; |
| 4656 | iph->check = 0; |
| 4657 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4658 | iph->daddr, 0, |
| 4659 | IPPROTO_TCP, |
| 4660 | 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4661 | adapter->hw_tso_ctxt++; |
| 4662 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { |
| 4663 | ipv6_hdr(skb)->payload_len = 0; |
| 4664 | tcp_hdr(skb)->check = |
| 4665 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4666 | &ipv6_hdr(skb)->daddr, |
| 4667 | 0, IPPROTO_TCP, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4668 | adapter->hw_tso6_ctxt++; |
| 4669 | } |
| 4670 | |
| 4671 | i = tx_ring->next_to_use; |
| 4672 | |
| 4673 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4674 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4675 | |
| 4676 | /* VLAN MACLEN IPLEN */ |
| 4677 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4678 | vlan_macip_lens |= |
| 4679 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4680 | vlan_macip_lens |= ((skb_network_offset(skb)) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4681 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4682 | *hdr_len += skb_network_offset(skb); |
| 4683 | vlan_macip_lens |= |
| 4684 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4685 | *hdr_len += |
| 4686 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4687 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4688 | context_desc->seqnum_seed = 0; |
| 4689 | |
| 4690 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4691 | type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4692 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4693 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4694 | if (skb->protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4695 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 4696 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 4697 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
| 4698 | |
| 4699 | /* MSS L4LEN IDX */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4700 | mss_l4len_idx = |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4701 | (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT); |
| 4702 | mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4703 | /* use index 1 for TSO */ |
| 4704 | mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4705 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 4706 | |
| 4707 | tx_buffer_info->time_stamp = jiffies; |
| 4708 | tx_buffer_info->next_to_watch = i; |
| 4709 | |
| 4710 | i++; |
| 4711 | if (i == tx_ring->count) |
| 4712 | i = 0; |
| 4713 | tx_ring->next_to_use = i; |
| 4714 | |
| 4715 | return true; |
| 4716 | } |
| 4717 | return false; |
| 4718 | } |
| 4719 | |
| 4720 | static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4721 | struct ixgbe_ring *tx_ring, |
| 4722 | struct sk_buff *skb, u32 tx_flags) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4723 | { |
| 4724 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4725 | unsigned int i; |
| 4726 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4727 | u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0; |
| 4728 | |
| 4729 | if (skb->ip_summed == CHECKSUM_PARTIAL || |
| 4730 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) { |
| 4731 | i = tx_ring->next_to_use; |
| 4732 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4733 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4734 | |
| 4735 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4736 | vlan_macip_lens |= |
| 4737 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4738 | vlan_macip_lens |= (skb_network_offset(skb) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4739 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4740 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 4741 | vlan_macip_lens |= (skb_transport_header(skb) - |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4742 | skb_network_header(skb)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4743 | |
| 4744 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4745 | context_desc->seqnum_seed = 0; |
| 4746 | |
| 4747 | type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4748 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4749 | |
| 4750 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4751 | switch (skb->protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4752 | case cpu_to_be16(ETH_P_IP): |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4753 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4754 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 4755 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4756 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 4757 | else if (ip_hdr(skb)->protocol == IPPROTO_SCTP) |
| 4758 | type_tucmd_mlhl |= |
| 4759 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4760 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4761 | case cpu_to_be16(ETH_P_IPV6): |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4762 | /* XXX what about other V6 headers?? */ |
| 4763 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 4764 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4765 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 4766 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP) |
| 4767 | type_tucmd_mlhl |= |
| 4768 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4769 | break; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4770 | default: |
| 4771 | if (unlikely(net_ratelimit())) { |
| 4772 | DPRINTK(PROBE, WARNING, |
| 4773 | "partial checksum but proto=%x!\n", |
| 4774 | skb->protocol); |
| 4775 | } |
| 4776 | break; |
| 4777 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4781 | /* use index zero for tx checksum offload */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4782 | context_desc->mss_l4len_idx = 0; |
| 4783 | |
| 4784 | tx_buffer_info->time_stamp = jiffies; |
| 4785 | tx_buffer_info->next_to_watch = i; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4786 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4787 | adapter->hw_csum_tx_good++; |
| 4788 | i++; |
| 4789 | if (i == tx_ring->count) |
| 4790 | i = 0; |
| 4791 | tx_ring->next_to_use = i; |
| 4792 | |
| 4793 | return true; |
| 4794 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4795 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4796 | return false; |
| 4797 | } |
| 4798 | |
| 4799 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4800 | struct ixgbe_ring *tx_ring, |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4801 | struct sk_buff *skb, u32 tx_flags, |
| 4802 | unsigned int first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4803 | { |
| 4804 | struct ixgbe_tx_buffer *tx_buffer_info; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4805 | unsigned int len; |
| 4806 | unsigned int total = skb->len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4807 | unsigned int offset = 0, size, count = 0, i; |
| 4808 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 4809 | unsigned int f; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4810 | dma_addr_t *map; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4811 | |
| 4812 | i = tx_ring->next_to_use; |
| 4813 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4814 | if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) { |
| 4815 | dev_err(&adapter->pdev->dev, "TX DMA map failed\n"); |
| 4816 | return 0; |
| 4817 | } |
| 4818 | |
| 4819 | map = skb_shinfo(skb)->dma_maps; |
| 4820 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4821 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
| 4822 | /* excluding fcoe_crc_eof for FCoE */ |
| 4823 | total -= sizeof(struct fcoe_crc_eof); |
| 4824 | |
| 4825 | len = min(skb_headlen(skb), total); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4826 | while (len) { |
| 4827 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4828 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 4829 | |
| 4830 | tx_buffer_info->length = size; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4831 | tx_buffer_info->dma = map[0] + offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4832 | tx_buffer_info->time_stamp = jiffies; |
| 4833 | tx_buffer_info->next_to_watch = i; |
| 4834 | |
| 4835 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4836 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4837 | offset += size; |
| 4838 | count++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4839 | |
| 4840 | if (len) { |
| 4841 | i++; |
| 4842 | if (i == tx_ring->count) |
| 4843 | i = 0; |
| 4844 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4845 | } |
| 4846 | |
| 4847 | for (f = 0; f < nr_frags; f++) { |
| 4848 | struct skb_frag_struct *frag; |
| 4849 | |
| 4850 | frag = &skb_shinfo(skb)->frags[f]; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4851 | len = min((unsigned int)frag->size, total); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4852 | offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4853 | |
| 4854 | while (len) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4855 | i++; |
| 4856 | if (i == tx_ring->count) |
| 4857 | i = 0; |
| 4858 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4859 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4860 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 4861 | |
| 4862 | tx_buffer_info->length = size; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4863 | tx_buffer_info->dma = map[f + 1] + offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4864 | tx_buffer_info->time_stamp = jiffies; |
| 4865 | tx_buffer_info->next_to_watch = i; |
| 4866 | |
| 4867 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4868 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4869 | offset += size; |
| 4870 | count++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4871 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4872 | if (total == 0) |
| 4873 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4874 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4875 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4876 | tx_ring->tx_buffer_info[i].skb = skb; |
| 4877 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 4878 | |
| 4879 | return count; |
| 4880 | } |
| 4881 | |
| 4882 | static void ixgbe_tx_queue(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4883 | struct ixgbe_ring *tx_ring, |
| 4884 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4885 | { |
| 4886 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 4887 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4888 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 4889 | unsigned int i; |
| 4890 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 4891 | |
| 4892 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 4893 | |
| 4894 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 4895 | |
| 4896 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4897 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 4898 | |
| 4899 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 4900 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 4901 | |
| 4902 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4903 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4904 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4905 | /* use index 1 context for tso */ |
| 4906 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4907 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 4908 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4909 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4910 | |
| 4911 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 4912 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4913 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4914 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4915 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 4916 | olinfo_status |= IXGBE_ADVTXD_CC; |
| 4917 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 4918 | if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 4919 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 4920 | } |
| 4921 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4922 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 4923 | |
| 4924 | i = tx_ring->next_to_use; |
| 4925 | while (count--) { |
| 4926 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4927 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 4928 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 4929 | tx_desc->read.cmd_type_len = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4930 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4931 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4932 | i++; |
| 4933 | if (i == tx_ring->count) |
| 4934 | i = 0; |
| 4935 | } |
| 4936 | |
| 4937 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 4938 | |
| 4939 | /* |
| 4940 | * Force memory writes to complete before letting h/w |
| 4941 | * know there are new descriptors to fetch. (Only |
| 4942 | * applicable for weak-ordered memory model archs, |
| 4943 | * such as IA-64). |
| 4944 | */ |
| 4945 | wmb(); |
| 4946 | |
| 4947 | tx_ring->next_to_use = i; |
| 4948 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
| 4949 | } |
| 4950 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 4951 | static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb, |
| 4952 | int queue, u32 tx_flags) |
| 4953 | { |
| 4954 | /* Right now, we support IPv4 only */ |
| 4955 | struct ixgbe_atr_input atr_input; |
| 4956 | struct tcphdr *th; |
| 4957 | struct udphdr *uh; |
| 4958 | struct iphdr *iph = ip_hdr(skb); |
| 4959 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 4960 | u16 vlan_id, src_port, dst_port, flex_bytes; |
| 4961 | u32 src_ipv4_addr, dst_ipv4_addr; |
| 4962 | u8 l4type = 0; |
| 4963 | |
| 4964 | /* check if we're UDP or TCP */ |
| 4965 | if (iph->protocol == IPPROTO_TCP) { |
| 4966 | th = tcp_hdr(skb); |
| 4967 | src_port = th->source; |
| 4968 | dst_port = th->dest; |
| 4969 | l4type |= IXGBE_ATR_L4TYPE_TCP; |
| 4970 | /* l4type IPv4 type is 0, no need to assign */ |
| 4971 | } else if(iph->protocol == IPPROTO_UDP) { |
| 4972 | uh = udp_hdr(skb); |
| 4973 | src_port = uh->source; |
| 4974 | dst_port = uh->dest; |
| 4975 | l4type |= IXGBE_ATR_L4TYPE_UDP; |
| 4976 | /* l4type IPv4 type is 0, no need to assign */ |
| 4977 | } else { |
| 4978 | /* Unsupported L4 header, just bail here */ |
| 4979 | return; |
| 4980 | } |
| 4981 | |
| 4982 | memset(&atr_input, 0, sizeof(struct ixgbe_atr_input)); |
| 4983 | |
| 4984 | vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >> |
| 4985 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 4986 | src_ipv4_addr = iph->saddr; |
| 4987 | dst_ipv4_addr = iph->daddr; |
| 4988 | flex_bytes = eth->h_proto; |
| 4989 | |
| 4990 | ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id); |
| 4991 | ixgbe_atr_set_src_port_82599(&atr_input, dst_port); |
| 4992 | ixgbe_atr_set_dst_port_82599(&atr_input, src_port); |
| 4993 | ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes); |
| 4994 | ixgbe_atr_set_l4type_82599(&atr_input, l4type); |
| 4995 | /* src and dst are inverted, think how the receiver sees them */ |
| 4996 | ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr); |
| 4997 | ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr); |
| 4998 | |
| 4999 | /* This assumes the Rx queue and Tx queue are bound to the same CPU */ |
| 5000 | ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue); |
| 5001 | } |
| 5002 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5003 | static int __ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5004 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5005 | { |
| 5006 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5007 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5008 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5009 | /* Herbert's original patch had: |
| 5010 | * smp_mb__after_netif_stop_queue(); |
| 5011 | * but since that doesn't exist yet, just open code it. */ |
| 5012 | smp_mb(); |
| 5013 | |
| 5014 | /* We need to check again in a case another CPU has just |
| 5015 | * made room available. */ |
| 5016 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) |
| 5017 | return -EBUSY; |
| 5018 | |
| 5019 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Jesse Brandeburg | af72166 | 2008-09-11 19:54:23 -0700 | [diff] [blame] | 5020 | netif_start_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5021 | ++adapter->restart_queue; |
| 5022 | return 0; |
| 5023 | } |
| 5024 | |
| 5025 | static int ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5026 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5027 | { |
| 5028 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) |
| 5029 | return 0; |
| 5030 | return __ixgbe_maybe_stop_tx(netdev, tx_ring, size); |
| 5031 | } |
| 5032 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5033 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 5034 | { |
| 5035 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5036 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 5037 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
| 5038 | return smp_processor_id(); |
| 5039 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5040 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 5041 | return 0; /* All traffic should default to class 0 */ |
| 5042 | |
| 5043 | return skb_tx_hash(dev, skb); |
| 5044 | } |
| 5045 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5046 | static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 5047 | { |
| 5048 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5049 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5050 | unsigned int first; |
| 5051 | unsigned int tx_flags = 0; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5052 | u8 hdr_len = 0; |
| 5053 | int r_idx = 0, tso; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5054 | int count = 0; |
| 5055 | unsigned int f; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5056 | |
Wu Fengguang | 95615d9 | 2009-04-14 21:53:48 -0700 | [diff] [blame] | 5057 | r_idx = skb->queue_mapping; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5058 | tx_ring = &adapter->tx_ring[r_idx]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5059 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5060 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 5061 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5062 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5063 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
| 5064 | tx_flags |= (skb->queue_mapping << 13); |
| 5065 | } |
| 5066 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5067 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5068 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5069 | tx_flags |= (skb->queue_mapping << 13); |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5070 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5071 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5072 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5073 | |
| 5074 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 5075 | (skb->protocol == htons(ETH_P_FCOE))) |
| 5076 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
| 5077 | |
| 5078 | /* four things can cause us to need a context descriptor */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5079 | if (skb_is_gso(skb) || |
| 5080 | (skb->ip_summed == CHECKSUM_PARTIAL) || |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5081 | (tx_flags & IXGBE_TX_FLAGS_VLAN) || |
| 5082 | (tx_flags & IXGBE_TX_FLAGS_FCOE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5083 | count++; |
| 5084 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5085 | count += TXD_USE_COUNT(skb_headlen(skb)); |
| 5086 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5087 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 5088 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5089 | if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5090 | adapter->tx_busy++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5091 | return NETDEV_TX_BUSY; |
| 5092 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5093 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5094 | first = tx_ring->next_to_use; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5095 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5096 | #ifdef IXGBE_FCOE |
| 5097 | /* setup tx offload for FCoE */ |
| 5098 | tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5099 | if (tso < 0) { |
| 5100 | dev_kfree_skb_any(skb); |
| 5101 | return NETDEV_TX_OK; |
| 5102 | } |
| 5103 | if (tso) |
| 5104 | tx_flags |= IXGBE_TX_FLAGS_FSO; |
| 5105 | #endif /* IXGBE_FCOE */ |
| 5106 | } else { |
| 5107 | if (skb->protocol == htons(ETH_P_IP)) |
| 5108 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
| 5109 | tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5110 | if (tso < 0) { |
| 5111 | dev_kfree_skb_any(skb); |
| 5112 | return NETDEV_TX_OK; |
| 5113 | } |
| 5114 | |
| 5115 | if (tso) |
| 5116 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
| 5117 | else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) && |
| 5118 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5119 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5120 | } |
| 5121 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5122 | count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5123 | if (count) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 5124 | /* add the ATR filter if ATR is on */ |
| 5125 | if (tx_ring->atr_sample_rate) { |
| 5126 | ++tx_ring->atr_count; |
| 5127 | if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) && |
| 5128 | test_bit(__IXGBE_FDIR_INIT_DONE, |
| 5129 | &tx_ring->reinit_state)) { |
| 5130 | ixgbe_atr(adapter, skb, tx_ring->queue_index, |
| 5131 | tx_flags); |
| 5132 | tx_ring->atr_count = 0; |
| 5133 | } |
| 5134 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5135 | ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len, |
| 5136 | hdr_len); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5137 | ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5138 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5139 | } else { |
| 5140 | dev_kfree_skb_any(skb); |
| 5141 | tx_ring->tx_buffer_info[first].time_stamp = 0; |
| 5142 | tx_ring->next_to_use = first; |
| 5143 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5144 | |
| 5145 | return NETDEV_TX_OK; |
| 5146 | } |
| 5147 | |
| 5148 | /** |
| 5149 | * ixgbe_get_stats - Get System Network Statistics |
| 5150 | * @netdev: network interface device structure |
| 5151 | * |
| 5152 | * Returns the address of the device statistics structure. |
| 5153 | * The statistics are actually updated from the timer callback. |
| 5154 | **/ |
| 5155 | static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev) |
| 5156 | { |
| 5157 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5158 | |
| 5159 | /* only return the current stats */ |
| 5160 | return &adapter->net_stats; |
| 5161 | } |
| 5162 | |
| 5163 | /** |
| 5164 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 5165 | * @netdev: network interface device structure |
| 5166 | * @p: pointer to an address structure |
| 5167 | * |
| 5168 | * Returns 0 on success, negative on failure |
| 5169 | **/ |
| 5170 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 5171 | { |
| 5172 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5173 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5174 | struct sockaddr *addr = p; |
| 5175 | |
| 5176 | if (!is_valid_ether_addr(addr->sa_data)) |
| 5177 | return -EADDRNOTAVAIL; |
| 5178 | |
| 5179 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5180 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5181 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5182 | 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] | 5183 | |
| 5184 | return 0; |
| 5185 | } |
| 5186 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5187 | static int |
| 5188 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 5189 | { |
| 5190 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5191 | struct ixgbe_hw *hw = &adapter->hw; |
| 5192 | u16 value; |
| 5193 | int rc; |
| 5194 | |
| 5195 | if (prtad != hw->phy.mdio.prtad) |
| 5196 | return -EINVAL; |
| 5197 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 5198 | if (!rc) |
| 5199 | rc = value; |
| 5200 | return rc; |
| 5201 | } |
| 5202 | |
| 5203 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 5204 | u16 addr, u16 value) |
| 5205 | { |
| 5206 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5207 | struct ixgbe_hw *hw = &adapter->hw; |
| 5208 | |
| 5209 | if (prtad != hw->phy.mdio.prtad) |
| 5210 | return -EINVAL; |
| 5211 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 5212 | } |
| 5213 | |
| 5214 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 5215 | { |
| 5216 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5217 | |
| 5218 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 5219 | } |
| 5220 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5221 | /** |
| 5222 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
| 5223 | * netdev->dev_addr_list |
| 5224 | * @netdev: network interface device structure |
| 5225 | * |
| 5226 | * Returns non-zero on failure |
| 5227 | **/ |
| 5228 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 5229 | { |
| 5230 | int err = 0; |
| 5231 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5232 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5233 | |
| 5234 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5235 | rtnl_lock(); |
| 5236 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5237 | rtnl_unlock(); |
| 5238 | } |
| 5239 | return err; |
| 5240 | } |
| 5241 | |
| 5242 | /** |
| 5243 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
| 5244 | * netdev->dev_addr_list |
| 5245 | * @netdev: network interface device structure |
| 5246 | * |
| 5247 | * Returns non-zero on failure |
| 5248 | **/ |
| 5249 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 5250 | { |
| 5251 | int err = 0; |
| 5252 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5253 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5254 | |
| 5255 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5256 | rtnl_lock(); |
| 5257 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5258 | rtnl_unlock(); |
| 5259 | } |
| 5260 | return err; |
| 5261 | } |
| 5262 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5263 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5264 | /* |
| 5265 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5266 | * without having to re-enable interrupts. It's not called while |
| 5267 | * the interrupt routine is executing. |
| 5268 | */ |
| 5269 | static void ixgbe_netpoll(struct net_device *netdev) |
| 5270 | { |
| 5271 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5272 | |
| 5273 | disable_irq(adapter->pdev->irq); |
| 5274 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
| 5275 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 5276 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
| 5277 | enable_irq(adapter->pdev->irq); |
| 5278 | } |
| 5279 | #endif |
| 5280 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5281 | static const struct net_device_ops ixgbe_netdev_ops = { |
| 5282 | .ndo_open = ixgbe_open, |
| 5283 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5284 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5285 | .ndo_select_queue = ixgbe_select_queue, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5286 | .ndo_get_stats = ixgbe_get_stats, |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 5287 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5288 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 5289 | .ndo_validate_addr = eth_validate_addr, |
| 5290 | .ndo_set_mac_address = ixgbe_set_mac, |
| 5291 | .ndo_change_mtu = ixgbe_change_mtu, |
| 5292 | .ndo_tx_timeout = ixgbe_tx_timeout, |
| 5293 | .ndo_vlan_rx_register = ixgbe_vlan_rx_register, |
| 5294 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 5295 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5296 | .ndo_do_ioctl = ixgbe_ioctl, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5297 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5298 | .ndo_poll_controller = ixgbe_netpoll, |
| 5299 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5300 | #ifdef IXGBE_FCOE |
| 5301 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
| 5302 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
| 5303 | #endif /* IXGBE_FCOE */ |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5304 | }; |
| 5305 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5306 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5307 | * ixgbe_probe - Device Initialization Routine |
| 5308 | * @pdev: PCI device information struct |
| 5309 | * @ent: entry in ixgbe_pci_tbl |
| 5310 | * |
| 5311 | * Returns 0 on success, negative on failure |
| 5312 | * |
| 5313 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 5314 | * The OS initialization, configuring of the adapter private structure, |
| 5315 | * and a hardware reset occur. |
| 5316 | **/ |
| 5317 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5318 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5319 | { |
| 5320 | struct net_device *netdev; |
| 5321 | struct ixgbe_adapter *adapter = NULL; |
| 5322 | struct ixgbe_hw *hw; |
| 5323 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5324 | static int cards_found; |
| 5325 | int i, err, pci_using_dac; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5326 | #ifdef IXGBE_FCOE |
| 5327 | u16 device_caps; |
| 5328 | #endif |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5329 | u32 part_num, eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5330 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5331 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5332 | if (err) |
| 5333 | return err; |
| 5334 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 5335 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 5336 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5337 | pci_using_dac = 1; |
| 5338 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5339 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5340 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5341 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5342 | if (err) { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5343 | dev_err(&pdev->dev, "No usable DMA " |
| 5344 | "configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5345 | goto err_dma; |
| 5346 | } |
| 5347 | } |
| 5348 | pci_using_dac = 0; |
| 5349 | } |
| 5350 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5351 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 5352 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5353 | if (err) { |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5354 | dev_err(&pdev->dev, |
| 5355 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5356 | goto err_pci_reg; |
| 5357 | } |
| 5358 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5359 | err = pci_enable_pcie_error_reporting(pdev); |
| 5360 | if (err) { |
| 5361 | dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed " |
| 5362 | "0x%x\n", err); |
| 5363 | /* non-fatal, continue */ |
| 5364 | } |
| 5365 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5366 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 5367 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5368 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5369 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5370 | if (!netdev) { |
| 5371 | err = -ENOMEM; |
| 5372 | goto err_alloc_etherdev; |
| 5373 | } |
| 5374 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5375 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 5376 | |
| 5377 | pci_set_drvdata(pdev, netdev); |
| 5378 | adapter = netdev_priv(netdev); |
| 5379 | |
| 5380 | adapter->netdev = netdev; |
| 5381 | adapter->pdev = pdev; |
| 5382 | hw = &adapter->hw; |
| 5383 | hw->back = adapter; |
| 5384 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 5385 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 5386 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 5387 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5388 | if (!hw->hw_addr) { |
| 5389 | err = -EIO; |
| 5390 | goto err_ioremap; |
| 5391 | } |
| 5392 | |
| 5393 | for (i = 1; i <= 5; i++) { |
| 5394 | if (pci_resource_len(pdev, i) == 0) |
| 5395 | continue; |
| 5396 | } |
| 5397 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5398 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5399 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5400 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5401 | strcpy(netdev->name, pci_name(pdev)); |
| 5402 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5403 | adapter->bd_number = cards_found; |
| 5404 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5405 | /* Setup hw api */ |
| 5406 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5407 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5408 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5409 | /* EEPROM */ |
| 5410 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 5411 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 5412 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 5413 | if (!(eec & (1 << 8))) |
| 5414 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 5415 | |
| 5416 | /* PHY */ |
| 5417 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5418 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5419 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 5420 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 5421 | hw->phy.mdio.mmds = 0; |
| 5422 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 5423 | hw->phy.mdio.dev = netdev; |
| 5424 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 5425 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5426 | |
| 5427 | /* set up this timer and work struct before calling get_invariants |
| 5428 | * which might start the timer |
| 5429 | */ |
| 5430 | init_timer(&adapter->sfp_timer); |
| 5431 | adapter->sfp_timer.function = &ixgbe_sfp_timer; |
| 5432 | adapter->sfp_timer.data = (unsigned long) adapter; |
| 5433 | |
| 5434 | INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5435 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5436 | /* multispeed fiber has its own tasklet, called from GPI SDP1 context */ |
| 5437 | INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task); |
| 5438 | |
| 5439 | /* a new SFP+ module arrival, called from GPI SDP2 context */ |
| 5440 | INIT_WORK(&adapter->sfp_config_module_task, |
| 5441 | ixgbe_sfp_config_module_task); |
| 5442 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5443 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5444 | |
| 5445 | /* setup the private structure */ |
| 5446 | err = ixgbe_sw_init(adapter); |
| 5447 | if (err) |
| 5448 | goto err_sw_init; |
| 5449 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5450 | /* |
| 5451 | * If there is a fan on this device and it has failed log the |
| 5452 | * failure. |
| 5453 | */ |
| 5454 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5455 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5456 | if (esdp & IXGBE_ESDP_SDP1) |
| 5457 | DPRINTK(PROBE, CRIT, |
| 5458 | "Fan has stopped, replace the adapter\n"); |
| 5459 | } |
| 5460 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5461 | /* reset_hw fills in the perm_addr as well */ |
| 5462 | err = hw->mac.ops.reset_hw(hw); |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5463 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 5464 | hw->mac.type == ixgbe_mac_82598EB) { |
| 5465 | /* |
| 5466 | * Start a kernel thread to watch for a module to arrive. |
| 5467 | * Only do this for 82598, since 82599 will generate |
| 5468 | * interrupts on module arrival. |
| 5469 | */ |
| 5470 | set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5471 | mod_timer(&adapter->sfp_timer, |
| 5472 | round_jiffies(jiffies + (2 * HZ))); |
| 5473 | err = 0; |
| 5474 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5475 | dev_err(&adapter->pdev->dev, "failed to load because an " |
| 5476 | "unsupported SFP+ module type was detected.\n"); |
| 5477 | goto err_sw_init; |
| 5478 | } else if (err) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5479 | dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err); |
| 5480 | goto err_sw_init; |
| 5481 | } |
| 5482 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5483 | netdev->features = NETIF_F_SG | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5484 | NETIF_F_IP_CSUM | |
| 5485 | NETIF_F_HW_VLAN_TX | |
| 5486 | NETIF_F_HW_VLAN_RX | |
| 5487 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5488 | |
Jesse Brandeburg | e9990a9 | 2008-08-26 04:27:24 -0700 | [diff] [blame] | 5489 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5490 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5491 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 5492 | netdev->features |= NETIF_F_GRO; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5493 | |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5494 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 5495 | netdev->features |= NETIF_F_SCTP_CSUM; |
| 5496 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5497 | netdev->vlan_features |= NETIF_F_TSO; |
| 5498 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 5499 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5500 | netdev->vlan_features |= NETIF_F_SG; |
| 5501 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5502 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 5503 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
| 5504 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5505 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5506 | netdev->dcbnl_ops = &dcbnl_ops; |
| 5507 | #endif |
| 5508 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5509 | #ifdef IXGBE_FCOE |
| 5510 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 5511 | if (hw->mac.ops.get_device_caps) { |
| 5512 | hw->mac.ops.get_device_caps(hw, &device_caps); |
| 5513 | if (!(device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)) { |
| 5514 | netdev->features |= NETIF_F_FCOE_CRC; |
| 5515 | netdev->features |= NETIF_F_FSO; |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5516 | netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 5517 | DPRINTK(DRV, INFO, "FCoE enabled, " |
| 5518 | "disabling Flow Director\n"); |
| 5519 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 5520 | adapter->flags &= |
| 5521 | ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 5522 | adapter->atr_sample_rate = 0; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5523 | } else { |
| 5524 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5525 | } |
| 5526 | } |
| 5527 | } |
| 5528 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5529 | if (pci_using_dac) |
| 5530 | netdev->features |= NETIF_F_HIGHDMA; |
| 5531 | |
Peter P Waskiewicz Jr | df647b5 | 2009-06-04 16:00:47 +0000 | [diff] [blame] | 5532 | if (adapter->flags & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5533 | netdev->features |= NETIF_F_LRO; |
| 5534 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5535 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5536 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5537 | dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); |
| 5538 | err = -EIO; |
| 5539 | goto err_eeprom; |
| 5540 | } |
| 5541 | |
| 5542 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5543 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5544 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5545 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
| 5546 | dev_err(&pdev->dev, "invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5547 | err = -EIO; |
| 5548 | goto err_eeprom; |
| 5549 | } |
| 5550 | |
| 5551 | init_timer(&adapter->watchdog_timer); |
| 5552 | adapter->watchdog_timer.function = &ixgbe_watchdog; |
| 5553 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 5554 | |
| 5555 | INIT_WORK(&adapter->reset_task, ixgbe_reset_task); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5556 | INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5557 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5558 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5559 | if (err) |
| 5560 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5561 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5562 | switch (pdev->device) { |
| 5563 | case IXGBE_DEV_ID_82599_KX4: |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5564 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
| 5565 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
Peter P Waskiewicz Jr | bdf0a55 | 2009-06-04 11:09:58 +0000 | [diff] [blame] | 5566 | /* Enable ACPI wakeup in GRC */ |
| 5567 | IXGBE_WRITE_REG(hw, IXGBE_GRC, |
| 5568 | (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5569 | break; |
| 5570 | default: |
| 5571 | adapter->wol = 0; |
| 5572 | break; |
| 5573 | } |
| 5574 | device_init_wakeup(&adapter->pdev->dev, true); |
| 5575 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 5576 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5577 | /* pick up the PCI bus settings for reporting later */ |
| 5578 | hw->mac.ops.get_bus_info(hw); |
| 5579 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5580 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5581 | dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n", |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5582 | ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s": |
| 5583 | (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"), |
| 5584 | ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" : |
| 5585 | (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" : |
| 5586 | (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" : |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5587 | "Unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5588 | netdev->dev_addr); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5589 | ixgbe_read_pba_num_generic(hw, &part_num); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5590 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 5591 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n", |
| 5592 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
| 5593 | (part_num >> 8), (part_num & 0xff)); |
| 5594 | else |
| 5595 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", |
| 5596 | hw->mac.type, hw->phy.type, |
| 5597 | (part_num >> 8), (part_num & 0xff)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5598 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5599 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5600 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5601 | "this card is not sufficient for optimal " |
| 5602 | "performance.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5603 | dev_warn(&pdev->dev, "For optimal performance a x8 " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5604 | "PCI-Express slot is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5605 | } |
| 5606 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 5607 | /* save off EEPROM version number */ |
| 5608 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 5609 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5610 | /* reset the hardware with the new settings */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5611 | hw->mac.ops.start_hw(hw); |
| 5612 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5613 | strcpy(netdev->name, "eth%d"); |
| 5614 | err = register_netdev(netdev); |
| 5615 | if (err) |
| 5616 | goto err_register; |
| 5617 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5618 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 5619 | netif_carrier_off(netdev); |
| 5620 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 5621 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5622 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5623 | INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task); |
| 5624 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5625 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 5626 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5627 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5628 | ixgbe_setup_dca(adapter); |
| 5629 | } |
| 5630 | #endif |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5631 | /* add san mac addr to netdev */ |
| 5632 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5633 | |
| 5634 | dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n"); |
| 5635 | cards_found++; |
| 5636 | return 0; |
| 5637 | |
| 5638 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5639 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5640 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5641 | err_sw_init: |
| 5642 | err_eeprom: |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5643 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5644 | del_timer_sync(&adapter->sfp_timer); |
| 5645 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5646 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5647 | cancel_work_sync(&adapter->sfp_config_module_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5648 | iounmap(hw->hw_addr); |
| 5649 | err_ioremap: |
| 5650 | free_netdev(netdev); |
| 5651 | err_alloc_etherdev: |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5652 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 5653 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5654 | err_pci_reg: |
| 5655 | err_dma: |
| 5656 | pci_disable_device(pdev); |
| 5657 | return err; |
| 5658 | } |
| 5659 | |
| 5660 | /** |
| 5661 | * ixgbe_remove - Device Removal Routine |
| 5662 | * @pdev: PCI device information struct |
| 5663 | * |
| 5664 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 5665 | * that it should release a PCI device. The could be caused by a |
| 5666 | * Hot-Plug event, or because the driver is going to be removed from |
| 5667 | * memory. |
| 5668 | **/ |
| 5669 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 5670 | { |
| 5671 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5672 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5673 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5674 | |
| 5675 | set_bit(__IXGBE_DOWN, &adapter->state); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5676 | /* clear the module not found bit to make sure the worker won't |
| 5677 | * reschedule |
| 5678 | */ |
| 5679 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5680 | del_timer_sync(&adapter->watchdog_timer); |
| 5681 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5682 | del_timer_sync(&adapter->sfp_timer); |
| 5683 | cancel_work_sync(&adapter->watchdog_task); |
| 5684 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5685 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5686 | cancel_work_sync(&adapter->sfp_config_module_task); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame^] | 5687 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5688 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5689 | cancel_work_sync(&adapter->fdir_reinit_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5690 | flush_scheduled_work(); |
| 5691 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5692 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5693 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 5694 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 5695 | dca_remove_requester(&pdev->dev); |
| 5696 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 5697 | } |
| 5698 | |
| 5699 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5700 | #ifdef IXGBE_FCOE |
| 5701 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 5702 | ixgbe_cleanup_fcoe(adapter); |
| 5703 | |
| 5704 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5705 | |
| 5706 | /* remove the added san mac */ |
| 5707 | ixgbe_del_sanmac_netdev(netdev); |
| 5708 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5709 | if (netdev->reg_state == NETREG_REGISTERED) |
| 5710 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5711 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5712 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5713 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5714 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5715 | |
| 5716 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5717 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 5718 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5719 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5720 | DPRINTK(PROBE, INFO, "complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5721 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5722 | free_netdev(netdev); |
| 5723 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5724 | err = pci_disable_pcie_error_reporting(pdev); |
| 5725 | if (err) |
| 5726 | dev_err(&pdev->dev, |
| 5727 | "pci_disable_pcie_error_reporting failed 0x%x\n", err); |
| 5728 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5729 | pci_disable_device(pdev); |
| 5730 | } |
| 5731 | |
| 5732 | /** |
| 5733 | * ixgbe_io_error_detected - called when PCI error is detected |
| 5734 | * @pdev: Pointer to PCI device |
| 5735 | * @state: The current pci connection state |
| 5736 | * |
| 5737 | * This function is called after a PCI bus error affecting |
| 5738 | * this device has been detected. |
| 5739 | */ |
| 5740 | 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] | 5741 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5742 | { |
| 5743 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 5744 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5745 | |
| 5746 | netif_device_detach(netdev); |
| 5747 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 5748 | if (state == pci_channel_io_perm_failure) |
| 5749 | return PCI_ERS_RESULT_DISCONNECT; |
| 5750 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5751 | if (netif_running(netdev)) |
| 5752 | ixgbe_down(adapter); |
| 5753 | pci_disable_device(pdev); |
| 5754 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5755 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5756 | return PCI_ERS_RESULT_NEED_RESET; |
| 5757 | } |
| 5758 | |
| 5759 | /** |
| 5760 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 5761 | * @pdev: Pointer to PCI device |
| 5762 | * |
| 5763 | * Restart the card from scratch, as if from a cold-boot. |
| 5764 | */ |
| 5765 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 5766 | { |
| 5767 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 5768 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5769 | pci_ers_result_t result; |
| 5770 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5771 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5772 | if (pci_enable_device_mem(pdev)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5773 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5774 | "Cannot re-enable PCI device after reset.\n"); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5775 | result = PCI_ERS_RESULT_DISCONNECT; |
| 5776 | } else { |
| 5777 | pci_set_master(pdev); |
| 5778 | pci_restore_state(pdev); |
| 5779 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5780 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5781 | |
| 5782 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 5783 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5784 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5785 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5786 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5787 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 5788 | if (err) { |
| 5789 | dev_err(&pdev->dev, |
| 5790 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err); |
| 5791 | /* non-fatal, continue */ |
| 5792 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5793 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5794 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5795 | } |
| 5796 | |
| 5797 | /** |
| 5798 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 5799 | * @pdev: Pointer to PCI device |
| 5800 | * |
| 5801 | * This callback is called when the error recovery driver tells us that |
| 5802 | * its OK to resume normal operation. |
| 5803 | */ |
| 5804 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 5805 | { |
| 5806 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 5807 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5808 | |
| 5809 | if (netif_running(netdev)) { |
| 5810 | if (ixgbe_up(adapter)) { |
| 5811 | DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n"); |
| 5812 | return; |
| 5813 | } |
| 5814 | } |
| 5815 | |
| 5816 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | static struct pci_error_handlers ixgbe_err_handler = { |
| 5820 | .error_detected = ixgbe_io_error_detected, |
| 5821 | .slot_reset = ixgbe_io_slot_reset, |
| 5822 | .resume = ixgbe_io_resume, |
| 5823 | }; |
| 5824 | |
| 5825 | static struct pci_driver ixgbe_driver = { |
| 5826 | .name = ixgbe_driver_name, |
| 5827 | .id_table = ixgbe_pci_tbl, |
| 5828 | .probe = ixgbe_probe, |
| 5829 | .remove = __devexit_p(ixgbe_remove), |
| 5830 | #ifdef CONFIG_PM |
| 5831 | .suspend = ixgbe_suspend, |
| 5832 | .resume = ixgbe_resume, |
| 5833 | #endif |
| 5834 | .shutdown = ixgbe_shutdown, |
| 5835 | .err_handler = &ixgbe_err_handler |
| 5836 | }; |
| 5837 | |
| 5838 | /** |
| 5839 | * ixgbe_init_module - Driver Registration Routine |
| 5840 | * |
| 5841 | * ixgbe_init_module is the first routine called when the driver is |
| 5842 | * loaded. All it does is register with the PCI subsystem. |
| 5843 | **/ |
| 5844 | static int __init ixgbe_init_module(void) |
| 5845 | { |
| 5846 | int ret; |
| 5847 | printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name, |
| 5848 | ixgbe_driver_string, ixgbe_driver_version); |
| 5849 | |
| 5850 | printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright); |
| 5851 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5852 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5853 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5854 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5855 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5856 | ret = pci_register_driver(&ixgbe_driver); |
| 5857 | return ret; |
| 5858 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5859 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5860 | module_init(ixgbe_init_module); |
| 5861 | |
| 5862 | /** |
| 5863 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 5864 | * |
| 5865 | * ixgbe_exit_module is called just before the driver is removed |
| 5866 | * from memory. |
| 5867 | **/ |
| 5868 | static void __exit ixgbe_exit_module(void) |
| 5869 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5870 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5871 | dca_unregister_notify(&dca_notifier); |
| 5872 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5873 | pci_unregister_driver(&ixgbe_driver); |
| 5874 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5875 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5876 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5877 | 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] | 5878 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5879 | { |
| 5880 | int ret_val; |
| 5881 | |
| 5882 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5883 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5884 | |
| 5885 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 5886 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5887 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 5888 | #endif /* CONFIG_IXGBE_DCA */ |
| 5889 | #ifdef DEBUG |
| 5890 | /** |
| 5891 | * ixgbe_get_hw_dev_name - return device name string |
| 5892 | * used by hardware layer to print debugging information |
| 5893 | **/ |
| 5894 | char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw) |
| 5895 | { |
| 5896 | struct ixgbe_adapter *adapter = hw->back; |
| 5897 | return adapter->netdev->name; |
| 5898 | } |
| 5899 | |
| 5900 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5901 | module_exit(ixgbe_exit_module); |
| 5902 | |
| 5903 | /* ixgbe_main.c */ |