Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Peter P Waskiewicz Jr | 3efac5a | 2009-02-01 01:19:20 -0800 | [diff] [blame] | 4 | Copyright(c) 1999 - 2009 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/vmalloc.h> |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/in.h> |
| 35 | #include <linux/ip.h> |
| 36 | #include <linux/tcp.h> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 37 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 38 | #include <linux/ipv6.h> |
| 39 | #include <net/checksum.h> |
| 40 | #include <net/ip6_checksum.h> |
| 41 | #include <linux/ethtool.h> |
| 42 | #include <linux/if_vlan.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 43 | #include <scsi/fc/fc_fcoe.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 44 | |
| 45 | #include "ixgbe.h" |
| 46 | #include "ixgbe_common.h" |
| 47 | |
| 48 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 49 | static const char ixgbe_driver_string[] = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 50 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 51 | |
Peter P Waskiewicz Jr | e0f4daf | 2009-09-30 12:07:57 +0000 | [diff] [blame] | 52 | #define DRV_VERSION "2.0.44-k2" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 53 | const char ixgbe_driver_version[] = DRV_VERSION; |
Peter P Waskiewicz Jr | 3efac5a | 2009-02-01 01:19:20 -0800 | [diff] [blame] | 54 | static char ixgbe_copyright[] = "Copyright (c) 1999-2009 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 55 | |
| 56 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 57 | [board_82598] = &ixgbe_82598_info, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 58 | [board_82599] = &ixgbe_82599_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 62 | * |
| 63 | * Wildcard entries (PCI_ANY_ID) should come last |
| 64 | * Last entry must be all 0s |
| 65 | * |
| 66 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 67 | * Class, Class Mask, private data (not used) } |
| 68 | */ |
| 69 | static struct pci_device_id ixgbe_pci_tbl[] = { |
Don Skidmore | 1e336d0 | 2009-01-26 20:57:51 -0800 | [diff] [blame] | 70 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), |
| 71 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 72 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 73 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 74 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 75 | board_82598 }, |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 76 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), |
| 77 | board_82598 }, |
Peter P Waskiewicz Jr | 3845bec | 2009-07-16 15:50:52 +0000 | [diff] [blame] | 78 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), |
| 79 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 80 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 81 | board_82598 }, |
Jesse Brandeburg | 8d792cd | 2008-08-08 16:24:19 -0700 | [diff] [blame] | 82 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), |
| 83 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 84 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), |
| 85 | board_82598 }, |
| 86 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), |
| 87 | board_82598 }, |
Jesse Brandeburg | b95f5fc | 2008-09-11 19:58:59 -0700 | [diff] [blame] | 88 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), |
| 89 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 90 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), |
| 91 | board_82598 }, |
Don Skidmore | 2f21bdd | 2009-02-01 01:18:23 -0800 | [diff] [blame] | 92 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), |
| 93 | board_82598 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 94 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), |
| 95 | board_82599 }, |
Peter P Waskiewicz Jr | 1fcf03e | 2009-05-17 20:58:04 +0000 | [diff] [blame] | 96 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), |
| 97 | board_82599 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 98 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), |
| 99 | board_82599 }, |
Don Skidmore | 38ad1c8 | 2009-10-08 15:35:58 +0000 | [diff] [blame^] | 100 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), |
| 101 | board_82599 }, |
Don Skidmore | dbfec66 | 2009-10-02 08:58:25 +0000 | [diff] [blame] | 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), |
| 103 | board_82599 }, |
Peter P Waskiewicz Jr | 8911184 | 2009-09-14 07:47:49 +0000 | [diff] [blame] | 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), |
| 105 | board_82599 }, |
Don Skidmore | 312eb93 | 2009-10-02 08:58:04 +0000 | [diff] [blame] | 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), |
| 107 | board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 108 | |
| 109 | /* required last entry */ |
| 110 | {0, } |
| 111 | }; |
| 112 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 113 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 114 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 115 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 116 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 117 | static struct notifier_block dca_notifier = { |
| 118 | .notifier_call = ixgbe_notify_dca, |
| 119 | .next = NULL, |
| 120 | .priority = 0 |
| 121 | }; |
| 122 | #endif |
| 123 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 124 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 125 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 126 | MODULE_LICENSE("GPL"); |
| 127 | MODULE_VERSION(DRV_VERSION); |
| 128 | |
| 129 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 130 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 131 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 132 | { |
| 133 | u32 ctrl_ext; |
| 134 | |
| 135 | /* Let firmware take over control of h/w */ |
| 136 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 137 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 138 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 142 | { |
| 143 | u32 ctrl_ext; |
| 144 | |
| 145 | /* Let firmware know the driver has taken over */ |
| 146 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 147 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 148 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 149 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 150 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 151 | /* |
| 152 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 153 | * @adapter: pointer to adapter struct |
| 154 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 155 | * @queue: queue to map the corresponding interrupt to |
| 156 | * @msix_vector: the vector to map to the corresponding queue |
| 157 | * |
| 158 | */ |
| 159 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
| 160 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 161 | { |
| 162 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 163 | struct ixgbe_hw *hw = &adapter->hw; |
| 164 | switch (hw->mac.type) { |
| 165 | case ixgbe_mac_82598EB: |
| 166 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 167 | if (direction == -1) |
| 168 | direction = 0; |
| 169 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 170 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 171 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 172 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 173 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 174 | break; |
| 175 | case ixgbe_mac_82599EB: |
| 176 | if (direction == -1) { |
| 177 | /* other causes */ |
| 178 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 179 | index = ((queue & 1) * 8); |
| 180 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 181 | ivar &= ~(0xFF << index); |
| 182 | ivar |= (msix_vector << index); |
| 183 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 184 | break; |
| 185 | } else { |
| 186 | /* tx or rx causes */ |
| 187 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 188 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 189 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 190 | ivar &= ~(0xFF << index); |
| 191 | ivar |= (msix_vector << index); |
| 192 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 193 | break; |
| 194 | } |
| 195 | default: |
| 196 | break; |
| 197 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 200 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
| 201 | u64 qmask) |
| 202 | { |
| 203 | u32 mask; |
| 204 | |
| 205 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 206 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 207 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
| 208 | } else { |
| 209 | mask = (qmask & 0xFFFFFFFF); |
| 210 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 211 | mask = (qmask >> 32); |
| 212 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
| 213 | } |
| 214 | } |
| 215 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 216 | 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] | 217 | struct ixgbe_tx_buffer |
| 218 | *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 219 | { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 220 | tx_buffer_info->dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 221 | if (tx_buffer_info->skb) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 222 | skb_dma_unmap(&adapter->pdev->dev, tx_buffer_info->skb, |
| 223 | DMA_TO_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 224 | dev_kfree_skb_any(tx_buffer_info->skb); |
| 225 | tx_buffer_info->skb = NULL; |
| 226 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 227 | tx_buffer_info->time_stamp = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 228 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 229 | } |
| 230 | |
| 231 | static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 232 | struct ixgbe_ring *tx_ring, |
| 233 | unsigned int eop) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 234 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 235 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 236 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 237 | /* Detect a transmit hang in hardware, this serializes the |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 238 | * check with the clearing of time_stamp and movement of eop */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 239 | adapter->detect_tx_hung = false; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 240 | if (tx_ring->tx_buffer_info[eop].time_stamp && |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 241 | time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) && |
| 242 | !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) { |
| 243 | /* detected Tx unit hang */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 244 | union ixgbe_adv_tx_desc *tx_desc; |
| 245 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 246 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 247 | " Tx Queue <%d>\n" |
| 248 | " TDH, TDT <%x>, <%x>\n" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 249 | " next_to_use <%x>\n" |
| 250 | " next_to_clean <%x>\n" |
| 251 | "tx_buffer_info[next_to_clean]\n" |
| 252 | " time_stamp <%lx>\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 253 | " jiffies <%lx>\n", |
| 254 | tx_ring->queue_index, |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 255 | IXGBE_READ_REG(hw, tx_ring->head), |
| 256 | IXGBE_READ_REG(hw, tx_ring->tail), |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 257 | tx_ring->next_to_use, eop, |
| 258 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 259 | return true; |
| 260 | } |
| 261 | |
| 262 | return false; |
| 263 | } |
| 264 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 265 | #define IXGBE_MAX_TXD_PWR 14 |
| 266 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 267 | |
| 268 | /* Tx Descriptors needed, worst case */ |
| 269 | #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \ |
| 270 | (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) |
| 271 | #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] | 272 | MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 273 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 274 | static void ixgbe_tx_timeout(struct net_device *netdev); |
| 275 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 276 | /** |
| 277 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 278 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 279 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 280 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 281 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 282 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 283 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 284 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 285 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 286 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 287 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 288 | unsigned int i, eop, count = 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 289 | unsigned int total_bytes = 0, total_packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 290 | |
| 291 | i = tx_ring->next_to_clean; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 292 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 293 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 294 | |
| 295 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 296 | (count < tx_ring->work_limit)) { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 297 | bool cleaned = false; |
| 298 | for ( ; !cleaned; count++) { |
| 299 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 300 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 301 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 302 | cleaned = (i == eop); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 303 | skb = tx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 304 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 305 | if (cleaned && skb) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 306 | unsigned int segs, bytecount; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 307 | unsigned int hlen = skb_headlen(skb); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 308 | |
| 309 | /* gso_segs is currently only valid for tcp */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 310 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 311 | #ifdef IXGBE_FCOE |
| 312 | /* adjust for FCoE Sequence Offload */ |
| 313 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 314 | && (skb->protocol == htons(ETH_P_FCOE)) && |
| 315 | skb_is_gso(skb)) { |
| 316 | hlen = skb_transport_offset(skb) + |
| 317 | sizeof(struct fc_frame_header) + |
| 318 | sizeof(struct fcoe_crc_eof); |
| 319 | segs = DIV_ROUND_UP(skb->len - hlen, |
| 320 | skb_shinfo(skb)->gso_size); |
| 321 | } |
| 322 | #endif /* IXGBE_FCOE */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 323 | /* multiply data chunks by size of headers */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 324 | bytecount = ((segs - 1) * hlen) + skb->len; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 325 | total_packets += segs; |
| 326 | total_bytes += bytecount; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 327 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 328 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 329 | ixgbe_unmap_and_free_tx_resource(adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 330 | tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 331 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 332 | tx_desc->wb.status = 0; |
| 333 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 334 | i++; |
| 335 | if (i == tx_ring->count) |
| 336 | i = 0; |
| 337 | } |
| 338 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 339 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 340 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 341 | } |
| 342 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 343 | tx_ring->next_to_clean = i; |
| 344 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 345 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 346 | if (unlikely(count && netif_carrier_ok(netdev) && |
| 347 | (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 348 | /* Make sure that anybody stopping the queue after this |
| 349 | * sees the new next_to_clean. |
| 350 | */ |
| 351 | smp_mb(); |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 352 | if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) && |
| 353 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 354 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 355 | ++adapter->restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 356 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 357 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 358 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 359 | if (adapter->detect_tx_hung) { |
| 360 | if (ixgbe_check_tx_hang(adapter, tx_ring, i)) { |
| 361 | /* schedule immediate reset if we believe we hung */ |
| 362 | DPRINTK(PROBE, INFO, |
| 363 | "tx hang %d detected, resetting adapter\n", |
| 364 | adapter->tx_timeout_count + 1); |
| 365 | ixgbe_tx_timeout(adapter->netdev); |
| 366 | } |
| 367 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 368 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 369 | /* re-arm the interrupt */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 370 | if (count >= tx_ring->work_limit) |
| 371 | ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 372 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 373 | tx_ring->total_bytes += total_bytes; |
| 374 | tx_ring->total_packets += total_packets; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 375 | tx_ring->stats.packets += total_packets; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 376 | tx_ring->stats.bytes += total_bytes; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 377 | netdev->stats.tx_bytes += total_bytes; |
| 378 | netdev->stats.tx_packets += total_packets; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 379 | return (count < tx_ring->work_limit); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 382 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 383 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 384 | struct ixgbe_ring *rx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 385 | { |
| 386 | u32 rxctrl; |
| 387 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 388 | int q = rx_ring - adapter->rx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 389 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 390 | if (rx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 391 | rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 392 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 393 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 394 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 395 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 396 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 397 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 398 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 399 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 400 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 401 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
Don Skidmore | 15005a3 | 2009-01-19 16:54:13 -0800 | [diff] [blame] | 402 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
| 403 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 404 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 405 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 406 | rx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 407 | } |
| 408 | put_cpu(); |
| 409 | } |
| 410 | |
| 411 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 412 | struct ixgbe_ring *tx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 413 | { |
| 414 | u32 txctrl; |
| 415 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 416 | int q = tx_ring - adapter->tx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 417 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 418 | if (tx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 419 | txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 420 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 421 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 422 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 423 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 424 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 425 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 426 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 427 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 428 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 429 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 430 | tx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 431 | } |
| 432 | put_cpu(); |
| 433 | } |
| 434 | |
| 435 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 436 | { |
| 437 | int i; |
| 438 | |
| 439 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 440 | return; |
| 441 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 442 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 443 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 444 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 445 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 446 | adapter->tx_ring[i].cpu = -1; |
| 447 | ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]); |
| 448 | } |
| 449 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 450 | adapter->rx_ring[i].cpu = -1; |
| 451 | ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 456 | { |
| 457 | struct net_device *netdev = dev_get_drvdata(dev); |
| 458 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 459 | unsigned long event = *(unsigned long *)data; |
| 460 | |
| 461 | switch (event) { |
| 462 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 463 | /* if we're already enabled, don't do it again */ |
| 464 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 465 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 466 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 467 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 468 | ixgbe_setup_dca(adapter); |
| 469 | break; |
| 470 | } |
| 471 | /* Fall Through since DCA is disabled. */ |
| 472 | case DCA_PROVIDER_REMOVE: |
| 473 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 474 | dca_remove_requester(dev); |
| 475 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 476 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 477 | } |
| 478 | break; |
| 479 | } |
| 480 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 481 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 482 | } |
| 483 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 484 | #endif /* CONFIG_IXGBE_DCA */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 485 | /** |
| 486 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 487 | * @adapter: board private structure |
| 488 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 489 | * @status: hardware indication of status of receive |
| 490 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 491 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 492 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 493 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 494 | struct sk_buff *skb, u8 status, |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 495 | struct ixgbe_ring *ring, |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 496 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 497 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 498 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 499 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 500 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 501 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 502 | |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 503 | skb_record_rx_queue(skb, ring->queue_index); |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 504 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) { |
Lucy Liu | 8a62bab | 2009-08-13 14:09:38 +0000 | [diff] [blame] | 505 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 506 | vlan_gro_receive(napi, adapter->vlgrp, tag, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 507 | else |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 508 | napi_gro_receive(napi, skb); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 509 | } else { |
Lucy Liu | 8a62bab | 2009-08-13 14:09:38 +0000 | [diff] [blame] | 510 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 511 | vlan_hwaccel_rx(skb, adapter->vlgrp, tag); |
| 512 | else |
| 513 | netif_rx(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 514 | } |
| 515 | } |
| 516 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 517 | /** |
| 518 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 519 | * @adapter: address of board private structure |
| 520 | * @status_err: hardware indication of status of receive |
| 521 | * @skb: skb currently being received and modified |
| 522 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 523 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 524 | union ixgbe_adv_rx_desc *rx_desc, |
| 525 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 526 | { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 527 | u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 528 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 529 | skb->ip_summed = CHECKSUM_NONE; |
| 530 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 531 | /* Rx csum disabled */ |
| 532 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 533 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 534 | |
| 535 | /* if IP and error */ |
| 536 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 537 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 538 | adapter->hw_csum_rx_error++; |
| 539 | return; |
| 540 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 541 | |
| 542 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 543 | return; |
| 544 | |
| 545 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 546 | u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 547 | |
| 548 | /* |
| 549 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 550 | * checksum errors. |
| 551 | */ |
| 552 | if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) && |
| 553 | (adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 554 | return; |
| 555 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 556 | adapter->hw_csum_rx_error++; |
| 557 | return; |
| 558 | } |
| 559 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 560 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 561 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 562 | adapter->hw_csum_rx_good++; |
| 563 | } |
| 564 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 565 | static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw, |
| 566 | struct ixgbe_ring *rx_ring, u32 val) |
| 567 | { |
| 568 | /* |
| 569 | * Force memory writes to complete before letting h/w |
| 570 | * know there are new descriptors to fetch. (Only |
| 571 | * applicable for weak-ordered memory model archs, |
| 572 | * such as IA-64). |
| 573 | */ |
| 574 | wmb(); |
| 575 | IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val); |
| 576 | } |
| 577 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 578 | /** |
| 579 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
| 580 | * @adapter: address of board private structure |
| 581 | **/ |
| 582 | static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 583 | struct ixgbe_ring *rx_ring, |
| 584 | int cleaned_count) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 585 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 586 | struct pci_dev *pdev = adapter->pdev; |
| 587 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 588 | struct ixgbe_rx_buffer *bi; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 589 | unsigned int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 590 | |
| 591 | i = rx_ring->next_to_use; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 592 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 593 | |
| 594 | while (cleaned_count--) { |
| 595 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 596 | |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 597 | if (!bi->page_dma && |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 598 | (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 599 | if (!bi->page) { |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 600 | bi->page = alloc_page(GFP_ATOMIC); |
| 601 | if (!bi->page) { |
| 602 | adapter->alloc_rx_page_failed++; |
| 603 | goto no_buffers; |
| 604 | } |
| 605 | bi->page_offset = 0; |
| 606 | } else { |
| 607 | /* use a half page if we're re-using */ |
| 608 | bi->page_offset ^= (PAGE_SIZE / 2); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 609 | } |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 610 | |
| 611 | bi->page_dma = pci_map_page(pdev, bi->page, |
| 612 | bi->page_offset, |
| 613 | (PAGE_SIZE / 2), |
| 614 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 617 | if (!bi->skb) { |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 618 | struct sk_buff *skb; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 619 | skb = netdev_alloc_skb(adapter->netdev, |
| 620 | (rx_ring->rx_buf_len + |
| 621 | NET_IP_ALIGN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 622 | |
| 623 | if (!skb) { |
| 624 | adapter->alloc_rx_buff_failed++; |
| 625 | goto no_buffers; |
| 626 | } |
| 627 | |
| 628 | /* |
| 629 | * Make buffer alignment 2 beyond a 16 byte boundary |
| 630 | * this will result in a 16 byte aligned IP header after |
| 631 | * the 14 byte MAC header is removed |
| 632 | */ |
| 633 | skb_reserve(skb, NET_IP_ALIGN); |
| 634 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 635 | bi->skb = skb; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 636 | bi->dma = pci_map_single(pdev, skb->data, |
| 637 | rx_ring->rx_buf_len, |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 638 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 639 | } |
| 640 | /* Refresh the desc even if buffer_addrs didn't change because |
| 641 | * each write-back erases this info. */ |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 642 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 643 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 644 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 645 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 646 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | i++; |
| 650 | if (i == rx_ring->count) |
| 651 | i = 0; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 652 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 653 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 654 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 655 | no_buffers: |
| 656 | if (rx_ring->next_to_use != i) { |
| 657 | rx_ring->next_to_use = i; |
| 658 | if (i-- == 0) |
| 659 | i = (rx_ring->count - 1); |
| 660 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 661 | ixgbe_release_rx_desc(&adapter->hw, rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 665 | static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc) |
| 666 | { |
| 667 | return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 668 | } |
| 669 | |
| 670 | static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc) |
| 671 | { |
| 672 | return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 673 | } |
| 674 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 675 | static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc) |
| 676 | { |
| 677 | return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & |
| 678 | IXGBE_RXDADV_RSCCNT_MASK) >> |
| 679 | IXGBE_RXDADV_RSCCNT_SHIFT; |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet |
| 684 | * @skb: pointer to the last skb in the rsc queue |
| 685 | * |
| 686 | * This function changes a queue full of hw rsc buffers into a completed |
| 687 | * packet. It uses the ->prev pointers to find the first packet and then |
| 688 | * turns it into the frag list owner. |
| 689 | **/ |
| 690 | static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb) |
| 691 | { |
| 692 | unsigned int frag_list_size = 0; |
| 693 | |
| 694 | while (skb->prev) { |
| 695 | struct sk_buff *prev = skb->prev; |
| 696 | frag_list_size += skb->len; |
| 697 | skb->prev = NULL; |
| 698 | skb = prev; |
| 699 | } |
| 700 | |
| 701 | skb_shinfo(skb)->frag_list = skb->next; |
| 702 | skb->next = NULL; |
| 703 | skb->len += frag_list_size; |
| 704 | skb->data_len += frag_list_size; |
| 705 | skb->truesize += frag_list_size; |
| 706 | return skb; |
| 707 | } |
| 708 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 709 | 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] | 710 | struct ixgbe_ring *rx_ring, |
| 711 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 712 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 713 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 714 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 715 | struct pci_dev *pdev = adapter->pdev; |
| 716 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 717 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 718 | struct sk_buff *skb; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 719 | unsigned int i, rsc_count = 0; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 720 | u32 len, staterr; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 721 | u16 hdr_info; |
| 722 | bool cleaned = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 723 | int cleaned_count = 0; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 724 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 725 | #ifdef IXGBE_FCOE |
| 726 | int ddp_bytes = 0; |
| 727 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 728 | |
| 729 | i = rx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 730 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 731 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 732 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 733 | |
| 734 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 735 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 736 | if (*work_done >= work_to_do) |
| 737 | break; |
| 738 | (*work_done)++; |
| 739 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 740 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 741 | hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc)); |
| 742 | len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 743 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 744 | if (hdr_info & IXGBE_RXDADV_SPH) |
| 745 | adapter->rx_hdr_split++; |
| 746 | if (len > IXGBE_RX_HDR_SIZE) |
| 747 | len = IXGBE_RX_HDR_SIZE; |
| 748 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 749 | } else { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 750 | len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 751 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 752 | |
| 753 | cleaned = true; |
| 754 | skb = rx_buffer_info->skb; |
| 755 | prefetch(skb->data - NET_IP_ALIGN); |
| 756 | rx_buffer_info->skb = NULL; |
| 757 | |
Alexander Duyck | 21fa4e6 | 2009-06-04 15:59:49 +0000 | [diff] [blame] | 758 | if (rx_buffer_info->dma) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 759 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 760 | rx_ring->rx_buf_len, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 761 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 762 | rx_buffer_info->dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 763 | skb_put(skb, len); |
| 764 | } |
| 765 | |
| 766 | if (upper_len) { |
| 767 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 768 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 769 | rx_buffer_info->page_dma = 0; |
| 770 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 771 | rx_buffer_info->page, |
| 772 | rx_buffer_info->page_offset, |
| 773 | upper_len); |
| 774 | |
| 775 | if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) || |
| 776 | (page_count(rx_buffer_info->page) != 1)) |
| 777 | rx_buffer_info->page = NULL; |
| 778 | else |
| 779 | get_page(rx_buffer_info->page); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 780 | |
| 781 | skb->len += upper_len; |
| 782 | skb->data_len += upper_len; |
| 783 | skb->truesize += upper_len; |
| 784 | } |
| 785 | |
| 786 | i++; |
| 787 | if (i == rx_ring->count) |
| 788 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 789 | |
| 790 | next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 791 | prefetch(next_rxd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 792 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 793 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 794 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 795 | rsc_count = ixgbe_get_rsc_count(rx_desc); |
| 796 | |
| 797 | if (rsc_count) { |
| 798 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> |
| 799 | IXGBE_RXDADV_NEXTP_SHIFT; |
| 800 | next_buffer = &rx_ring->rx_buffer_info[nextp]; |
| 801 | rx_ring->rsc_count += (rsc_count - 1); |
| 802 | } else { |
| 803 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 804 | } |
| 805 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 806 | if (staterr & IXGBE_RXD_STAT_EOP) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 807 | if (skb->prev) |
| 808 | skb = ixgbe_transform_rsc_queue(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 809 | rx_ring->stats.packets++; |
| 810 | rx_ring->stats.bytes += skb->len; |
| 811 | } else { |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 812 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 813 | rx_buffer_info->skb = next_buffer->skb; |
| 814 | rx_buffer_info->dma = next_buffer->dma; |
| 815 | next_buffer->skb = skb; |
| 816 | next_buffer->dma = 0; |
| 817 | } else { |
| 818 | skb->next = next_buffer->skb; |
| 819 | skb->next->prev = skb; |
| 820 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 821 | adapter->non_eop_descs++; |
| 822 | goto next_desc; |
| 823 | } |
| 824 | |
| 825 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { |
| 826 | dev_kfree_skb_irq(skb); |
| 827 | goto next_desc; |
| 828 | } |
| 829 | |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 830 | ixgbe_rx_checksum(adapter, rx_desc, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 831 | |
| 832 | /* probably a little skewed due to removing CRC */ |
| 833 | total_rx_bytes += skb->len; |
| 834 | total_rx_packets++; |
| 835 | |
Jesse Brandeburg | 74ce8dd | 2008-09-11 20:03:23 -0700 | [diff] [blame] | 836 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 837 | #ifdef IXGBE_FCOE |
| 838 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 839 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 840 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
| 841 | if (!ddp_bytes) |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 842 | goto next_desc; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 843 | } |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 844 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 845 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 846 | |
| 847 | next_desc: |
| 848 | rx_desc->wb.upper.status_error = 0; |
| 849 | |
| 850 | /* return some buffers to hardware, one at a time is too slow */ |
| 851 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 852 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 853 | cleaned_count = 0; |
| 854 | } |
| 855 | |
| 856 | /* use prefetched values */ |
| 857 | rx_desc = next_rxd; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 858 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 859 | |
| 860 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 863 | rx_ring->next_to_clean = i; |
| 864 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); |
| 865 | |
| 866 | if (cleaned_count) |
| 867 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 868 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 869 | #ifdef IXGBE_FCOE |
| 870 | /* include DDPed FCoE data */ |
| 871 | if (ddp_bytes > 0) { |
| 872 | unsigned int mss; |
| 873 | |
| 874 | mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) - |
| 875 | sizeof(struct fc_frame_header) - |
| 876 | sizeof(struct fcoe_crc_eof); |
| 877 | if (mss > 512) |
| 878 | mss &= ~511; |
| 879 | total_rx_bytes += ddp_bytes; |
| 880 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 881 | } |
| 882 | #endif /* IXGBE_FCOE */ |
| 883 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 884 | rx_ring->total_packets += total_rx_packets; |
| 885 | rx_ring->total_bytes += total_rx_bytes; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 886 | netdev->stats.rx_bytes += total_rx_bytes; |
| 887 | netdev->stats.rx_packets += total_rx_packets; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 888 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 889 | return cleaned; |
| 890 | } |
| 891 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 892 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 893 | /** |
| 894 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 895 | * @adapter: board private structure |
| 896 | * |
| 897 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 898 | * interrupts. |
| 899 | **/ |
| 900 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 901 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 902 | struct ixgbe_q_vector *q_vector; |
| 903 | int i, j, q_vectors, v_idx, r_idx; |
| 904 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 905 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 906 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 907 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 908 | /* |
| 909 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 910 | * corresponding register. |
| 911 | */ |
| 912 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 913 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 914 | /* XXX for_each_bit(...) */ |
| 915 | r_idx = find_first_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 916 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 917 | |
| 918 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 919 | j = adapter->rx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 920 | ixgbe_set_ivar(adapter, 0, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 921 | r_idx = find_next_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 922 | adapter->num_rx_queues, |
| 923 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 924 | } |
| 925 | r_idx = find_first_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 926 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 927 | |
| 928 | for (i = 0; i < q_vector->txr_count; i++) { |
| 929 | j = adapter->tx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 930 | ixgbe_set_ivar(adapter, 1, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 931 | r_idx = find_next_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 932 | adapter->num_tx_queues, |
| 933 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 934 | } |
| 935 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 936 | if (q_vector->txr_count && !q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 937 | /* tx only */ |
| 938 | q_vector->eitr = adapter->tx_eitr_param; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 939 | else if (q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 940 | /* rx or mixed */ |
| 941 | q_vector->eitr = adapter->rx_eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 942 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 943 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 944 | } |
| 945 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 946 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 947 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
| 948 | v_idx); |
| 949 | else if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 950 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 951 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 952 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 953 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 954 | mask = IXGBE_EIMS_ENABLE_MASK; |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 955 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 956 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 957 | } |
| 958 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 959 | enum latency_range { |
| 960 | lowest_latency = 0, |
| 961 | low_latency = 1, |
| 962 | bulk_latency = 2, |
| 963 | latency_invalid = 255 |
| 964 | }; |
| 965 | |
| 966 | /** |
| 967 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
| 968 | * @adapter: pointer to adapter |
| 969 | * @eitr: eitr setting (ints per sec) to give last timeslice |
| 970 | * @itr_setting: current throttle rate in ints/second |
| 971 | * @packets: the number of packets during this measurement interval |
| 972 | * @bytes: the number of bytes during this measurement interval |
| 973 | * |
| 974 | * Stores a new ITR value based on packets and byte |
| 975 | * counts during the last interrupt. The advantage of per interrupt |
| 976 | * computation is faster updates and more accurate ITR for the current |
| 977 | * traffic pattern. Constants in this function were computed |
| 978 | * based on theoretical maximum wire speed and thresholds were set based |
| 979 | * on testing data as well as attempting to minimize response time |
| 980 | * while increasing bulk throughput. |
| 981 | * this functionality is controlled by the InterruptThrottleRate module |
| 982 | * parameter (see ixgbe_param.c) |
| 983 | **/ |
| 984 | static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 985 | u32 eitr, u8 itr_setting, |
| 986 | int packets, int bytes) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 987 | { |
| 988 | unsigned int retval = itr_setting; |
| 989 | u32 timepassed_us; |
| 990 | u64 bytes_perint; |
| 991 | |
| 992 | if (packets == 0) |
| 993 | goto update_itr_done; |
| 994 | |
| 995 | |
| 996 | /* simple throttlerate management |
| 997 | * 0-20MB/s lowest (100000 ints/s) |
| 998 | * 20-100MB/s low (20000 ints/s) |
| 999 | * 100-1249MB/s bulk (8000 ints/s) |
| 1000 | */ |
| 1001 | /* what was last interrupt timeslice? */ |
| 1002 | timepassed_us = 1000000/eitr; |
| 1003 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1004 | |
| 1005 | switch (itr_setting) { |
| 1006 | case lowest_latency: |
| 1007 | if (bytes_perint > adapter->eitr_low) |
| 1008 | retval = low_latency; |
| 1009 | break; |
| 1010 | case low_latency: |
| 1011 | if (bytes_perint > adapter->eitr_high) |
| 1012 | retval = bulk_latency; |
| 1013 | else if (bytes_perint <= adapter->eitr_low) |
| 1014 | retval = lowest_latency; |
| 1015 | break; |
| 1016 | case bulk_latency: |
| 1017 | if (bytes_perint <= adapter->eitr_high) |
| 1018 | retval = low_latency; |
| 1019 | break; |
| 1020 | } |
| 1021 | |
| 1022 | update_itr_done: |
| 1023 | return retval; |
| 1024 | } |
| 1025 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1026 | /** |
| 1027 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1028 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1029 | * |
| 1030 | * This function is made to be called by ethtool and by the driver |
| 1031 | * when it needs to update EITR registers at runtime. Hardware |
| 1032 | * specific quirks/differences are taken care of here. |
| 1033 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1034 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1035 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1036 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1037 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1038 | int v_idx = q_vector->v_idx; |
| 1039 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); |
| 1040 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1041 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1042 | /* must write high and low 16 bits to reset counter */ |
| 1043 | itr_reg |= (itr_reg << 16); |
| 1044 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 1045 | /* |
| 1046 | * set the WDIS bit to not clear the timer bits and cause an |
| 1047 | * immediate assertion of the interrupt |
| 1048 | */ |
| 1049 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
| 1050 | } |
| 1051 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1052 | } |
| 1053 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1054 | static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector) |
| 1055 | { |
| 1056 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1057 | u32 new_itr; |
| 1058 | u8 current_itr, ret_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1059 | int i, r_idx; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1060 | struct ixgbe_ring *rx_ring, *tx_ring; |
| 1061 | |
| 1062 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1063 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1064 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1065 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1066 | q_vector->tx_itr, |
| 1067 | tx_ring->total_packets, |
| 1068 | tx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1069 | /* if the result for this queue would decrease interrupt |
| 1070 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1071 | q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1072 | q_vector->tx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1073 | 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] | 1074 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1078 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1079 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1080 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1081 | q_vector->rx_itr, |
| 1082 | rx_ring->total_packets, |
| 1083 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1084 | /* if the result for this queue would decrease interrupt |
| 1085 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1086 | q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1087 | q_vector->rx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1088 | 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] | 1089 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1092 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1093 | |
| 1094 | switch (current_itr) { |
| 1095 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1096 | case lowest_latency: |
| 1097 | new_itr = 100000; |
| 1098 | break; |
| 1099 | case low_latency: |
| 1100 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1101 | break; |
| 1102 | case bulk_latency: |
| 1103 | default: |
| 1104 | new_itr = 8000; |
| 1105 | break; |
| 1106 | } |
| 1107 | |
| 1108 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1109 | /* do an exponential smoothing */ |
| 1110 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1111 | |
| 1112 | /* save the algorithm value here, not the smoothed one */ |
| 1113 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1114 | |
| 1115 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | return; |
| 1119 | } |
| 1120 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1121 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 1122 | { |
| 1123 | struct ixgbe_hw *hw = &adapter->hw; |
| 1124 | |
| 1125 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 1126 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
| 1127 | DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n"); |
| 1128 | /* write to clear the interrupt */ |
| 1129 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1130 | } |
| 1131 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1132 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1133 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 1134 | { |
| 1135 | struct ixgbe_hw *hw = &adapter->hw; |
| 1136 | |
| 1137 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 1138 | /* Clear the interrupt */ |
| 1139 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1140 | schedule_work(&adapter->multispeed_fiber_task); |
| 1141 | } else if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 1142 | /* Clear the interrupt */ |
| 1143 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
| 1144 | schedule_work(&adapter->sfp_config_module_task); |
| 1145 | } else { |
| 1146 | /* Interrupt isn't for us... */ |
| 1147 | return; |
| 1148 | } |
| 1149 | } |
| 1150 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1151 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 1152 | { |
| 1153 | struct ixgbe_hw *hw = &adapter->hw; |
| 1154 | |
| 1155 | adapter->lsc_int++; |
| 1156 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 1157 | adapter->link_check_timeout = jiffies; |
| 1158 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1159 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
| 1160 | schedule_work(&adapter->watchdog_task); |
| 1161 | } |
| 1162 | } |
| 1163 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1164 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 1165 | { |
| 1166 | struct net_device *netdev = data; |
| 1167 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1168 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1169 | u32 eicr; |
| 1170 | |
| 1171 | /* |
| 1172 | * Workaround for Silicon errata. Use clear-by-write instead |
| 1173 | * of clear-by-read. Reading with EICS will return the |
| 1174 | * interrupt causes without clearing, which later be done |
| 1175 | * with the write to EICR. |
| 1176 | */ |
| 1177 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 1178 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1179 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1180 | if (eicr & IXGBE_EICR_LSC) |
| 1181 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1182 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1183 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 1184 | ixgbe_check_fan_failure(adapter, eicr); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1185 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1186 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1187 | ixgbe_check_sfp_event(adapter, eicr); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1188 | |
| 1189 | /* Handle Flow Director Full threshold interrupt */ |
| 1190 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 1191 | int i; |
| 1192 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR); |
| 1193 | /* Disable transmits before FDIR Re-initialization */ |
| 1194 | netif_tx_stop_all_queues(netdev); |
| 1195 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1196 | struct ixgbe_ring *tx_ring = |
| 1197 | &adapter->tx_ring[i]; |
| 1198 | if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE, |
| 1199 | &tx_ring->reinit_state)) |
| 1200 | schedule_work(&adapter->fdir_reinit_task); |
| 1201 | } |
| 1202 | } |
| 1203 | } |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1204 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1205 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1206 | |
| 1207 | return IRQ_HANDLED; |
| 1208 | } |
| 1209 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1210 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 1211 | u64 qmask) |
| 1212 | { |
| 1213 | u32 mask; |
| 1214 | |
| 1215 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1216 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1217 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 1218 | } else { |
| 1219 | mask = (qmask & 0xFFFFFFFF); |
| 1220 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask); |
| 1221 | mask = (qmask >> 32); |
| 1222 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask); |
| 1223 | } |
| 1224 | /* skip the flush */ |
| 1225 | } |
| 1226 | |
| 1227 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
| 1228 | u64 qmask) |
| 1229 | { |
| 1230 | u32 mask; |
| 1231 | |
| 1232 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1233 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1234 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask); |
| 1235 | } else { |
| 1236 | mask = (qmask & 0xFFFFFFFF); |
| 1237 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask); |
| 1238 | mask = (qmask >> 32); |
| 1239 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask); |
| 1240 | } |
| 1241 | /* skip the flush */ |
| 1242 | } |
| 1243 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1244 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 1245 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1246 | struct ixgbe_q_vector *q_vector = data; |
| 1247 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1248 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1249 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1250 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1251 | if (!q_vector->txr_count) |
| 1252 | return IRQ_HANDLED; |
| 1253 | |
| 1254 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1255 | for (i = 0; i < q_vector->txr_count; i++) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1256 | tx_ring = &(adapter->tx_ring[r_idx]); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1257 | tx_ring->total_bytes = 0; |
| 1258 | tx_ring->total_packets = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1259 | 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] | 1260 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1261 | } |
| 1262 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1263 | /* disable interrupts on this vector only */ |
| 1264 | ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1265 | napi_schedule(&q_vector->napi); |
| 1266 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1267 | return IRQ_HANDLED; |
| 1268 | } |
| 1269 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1270 | /** |
| 1271 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 1272 | * @irq: unused |
| 1273 | * @data: pointer to our q_vector struct for this interrupt vector |
| 1274 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1275 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 1276 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1277 | struct ixgbe_q_vector *q_vector = data; |
| 1278 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1279 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1280 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1281 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1282 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1283 | 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] | 1284 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1285 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1286 | rx_ring->total_bytes = 0; |
| 1287 | rx_ring->total_packets = 0; |
| 1288 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1289 | r_idx + 1); |
| 1290 | } |
| 1291 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1292 | if (!q_vector->rxr_count) |
| 1293 | return IRQ_HANDLED; |
| 1294 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1295 | 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] | 1296 | rx_ring = &(adapter->rx_ring[r_idx]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1297 | /* disable interrupts on this vector only */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1298 | ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1299 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1300 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1301 | return IRQ_HANDLED; |
| 1302 | } |
| 1303 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1304 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 1305 | { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1306 | struct ixgbe_q_vector *q_vector = data; |
| 1307 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1308 | struct ixgbe_ring *ring; |
| 1309 | int r_idx; |
| 1310 | int i; |
| 1311 | |
| 1312 | if (!q_vector->txr_count && !q_vector->rxr_count) |
| 1313 | return IRQ_HANDLED; |
| 1314 | |
| 1315 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1316 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1317 | ring = &(adapter->tx_ring[r_idx]); |
| 1318 | ring->total_bytes = 0; |
| 1319 | ring->total_packets = 0; |
| 1320 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1321 | r_idx + 1); |
| 1322 | } |
| 1323 | |
| 1324 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1325 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1326 | ring = &(adapter->rx_ring[r_idx]); |
| 1327 | ring->total_bytes = 0; |
| 1328 | ring->total_packets = 0; |
| 1329 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1330 | r_idx + 1); |
| 1331 | } |
| 1332 | |
| 1333 | /* disable interrupts on this vector only */ |
| 1334 | ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1335 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1336 | |
| 1337 | return IRQ_HANDLED; |
| 1338 | } |
| 1339 | |
| 1340 | /** |
| 1341 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 1342 | * @napi: napi struct with our devices info in it |
| 1343 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1344 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1345 | * This function is optimized for cleaning one queue only on a single |
| 1346 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1347 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1348 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 1349 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1350 | struct ixgbe_q_vector *q_vector = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1351 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1352 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1353 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1354 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1355 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1356 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1357 | 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] | 1358 | rx_ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1359 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1360 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1361 | ixgbe_update_rx_dca(adapter, rx_ring); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1362 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1363 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1364 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1365 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1366 | /* If all Rx work done, exit the polling mode */ |
| 1367 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1368 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1369 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1370 | ixgbe_set_itr_msix(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1371 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1372 | ixgbe_irq_enable_queues(adapter, |
| 1373 | ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | return work_done; |
| 1377 | } |
| 1378 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1379 | /** |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1380 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1381 | * @napi: napi struct with our devices info in it |
| 1382 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1383 | * |
| 1384 | * This function will clean more than one rx queue associated with a |
| 1385 | * q_vector. |
| 1386 | **/ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1387 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1388 | { |
| 1389 | struct ixgbe_q_vector *q_vector = |
| 1390 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1391 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1392 | struct ixgbe_ring *ring = NULL; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1393 | int work_done = 0, i; |
| 1394 | long r_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1395 | bool tx_clean_complete = true; |
| 1396 | |
| 1397 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1398 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1399 | 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, ring); |
| 1403 | #endif |
| 1404 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); |
| 1405 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1406 | r_idx + 1); |
| 1407 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1408 | |
| 1409 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 1410 | * the budget to go below 1 because we'll exit polling */ |
| 1411 | budget /= (q_vector->rxr_count ?: 1); |
| 1412 | budget = max(budget, 1); |
| 1413 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1414 | for (i = 0; i < q_vector->rxr_count; i++) { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1415 | ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1416 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1417 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1418 | ixgbe_update_rx_dca(adapter, ring); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1419 | #endif |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1420 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1421 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1422 | r_idx + 1); |
| 1423 | } |
| 1424 | |
| 1425 | 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] | 1426 | ring = &(adapter->rx_ring[r_idx]); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1427 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 1428 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1429 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1430 | if (adapter->rx_itr_setting & 1) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1431 | ixgbe_set_itr_msix(q_vector); |
| 1432 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1433 | ixgbe_irq_enable_queues(adapter, |
| 1434 | ((u64)1 << q_vector->v_idx)); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1435 | return 0; |
| 1436 | } |
| 1437 | |
| 1438 | return work_done; |
| 1439 | } |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1440 | |
| 1441 | /** |
| 1442 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine |
| 1443 | * @napi: napi struct with our devices info in it |
| 1444 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1445 | * |
| 1446 | * This function is optimized for cleaning one queue only on a single |
| 1447 | * q_vector!!! |
| 1448 | **/ |
| 1449 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) |
| 1450 | { |
| 1451 | struct ixgbe_q_vector *q_vector = |
| 1452 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1453 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1454 | struct ixgbe_ring *tx_ring = NULL; |
| 1455 | int work_done = 0; |
| 1456 | long r_idx; |
| 1457 | |
| 1458 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1459 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1460 | #ifdef CONFIG_IXGBE_DCA |
| 1461 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1462 | ixgbe_update_tx_dca(adapter, tx_ring); |
| 1463 | #endif |
| 1464 | |
| 1465 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) |
| 1466 | work_done = budget; |
| 1467 | |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1468 | /* If all Tx work done, exit the polling mode */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1469 | if (work_done < budget) { |
| 1470 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1471 | if (adapter->tx_itr_setting & 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1472 | ixgbe_set_itr_msix(q_vector); |
| 1473 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1474 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1475 | } |
| 1476 | |
| 1477 | return work_done; |
| 1478 | } |
| 1479 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1480 | 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] | 1481 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1482 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1483 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1484 | |
| 1485 | set_bit(r_idx, q_vector->rxr_idx); |
| 1486 | q_vector->rxr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1487 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1488 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1489 | 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] | 1490 | int t_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1491 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1492 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1493 | |
| 1494 | set_bit(t_idx, q_vector->txr_idx); |
| 1495 | q_vector->txr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1496 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1497 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1498 | /** |
| 1499 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 1500 | * @adapter: board private structure to initialize |
| 1501 | * @vectors: allotted vector count for descriptor rings |
| 1502 | * |
| 1503 | * This function maps descriptor rings to the queue-specific vectors |
| 1504 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 1505 | * one vector per ring/queue, but on a constrained vector budget, we |
| 1506 | * group the rings as "efficiently" as possible. You would add new |
| 1507 | * mapping configurations in here. |
| 1508 | **/ |
| 1509 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1510 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1511 | { |
| 1512 | int v_start = 0; |
| 1513 | int rxr_idx = 0, txr_idx = 0; |
| 1514 | int rxr_remaining = adapter->num_rx_queues; |
| 1515 | int txr_remaining = adapter->num_tx_queues; |
| 1516 | int i, j; |
| 1517 | int rqpv, tqpv; |
| 1518 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1519 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1520 | /* No mapping required if MSI-X is disabled. */ |
| 1521 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1522 | goto out; |
| 1523 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1524 | /* |
| 1525 | * The ideal configuration... |
| 1526 | * We have enough vectors to map one per queue. |
| 1527 | */ |
| 1528 | if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
| 1529 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 1530 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 1531 | |
| 1532 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 1533 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 1534 | |
| 1535 | goto out; |
| 1536 | } |
| 1537 | |
| 1538 | /* |
| 1539 | * If we don't have enough vectors for a 1-to-1 |
| 1540 | * mapping, we'll have to group them so there are |
| 1541 | * multiple queues per vector. |
| 1542 | */ |
| 1543 | /* Re-adjusting *qpv takes care of the remainder. */ |
| 1544 | for (i = v_start; i < vectors; i++) { |
| 1545 | rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i); |
| 1546 | for (j = 0; j < rqpv; j++) { |
| 1547 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 1548 | rxr_idx++; |
| 1549 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1550 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1551 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1552 | for (i = v_start; i < vectors; i++) { |
| 1553 | tqpv = DIV_ROUND_UP(txr_remaining, vectors - i); |
| 1554 | for (j = 0; j < tqpv; j++) { |
| 1555 | map_vector_to_txq(adapter, i, txr_idx); |
| 1556 | txr_idx++; |
| 1557 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1558 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1559 | } |
| 1560 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1561 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1562 | return err; |
| 1563 | } |
| 1564 | |
| 1565 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1566 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 1567 | * @adapter: board private structure |
| 1568 | * |
| 1569 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 1570 | * interrupts from the kernel. |
| 1571 | **/ |
| 1572 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 1573 | { |
| 1574 | struct net_device *netdev = adapter->netdev; |
| 1575 | irqreturn_t (*handler)(int, void *); |
| 1576 | int i, vector, q_vectors, err; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1577 | int ri=0, ti=0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1578 | |
| 1579 | /* Decrement for Other and TCP Timer vectors */ |
| 1580 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1581 | |
| 1582 | /* Map the Tx/Rx rings to the vectors we were allotted. */ |
| 1583 | err = ixgbe_map_rings_to_vectors(adapter, q_vectors); |
| 1584 | if (err) |
| 1585 | goto out; |
| 1586 | |
| 1587 | #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1588 | (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \ |
| 1589 | &ixgbe_msix_clean_many) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1590 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1591 | handler = SET_HANDLER(adapter->q_vector[vector]); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1592 | |
| 1593 | if(handler == &ixgbe_msix_clean_rx) { |
| 1594 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1595 | netdev->name, "rx", ri++); |
| 1596 | } |
| 1597 | else if(handler == &ixgbe_msix_clean_tx) { |
| 1598 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1599 | netdev->name, "tx", ti++); |
| 1600 | } |
| 1601 | else |
| 1602 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1603 | netdev->name, "TxRx", vector); |
| 1604 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1605 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1606 | handler, 0, adapter->name[vector], |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1607 | adapter->q_vector[vector]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1608 | if (err) { |
| 1609 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1610 | "request_irq failed for MSIX interrupt " |
| 1611 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1612 | goto free_queue_irqs; |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | sprintf(adapter->name[vector], "%s:lsc", netdev->name); |
| 1617 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1618 | &ixgbe_msix_lsc, 0, adapter->name[vector], netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1619 | if (err) { |
| 1620 | DPRINTK(PROBE, ERR, |
| 1621 | "request_irq for msix_lsc failed: %d\n", err); |
| 1622 | goto free_queue_irqs; |
| 1623 | } |
| 1624 | |
| 1625 | return 0; |
| 1626 | |
| 1627 | free_queue_irqs: |
| 1628 | for (i = vector - 1; i >= 0; i--) |
| 1629 | free_irq(adapter->msix_entries[--vector].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1630 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1631 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 1632 | pci_disable_msix(adapter->pdev); |
| 1633 | kfree(adapter->msix_entries); |
| 1634 | adapter->msix_entries = NULL; |
| 1635 | out: |
| 1636 | return err; |
| 1637 | } |
| 1638 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1639 | static void ixgbe_set_itr(struct ixgbe_adapter *adapter) |
| 1640 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1641 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1642 | u8 current_itr; |
| 1643 | u32 new_itr = q_vector->eitr; |
| 1644 | struct ixgbe_ring *rx_ring = &adapter->rx_ring[0]; |
| 1645 | struct ixgbe_ring *tx_ring = &adapter->tx_ring[0]; |
| 1646 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1647 | q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1648 | q_vector->tx_itr, |
| 1649 | tx_ring->total_packets, |
| 1650 | tx_ring->total_bytes); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1651 | q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1652 | q_vector->rx_itr, |
| 1653 | rx_ring->total_packets, |
| 1654 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1655 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1656 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1657 | |
| 1658 | switch (current_itr) { |
| 1659 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1660 | case lowest_latency: |
| 1661 | new_itr = 100000; |
| 1662 | break; |
| 1663 | case low_latency: |
| 1664 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1665 | break; |
| 1666 | case bulk_latency: |
| 1667 | new_itr = 8000; |
| 1668 | break; |
| 1669 | default: |
| 1670 | break; |
| 1671 | } |
| 1672 | |
| 1673 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1674 | /* do an exponential smoothing */ |
| 1675 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1676 | |
| 1677 | /* save the algorithm value here, not the smoothed one */ |
| 1678 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1679 | |
| 1680 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | return; |
| 1684 | } |
| 1685 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1686 | /** |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1687 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 1688 | * @adapter: board private structure |
| 1689 | **/ |
| 1690 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter) |
| 1691 | { |
| 1692 | u32 mask; |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1693 | |
| 1694 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 1695 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 1696 | mask |= IXGBE_EIMS_GPI_SDP1; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1697 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 1698 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1699 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 1700 | mask |= IXGBE_EIMS_GPI_SDP2; |
| 1701 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1702 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 1703 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 1704 | mask |= IXGBE_EIMS_FLOW_DIR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1705 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1706 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1707 | ixgbe_irq_enable_queues(adapter, ~0); |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1708 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1709 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1710 | |
| 1711 | /** |
| 1712 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1713 | * @irq: interrupt number |
| 1714 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1715 | **/ |
| 1716 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 1717 | { |
| 1718 | struct net_device *netdev = data; |
| 1719 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1720 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1721 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1722 | u32 eicr; |
| 1723 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1724 | /* |
| 1725 | * Workaround for silicon errata. Mask the interrupts |
| 1726 | * before the read of EICR. |
| 1727 | */ |
| 1728 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 1729 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1730 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 1731 | * therefore no explict interrupt disable is necessary */ |
| 1732 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1733 | if (!eicr) { |
| 1734 | /* shared interrupt alert! |
| 1735 | * make sure interrupts are enabled because the read will |
| 1736 | * have disabled interrupts due to EIAM */ |
| 1737 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1738 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1739 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1740 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1741 | if (eicr & IXGBE_EICR_LSC) |
| 1742 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1743 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1744 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 1745 | ixgbe_check_sfp_event(adapter, eicr); |
| 1746 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1747 | ixgbe_check_fan_failure(adapter, eicr); |
| 1748 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1749 | if (napi_schedule_prep(&(q_vector->napi))) { |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1750 | adapter->tx_ring[0].total_packets = 0; |
| 1751 | adapter->tx_ring[0].total_bytes = 0; |
| 1752 | adapter->rx_ring[0].total_packets = 0; |
| 1753 | adapter->rx_ring[0].total_bytes = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1754 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1755 | __napi_schedule(&(q_vector->napi)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | return IRQ_HANDLED; |
| 1759 | } |
| 1760 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1761 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 1762 | { |
| 1763 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1764 | |
| 1765 | for (i = 0; i < q_vectors; i++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1766 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1767 | bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES); |
| 1768 | bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES); |
| 1769 | q_vector->rxr_count = 0; |
| 1770 | q_vector->txr_count = 0; |
| 1771 | } |
| 1772 | } |
| 1773 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1774 | /** |
| 1775 | * ixgbe_request_irq - initialize interrupts |
| 1776 | * @adapter: board private structure |
| 1777 | * |
| 1778 | * Attempts to configure interrupts using the best available |
| 1779 | * capabilities of the hardware and kernel. |
| 1780 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1781 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1782 | { |
| 1783 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1784 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1785 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1786 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1787 | err = ixgbe_request_msix_irqs(adapter); |
| 1788 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 1789 | err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1790 | netdev->name, netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1791 | } else { |
| 1792 | err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1793 | netdev->name, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1796 | if (err) |
| 1797 | DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err); |
| 1798 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1799 | return err; |
| 1800 | } |
| 1801 | |
| 1802 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 1803 | { |
| 1804 | struct net_device *netdev = adapter->netdev; |
| 1805 | |
| 1806 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1807 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1808 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1809 | q_vectors = adapter->num_msix_vectors; |
| 1810 | |
| 1811 | i = q_vectors - 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1812 | free_irq(adapter->msix_entries[i].vector, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1813 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1814 | i--; |
| 1815 | for (; i >= 0; i--) { |
| 1816 | free_irq(adapter->msix_entries[i].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1817 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | ixgbe_reset_q_vectors(adapter); |
| 1821 | } else { |
| 1822 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1827 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 1828 | * @adapter: board private structure |
| 1829 | **/ |
| 1830 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 1831 | { |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1832 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1833 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
| 1834 | } else { |
| 1835 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 1836 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1837 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1838 | } |
| 1839 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1840 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1841 | int i; |
| 1842 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 1843 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1844 | } else { |
| 1845 | synchronize_irq(adapter->pdev->irq); |
| 1846 | } |
| 1847 | } |
| 1848 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1849 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1850 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 1851 | * |
| 1852 | **/ |
| 1853 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 1854 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1855 | struct ixgbe_hw *hw = &adapter->hw; |
| 1856 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1857 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1858 | EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1859 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1860 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 1861 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1862 | |
| 1863 | map_vector_to_rxq(adapter, 0, 0); |
| 1864 | map_vector_to_txq(adapter, 0, 0); |
| 1865 | |
| 1866 | DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1870 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1871 | * @adapter: board private structure |
| 1872 | * |
| 1873 | * Configure the Tx unit of the MAC after a reset. |
| 1874 | **/ |
| 1875 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 1876 | { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1877 | u64 tdba; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1878 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1879 | u32 i, j, tdlen, txctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1880 | |
| 1881 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1882 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1883 | struct ixgbe_ring *ring = &adapter->tx_ring[i]; |
| 1884 | j = ring->reg_idx; |
| 1885 | tdba = ring->dma; |
| 1886 | tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1887 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j), |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1888 | (tdba & DMA_BIT_MASK(32))); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1889 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32)); |
| 1890 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen); |
| 1891 | IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0); |
| 1892 | IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0); |
| 1893 | adapter->tx_ring[i].head = IXGBE_TDH(j); |
| 1894 | adapter->tx_ring[i].tail = IXGBE_TDT(j); |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1895 | /* |
| 1896 | * Disable Tx Head Writeback RO bit, since this hoses |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1897 | * bookkeeping if things aren't delivered in order. |
| 1898 | */ |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1899 | switch (hw->mac.type) { |
| 1900 | case ixgbe_mac_82598EB: |
| 1901 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j)); |
| 1902 | break; |
| 1903 | case ixgbe_mac_82599EB: |
| 1904 | default: |
| 1905 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j)); |
| 1906 | break; |
| 1907 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1908 | txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1909 | switch (hw->mac.type) { |
| 1910 | case ixgbe_mac_82598EB: |
| 1911 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl); |
| 1912 | break; |
| 1913 | case ixgbe_mac_82599EB: |
| 1914 | default: |
| 1915 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl); |
| 1916 | break; |
| 1917 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1918 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1919 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 1920 | /* We enable 8 traffic classes, DCB only */ |
| 1921 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 1922 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA | |
| 1923 | IXGBE_MTQC_8TC_8TQ)); |
| 1924 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1927 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1928 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 1929 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
| 1930 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1931 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1932 | u32 srrctl; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 1933 | int index; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 1934 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1935 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 1936 | index = rx_ring->reg_idx; |
| 1937 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1938 | unsigned long mask; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 1939 | mask = (unsigned long) feature[RING_F_RSS].mask; |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1940 | index = index & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1941 | } |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1942 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index)); |
| 1943 | |
| 1944 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 1945 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
| 1946 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 1947 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 1948 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 1949 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 1950 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 1951 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
| 1952 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1953 | #else |
| 1954 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1955 | #endif |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1956 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1957 | } else { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 1958 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 1959 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1960 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1961 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1962 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1963 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl); |
| 1964 | } |
| 1965 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 1966 | static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 1967 | { |
| 1968 | u32 mrqc = 0; |
| 1969 | int mask; |
| 1970 | |
| 1971 | if (!(adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 1972 | return mrqc; |
| 1973 | |
| 1974 | mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 1975 | #ifdef CONFIG_IXGBE_DCB |
| 1976 | | IXGBE_FLAG_DCB_ENABLED |
| 1977 | #endif |
| 1978 | ); |
| 1979 | |
| 1980 | switch (mask) { |
| 1981 | case (IXGBE_FLAG_RSS_ENABLED): |
| 1982 | mrqc = IXGBE_MRQC_RSSEN; |
| 1983 | break; |
| 1984 | #ifdef CONFIG_IXGBE_DCB |
| 1985 | case (IXGBE_FLAG_DCB_ENABLED): |
| 1986 | mrqc = IXGBE_MRQC_RT8TCEN; |
| 1987 | break; |
| 1988 | #endif /* CONFIG_IXGBE_DCB */ |
| 1989 | default: |
| 1990 | break; |
| 1991 | } |
| 1992 | |
| 1993 | return mrqc; |
| 1994 | } |
| 1995 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1996 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 1997 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 1998 | * @adapter: address of board private structure |
| 1999 | * @index: index of ring to set |
| 2000 | * @rx_buf_len: rx buffer length |
| 2001 | **/ |
| 2002 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index, |
| 2003 | int rx_buf_len) |
| 2004 | { |
| 2005 | struct ixgbe_ring *rx_ring; |
| 2006 | struct ixgbe_hw *hw = &adapter->hw; |
| 2007 | int j; |
| 2008 | u32 rscctrl; |
| 2009 | |
| 2010 | rx_ring = &adapter->rx_ring[index]; |
| 2011 | j = rx_ring->reg_idx; |
| 2012 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j)); |
| 2013 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2014 | /* |
| 2015 | * we must limit the number of descriptors so that the |
| 2016 | * total size of max desc * buf_len is not greater |
| 2017 | * than 65535 |
| 2018 | */ |
| 2019 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
| 2020 | #if (MAX_SKB_FRAGS > 16) |
| 2021 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2022 | #elif (MAX_SKB_FRAGS > 8) |
| 2023 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2024 | #elif (MAX_SKB_FRAGS > 4) |
| 2025 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2026 | #else |
| 2027 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; |
| 2028 | #endif |
| 2029 | } else { |
| 2030 | if (rx_buf_len < IXGBE_RXBUFFER_4096) |
| 2031 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2032 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) |
| 2033 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2034 | else |
| 2035 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2036 | } |
| 2037 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl); |
| 2038 | } |
| 2039 | |
| 2040 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2041 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2042 | * @adapter: board private structure |
| 2043 | * |
| 2044 | * Configure the Rx unit of the MAC after a reset. |
| 2045 | **/ |
| 2046 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 2047 | { |
| 2048 | u64 rdba; |
| 2049 | struct ixgbe_hw *hw = &adapter->hw; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2050 | struct ixgbe_ring *rx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2051 | struct net_device *netdev = adapter->netdev; |
| 2052 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2053 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2054 | u32 rdlen, rxctrl, rxcsum; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2055 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
| 2056 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2057 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2058 | u32 fctrl, hlreg0; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2059 | u32 reta = 0, mrqc = 0; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2060 | u32 rdrxctl; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2061 | int rx_buf_len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2062 | |
| 2063 | /* Decide whether to use packet split mode or not */ |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2064 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2065 | |
| 2066 | /* Set the RX buffer length according to the mode */ |
| 2067 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2068 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2069 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2070 | /* PSRTYPE must be initialized in 82599 */ |
| 2071 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 2072 | IXGBE_PSRTYPE_UDPHDR | |
| 2073 | IXGBE_PSRTYPE_IPV4HDR | |
Yi Zou | dfa12f0 | 2009-05-07 10:39:35 +0000 | [diff] [blame] | 2074 | IXGBE_PSRTYPE_IPV6HDR | |
| 2075 | IXGBE_PSRTYPE_L2HDR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2076 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype); |
| 2077 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2078 | } else { |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 2079 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2080 | (netdev->mtu <= ETH_DATA_LEN)) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2081 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2082 | else |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2083 | rx_buf_len = ALIGN(max_frame, 1024); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); |
| 2087 | fctrl |= IXGBE_FCTRL_BAM; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2088 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2089 | fctrl |= IXGBE_FCTRL_PMCF; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2090 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl); |
| 2091 | |
| 2092 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
| 2093 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2094 | hlreg0 &= ~IXGBE_HLREG0_JUMBOEN; |
| 2095 | else |
| 2096 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2097 | #ifdef IXGBE_FCOE |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2098 | if (netdev->features & NETIF_F_FCOE_MTU) |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2099 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
| 2100 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2101 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 2102 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2103 | rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc); |
| 2104 | /* disable receives while setting up the descriptors */ |
| 2105 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2106 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 2107 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2108 | /* |
| 2109 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2110 | * the Base and Length of the Rx Descriptor Ring |
| 2111 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2112 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2113 | rx_ring = &adapter->rx_ring[i]; |
| 2114 | rdba = rx_ring->dma; |
| 2115 | j = rx_ring->reg_idx; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2116 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32))); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2117 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32)); |
| 2118 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen); |
| 2119 | IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0); |
| 2120 | IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0); |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2121 | rx_ring->head = IXGBE_RDH(j); |
| 2122 | rx_ring->tail = IXGBE_RDT(j); |
| 2123 | rx_ring->rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2124 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2125 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) |
| 2126 | rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED; |
Peter P Waskiewicz Jr | 1b3ff02 | 2009-09-14 07:47:27 +0000 | [diff] [blame] | 2127 | else |
| 2128 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2129 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2130 | #ifdef IXGBE_FCOE |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2131 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2132 | struct ixgbe_ring_feature *f; |
| 2133 | f = &adapter->ring_feature[RING_F_FCOE]; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2134 | if ((i >= f->mask) && (i < f->mask + f->indices)) { |
| 2135 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; |
| 2136 | if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 2137 | rx_ring->rx_buf_len = |
| 2138 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2139 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | #endif /* IXGBE_FCOE */ |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2143 | ixgbe_configure_srrctl(adapter, rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2146 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2147 | /* |
| 2148 | * For VMDq support of different descriptor types or |
| 2149 | * buffer sizes through the use of multiple SRRCTL |
| 2150 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 2151 | * |
| 2152 | * also, the manual doesn't mention it clearly but DCA hints |
| 2153 | * will only use queue 0's tags unless this bit is set. Side |
| 2154 | * effects of setting this bit are only that SRRCTL must be |
| 2155 | * fully programmed [0..15] |
| 2156 | */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2157 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2158 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 2159 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2160 | } |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2161 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2162 | /* Program MRQC for the distribution of queues */ |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2163 | mrqc = ixgbe_setup_mrqc(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2164 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2165 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2166 | /* Fill out redirection table */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2167 | for (i = 0, j = 0; i < 128; i++, j++) { |
| 2168 | if (j == adapter->ring_feature[RING_F_RSS].indices) |
| 2169 | j = 0; |
| 2170 | /* reta = 4-byte sliding window of |
| 2171 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2172 | reta = (reta << 8) | (j * 0x11); |
| 2173 | if ((i & 3) == 3) |
| 2174 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | /* Fill out hash function seeds */ |
| 2178 | for (i = 0; i < 10; i++) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2179 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2180 | |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2181 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2182 | mrqc |= IXGBE_MRQC_RSSEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2183 | /* Perform hash on these packet types */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2184 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2185 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2186 | | IXGBE_MRQC_RSS_FIELD_IPV4_UDP |
| 2187 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2188 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP |
| 2189 | | IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2190 | } |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2191 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2192 | |
| 2193 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2194 | |
| 2195 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED || |
| 2196 | adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) { |
| 2197 | /* Disable indicating checksum in descriptor, enables |
| 2198 | * RSS hash */ |
| 2199 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2200 | } |
| 2201 | if (!(rxcsum & IXGBE_RXCSUM_PCSD)) { |
| 2202 | /* Enable IPv4 payload checksum for UDP fragments |
| 2203 | * if PCSD is not set */ |
| 2204 | rxcsum |= IXGBE_RXCSUM_IPPCSE; |
| 2205 | } |
| 2206 | |
| 2207 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2208 | |
| 2209 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2210 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2211 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2212 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2213 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 2214 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2215 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 2216 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2217 | /* Enable 82599 HW-RSC */ |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2218 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2219 | ixgbe_configure_rscctl(adapter, i, rx_buf_len); |
| 2220 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2221 | /* Disable RSC for ACK packets */ |
| 2222 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 2223 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 2224 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2227 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 2228 | { |
| 2229 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2230 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2231 | |
| 2232 | /* add VID to filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2233 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 2237 | { |
| 2238 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2239 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2240 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2241 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2242 | ixgbe_irq_disable(adapter); |
| 2243 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2244 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2245 | |
| 2246 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2247 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2248 | |
| 2249 | /* remove VID from filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2250 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2251 | } |
| 2252 | |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2253 | static void ixgbe_vlan_rx_register(struct net_device *netdev, |
| 2254 | struct vlan_group *grp) |
| 2255 | { |
| 2256 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2257 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2258 | int i, j; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2259 | |
| 2260 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2261 | ixgbe_irq_disable(adapter); |
| 2262 | adapter->vlgrp = grp; |
| 2263 | |
| 2264 | /* |
| 2265 | * For a DCB driver, always enable VLAN tag stripping so we can |
| 2266 | * still receive traffic from a DCB-enabled host even if we're |
| 2267 | * not in DCB mode. |
| 2268 | */ |
| 2269 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2270 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 2271 | ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2272 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2273 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2274 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 2275 | ctrl |= IXGBE_VLNCTRL_VFE; |
| 2276 | /* enable VLAN tag insert/strip */ |
| 2277 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
| 2278 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2279 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
| 2280 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2281 | j = adapter->rx_ring[i].reg_idx; |
| 2282 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j)); |
| 2283 | ctrl |= IXGBE_RXDCTL_VME; |
| 2284 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl); |
| 2285 | } |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2286 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2287 | ixgbe_vlan_rx_add_vid(netdev, 0); |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2288 | |
| 2289 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2290 | ixgbe_irq_enable(adapter); |
| 2291 | } |
| 2292 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2293 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 2294 | { |
| 2295 | ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 2296 | |
| 2297 | if (adapter->vlgrp) { |
| 2298 | u16 vid; |
| 2299 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 2300 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 2301 | continue; |
| 2302 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
| 2303 | } |
| 2304 | } |
| 2305 | } |
| 2306 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2307 | static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq) |
| 2308 | { |
| 2309 | struct dev_mc_list *mc_ptr; |
| 2310 | u8 *addr = *mc_addr_ptr; |
| 2311 | *vmdq = 0; |
| 2312 | |
| 2313 | mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]); |
| 2314 | if (mc_ptr->next) |
| 2315 | *mc_addr_ptr = mc_ptr->next->dmi_addr; |
| 2316 | else |
| 2317 | *mc_addr_ptr = NULL; |
| 2318 | |
| 2319 | return addr; |
| 2320 | } |
| 2321 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2322 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2323 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2324 | * @netdev: network interface device structure |
| 2325 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2326 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 2327 | * address list or the network interface flags are updated. This routine is |
| 2328 | * responsible for configuring the hardware for proper unicast, multicast and |
| 2329 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2330 | **/ |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2331 | static void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2332 | { |
| 2333 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2334 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2335 | u32 fctrl, vlnctrl; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2336 | u8 *addr_list = NULL; |
| 2337 | int addr_count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2338 | |
| 2339 | /* Check for Promiscuous and All Multicast modes */ |
| 2340 | |
| 2341 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2342 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2343 | |
| 2344 | if (netdev->flags & IFF_PROMISC) { |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2345 | hw->addr_ctrl.user_set_promisc = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2346 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2347 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2348 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2349 | if (netdev->flags & IFF_ALLMULTI) { |
| 2350 | fctrl |= IXGBE_FCTRL_MPE; |
| 2351 | fctrl &= ~IXGBE_FCTRL_UPE; |
| 2352 | } else { |
| 2353 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 2354 | } |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2355 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2356 | hw->addr_ctrl.user_set_promisc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2360 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2361 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2362 | /* reprogram secondary unicast list */ |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 2363 | hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2364 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2365 | /* reprogram multicast list */ |
| 2366 | addr_count = netdev->mc_count; |
| 2367 | if (addr_count) |
| 2368 | addr_list = netdev->mc_list->dmi_addr; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2369 | hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count, |
| 2370 | ixgbe_addr_list_itr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2373 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 2374 | { |
| 2375 | int q_idx; |
| 2376 | struct ixgbe_q_vector *q_vector; |
| 2377 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2378 | |
| 2379 | /* legacy and MSI only use one vector */ |
| 2380 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2381 | q_vectors = 1; |
| 2382 | |
| 2383 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2384 | struct napi_struct *napi; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2385 | q_vector = adapter->q_vector[q_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2386 | napi = &q_vector->napi; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2387 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2388 | if (!q_vector->rxr_count || !q_vector->txr_count) { |
| 2389 | if (q_vector->txr_count == 1) |
| 2390 | napi->poll = &ixgbe_clean_txonly; |
| 2391 | else if (q_vector->rxr_count == 1) |
| 2392 | napi->poll = &ixgbe_clean_rxonly; |
| 2393 | } |
| 2394 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2395 | |
| 2396 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2397 | } |
| 2398 | } |
| 2399 | |
| 2400 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 2401 | { |
| 2402 | int q_idx; |
| 2403 | struct ixgbe_q_vector *q_vector; |
| 2404 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2405 | |
| 2406 | /* legacy and MSI only use one vector */ |
| 2407 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2408 | q_vectors = 1; |
| 2409 | |
| 2410 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2411 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2412 | napi_disable(&q_vector->napi); |
| 2413 | } |
| 2414 | } |
| 2415 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2416 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2417 | /* |
| 2418 | * ixgbe_configure_dcb - Configure DCB hardware |
| 2419 | * @adapter: ixgbe adapter struct |
| 2420 | * |
| 2421 | * This is called by the driver on open to configure the DCB hardware. |
| 2422 | * This is also called by the gennetlink interface when reconfiguring |
| 2423 | * the DCB state. |
| 2424 | */ |
| 2425 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 2426 | { |
| 2427 | struct ixgbe_hw *hw = &adapter->hw; |
| 2428 | u32 txdctl, vlnctrl; |
| 2429 | int i, j; |
| 2430 | |
| 2431 | ixgbe_dcb_check_config(&adapter->dcb_cfg); |
| 2432 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG); |
| 2433 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG); |
| 2434 | |
| 2435 | /* reconfigure the hardware */ |
| 2436 | ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg); |
| 2437 | |
| 2438 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2439 | j = adapter->tx_ring[i].reg_idx; |
| 2440 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2441 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2442 | txdctl |= 32; |
| 2443 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2444 | } |
| 2445 | /* Enable VLAN tag insert/strip */ |
| 2446 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2447 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2448 | vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
| 2449 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2450 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2451 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2452 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 2453 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2454 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2455 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2456 | j = adapter->rx_ring[i].reg_idx; |
| 2457 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2458 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 2459 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 2460 | } |
| 2461 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2462 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
| 2463 | } |
| 2464 | |
| 2465 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2466 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 2467 | { |
| 2468 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2469 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2470 | int i; |
| 2471 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2472 | ixgbe_set_rx_mode(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2473 | |
| 2474 | ixgbe_restore_vlan(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2475 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2476 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 2477 | netif_set_gso_max_size(netdev, 32768); |
| 2478 | ixgbe_configure_dcb(adapter); |
| 2479 | } else { |
| 2480 | netif_set_gso_max_size(netdev, 65536); |
| 2481 | } |
| 2482 | #else |
| 2483 | netif_set_gso_max_size(netdev, 65536); |
| 2484 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2485 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 2486 | #ifdef IXGBE_FCOE |
| 2487 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 2488 | ixgbe_configure_fcoe(adapter); |
| 2489 | |
| 2490 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2491 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2492 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2493 | adapter->tx_ring[i].atr_sample_rate = |
| 2494 | adapter->atr_sample_rate; |
| 2495 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); |
| 2496 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 2497 | ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc); |
| 2498 | } |
| 2499 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2500 | ixgbe_configure_tx(adapter); |
| 2501 | ixgbe_configure_rx(adapter); |
| 2502 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2503 | ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i], |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2504 | (adapter->rx_ring[i].count - 1)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2505 | } |
| 2506 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2507 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2508 | { |
| 2509 | switch (hw->phy.type) { |
| 2510 | case ixgbe_phy_sfp_avago: |
| 2511 | case ixgbe_phy_sfp_ftl: |
| 2512 | case ixgbe_phy_sfp_intel: |
| 2513 | case ixgbe_phy_sfp_unknown: |
| 2514 | case ixgbe_phy_tw_tyco: |
| 2515 | case ixgbe_phy_tw_unknown: |
| 2516 | return true; |
| 2517 | default: |
| 2518 | return false; |
| 2519 | } |
| 2520 | } |
| 2521 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2522 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2523 | * ixgbe_sfp_link_config - set up SFP+ link |
| 2524 | * @adapter: pointer to private adapter struct |
| 2525 | **/ |
| 2526 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 2527 | { |
| 2528 | struct ixgbe_hw *hw = &adapter->hw; |
| 2529 | |
| 2530 | if (hw->phy.multispeed_fiber) { |
| 2531 | /* |
| 2532 | * In multispeed fiber setups, the device may not have |
| 2533 | * had a physical connection when the driver loaded. |
| 2534 | * If that's the case, the initial link configuration |
| 2535 | * couldn't get the MAC into 10G or 1G mode, so we'll |
| 2536 | * never have a link status change interrupt fire. |
| 2537 | * We need to try and force an autonegotiation |
| 2538 | * session, then bring up link. |
| 2539 | */ |
| 2540 | hw->mac.ops.setup_sfp(hw); |
| 2541 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
| 2542 | schedule_work(&adapter->multispeed_fiber_task); |
| 2543 | } else { |
| 2544 | /* |
| 2545 | * Direct Attach Cu and non-multispeed fiber modules |
| 2546 | * still need to be configured properly prior to |
| 2547 | * attempting link. |
| 2548 | */ |
| 2549 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK)) |
| 2550 | schedule_work(&adapter->sfp_config_module_task); |
| 2551 | } |
| 2552 | } |
| 2553 | |
| 2554 | /** |
| 2555 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2556 | * @hw: pointer to private hardware struct |
| 2557 | * |
| 2558 | * Returns 0 on success, negative on failure |
| 2559 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2560 | 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] | 2561 | { |
| 2562 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2563 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2564 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 2565 | |
| 2566 | if (hw->mac.ops.check_link) |
| 2567 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2568 | |
| 2569 | if (ret) |
| 2570 | goto link_cfg_out; |
| 2571 | |
| 2572 | if (hw->mac.ops.get_link_capabilities) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2573 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2574 | if (ret) |
| 2575 | goto link_cfg_out; |
| 2576 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2577 | if (hw->mac.ops.setup_link) |
| 2578 | ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2579 | link_cfg_out: |
| 2580 | return ret; |
| 2581 | } |
| 2582 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2583 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2584 | static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2585 | int rxr) |
| 2586 | { |
| 2587 | int j = adapter->rx_ring[rxr].reg_idx; |
| 2588 | int k; |
| 2589 | |
| 2590 | for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) { |
| 2591 | if (IXGBE_READ_REG(&adapter->hw, |
| 2592 | IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE) |
| 2593 | break; |
| 2594 | else |
| 2595 | msleep(1); |
| 2596 | } |
| 2597 | if (k >= IXGBE_MAX_RX_DESC_POLL) { |
| 2598 | DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d " |
| 2599 | "not set within the polling period\n", rxr); |
| 2600 | } |
| 2601 | ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr], |
| 2602 | (adapter->rx_ring[rxr].count - 1)); |
| 2603 | } |
| 2604 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2605 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 2606 | { |
| 2607 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2608 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2609 | int i, j = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2610 | int num_rx_rings = adapter->num_rx_queues; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2611 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2612 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2613 | u32 txdctl, rxdctl, mhadd; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2614 | u32 dmatxctl; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2615 | u32 gpie; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2616 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 2617 | ixgbe_get_hw_control(adapter); |
| 2618 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2619 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) || |
| 2620 | (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2621 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2622 | gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2623 | IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2624 | } else { |
| 2625 | /* MSI only */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2626 | gpie = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2627 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2628 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 2629 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 2630 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2631 | } |
| 2632 | |
| 2633 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 2634 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 2635 | * specifically only auto mask tx and rx interrupts */ |
| 2636 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2637 | } |
| 2638 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2639 | /* Enable fan failure interrupt if media type is copper */ |
| 2640 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2641 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2642 | gpie |= IXGBE_SDP1_GPIEN; |
| 2643 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2644 | } |
| 2645 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2646 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2647 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2648 | gpie |= IXGBE_SDP1_GPIEN; |
| 2649 | gpie |= IXGBE_SDP2_GPIEN; |
| 2650 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2651 | } |
| 2652 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2653 | #ifdef IXGBE_FCOE |
| 2654 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2655 | if ((netdev->features & NETIF_F_FCOE_MTU) && |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2656 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 2657 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2658 | |
| 2659 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2660 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2661 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 2662 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 2663 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 2664 | |
| 2665 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
| 2666 | } |
| 2667 | |
| 2668 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2669 | j = adapter->tx_ring[i].reg_idx; |
| 2670 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2671 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2672 | txdctl |= (8 << 16); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2673 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2674 | } |
| 2675 | |
| 2676 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2677 | /* DMATXCTL.EN must be set after all Tx queue config is done */ |
| 2678 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2679 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2680 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2681 | } |
| 2682 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2683 | j = adapter->tx_ring[i].reg_idx; |
| 2684 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2685 | txdctl |= IXGBE_TXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2686 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2687 | } |
| 2688 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2689 | for (i = 0; i < num_rx_rings; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2690 | j = adapter->rx_ring[i].reg_idx; |
| 2691 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2692 | /* enable PTHRESH=32 descriptors (half the internal cache) |
| 2693 | * and HTHRESH=0 descriptors (to minimize latency on fetch), |
| 2694 | * this also removes a pesky rx_no_buffer_count increment */ |
| 2695 | rxdctl |= 0x0020; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2696 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2697 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2698 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 2699 | ixgbe_rx_desc_queue_enable(adapter, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2700 | } |
| 2701 | /* enable all receives */ |
| 2702 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2703 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2704 | rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN); |
| 2705 | else |
| 2706 | rxdctl |= IXGBE_RXCTRL_RXEN; |
| 2707 | hw->mac.ops.enable_rx_dma(hw, rxdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2708 | |
| 2709 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 2710 | ixgbe_configure_msix(adapter); |
| 2711 | else |
| 2712 | ixgbe_configure_msi_and_legacy(adapter); |
| 2713 | |
| 2714 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2715 | ixgbe_napi_enable_all(adapter); |
| 2716 | |
| 2717 | /* clear any pending interrupts, may auto mask */ |
| 2718 | IXGBE_READ_REG(hw, IXGBE_EICR); |
| 2719 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2720 | ixgbe_irq_enable(adapter); |
| 2721 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2722 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 2723 | * If this adapter has a fan, check to see if we had a failure |
| 2724 | * before we enabled the interrupt. |
| 2725 | */ |
| 2726 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2727 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 2728 | if (esdp & IXGBE_ESDP_SDP1) |
| 2729 | DPRINTK(DRV, CRIT, |
| 2730 | "Fan has stopped, replace the adapter\n"); |
| 2731 | } |
| 2732 | |
| 2733 | /* |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2734 | * For hot-pluggable SFP+ devices, a new SFP+ module may have |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2735 | * arrived before interrupts were enabled but after probe. Such |
| 2736 | * devices wouldn't have their type identified yet. We need to |
| 2737 | * kick off the SFP+ module setup first, then try to bring up link. |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2738 | * If we're not hot-pluggable SFP+, we just need to configure link |
| 2739 | * and bring it up. |
| 2740 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2741 | if (hw->phy.type == ixgbe_phy_unknown) { |
| 2742 | err = hw->phy.ops.identify(hw); |
| 2743 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2744 | /* |
| 2745 | * Take the device down and schedule the sfp tasklet |
| 2746 | * which will unregister_netdev and log it. |
| 2747 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2748 | ixgbe_down(adapter); |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2749 | schedule_work(&adapter->sfp_config_module_task); |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2750 | return err; |
| 2751 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | if (ixgbe_is_sfp(hw)) { |
| 2755 | ixgbe_sfp_link_config(adapter); |
| 2756 | } else { |
| 2757 | err = ixgbe_non_sfp_link_config(hw); |
| 2758 | if (err) |
| 2759 | DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err); |
| 2760 | } |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2761 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2762 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2763 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 2764 | &(adapter->tx_ring[i].reinit_state)); |
| 2765 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 2766 | /* enable transmits */ |
| 2767 | netif_tx_start_all_queues(netdev); |
| 2768 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2769 | /* bring the link up in the watchdog, this could race with our first |
| 2770 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2771 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2772 | adapter->link_check_timeout = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2773 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 2774 | return 0; |
| 2775 | } |
| 2776 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2777 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 2778 | { |
| 2779 | WARN_ON(in_interrupt()); |
| 2780 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
| 2781 | msleep(1); |
| 2782 | ixgbe_down(adapter); |
| 2783 | ixgbe_up(adapter); |
| 2784 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 2785 | } |
| 2786 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2787 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 2788 | { |
| 2789 | /* hardware has been reset, we need to reload some things */ |
| 2790 | ixgbe_configure(adapter); |
| 2791 | |
| 2792 | return ixgbe_up_complete(adapter); |
| 2793 | } |
| 2794 | |
| 2795 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 2796 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2797 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 2798 | int err; |
| 2799 | |
| 2800 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2801 | switch (err) { |
| 2802 | case 0: |
| 2803 | case IXGBE_ERR_SFP_NOT_PRESENT: |
| 2804 | break; |
| 2805 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
| 2806 | dev_err(&adapter->pdev->dev, "master disable timed out\n"); |
| 2807 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 2808 | case IXGBE_ERR_EEPROM_VERSION: |
| 2809 | /* We are running on a pre-production device, log a warning */ |
| 2810 | dev_warn(&adapter->pdev->dev, "This device is a pre-production " |
| 2811 | "adapter/LOM. Please be aware there may be issues " |
| 2812 | "associated with your hardware. If you are " |
| 2813 | "experiencing problems please contact your Intel or " |
| 2814 | "hardware representative who provided you with this " |
| 2815 | "hardware.\n"); |
| 2816 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2817 | default: |
| 2818 | dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err); |
| 2819 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2820 | |
| 2821 | /* reprogram the RAR[0] in case user changed it. */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2822 | 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] | 2823 | } |
| 2824 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2825 | /** |
| 2826 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 2827 | * @adapter: board private structure |
| 2828 | * @rx_ring: ring to free buffers from |
| 2829 | **/ |
| 2830 | static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2831 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2832 | { |
| 2833 | struct pci_dev *pdev = adapter->pdev; |
| 2834 | unsigned long size; |
| 2835 | unsigned int i; |
| 2836 | |
| 2837 | /* Free all the Rx ring sk_buffs */ |
| 2838 | |
| 2839 | for (i = 0; i < rx_ring->count; i++) { |
| 2840 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 2841 | |
| 2842 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 2843 | if (rx_buffer_info->dma) { |
| 2844 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2845 | rx_ring->rx_buf_len, |
| 2846 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2847 | rx_buffer_info->dma = 0; |
| 2848 | } |
| 2849 | if (rx_buffer_info->skb) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2850 | struct sk_buff *skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2851 | rx_buffer_info->skb = NULL; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2852 | do { |
| 2853 | struct sk_buff *this = skb; |
| 2854 | skb = skb->prev; |
| 2855 | dev_kfree_skb(this); |
| 2856 | } while (skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2857 | } |
| 2858 | if (!rx_buffer_info->page) |
| 2859 | continue; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 2860 | if (rx_buffer_info->page_dma) { |
| 2861 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
| 2862 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
| 2863 | rx_buffer_info->page_dma = 0; |
| 2864 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2865 | put_page(rx_buffer_info->page); |
| 2866 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2867 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 2871 | memset(rx_ring->rx_buffer_info, 0, size); |
| 2872 | |
| 2873 | /* Zero out the descriptor ring */ |
| 2874 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2875 | |
| 2876 | rx_ring->next_to_clean = 0; |
| 2877 | rx_ring->next_to_use = 0; |
| 2878 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 2879 | if (rx_ring->head) |
| 2880 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 2881 | if (rx_ring->tail) |
| 2882 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | /** |
| 2886 | * ixgbe_clean_tx_ring - Free Tx Buffers |
| 2887 | * @adapter: board private structure |
| 2888 | * @tx_ring: ring to be cleaned |
| 2889 | **/ |
| 2890 | static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2891 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2892 | { |
| 2893 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 2894 | unsigned long size; |
| 2895 | unsigned int i; |
| 2896 | |
| 2897 | /* Free all the Tx ring sk_buffs */ |
| 2898 | |
| 2899 | for (i = 0; i < tx_ring->count; i++) { |
| 2900 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 2901 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 2902 | } |
| 2903 | |
| 2904 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 2905 | memset(tx_ring->tx_buffer_info, 0, size); |
| 2906 | |
| 2907 | /* Zero out the descriptor ring */ |
| 2908 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2909 | |
| 2910 | tx_ring->next_to_use = 0; |
| 2911 | tx_ring->next_to_clean = 0; |
| 2912 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 2913 | if (tx_ring->head) |
| 2914 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 2915 | if (tx_ring->tail) |
| 2916 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2920 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2921 | * @adapter: board private structure |
| 2922 | **/ |
| 2923 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 2924 | { |
| 2925 | int i; |
| 2926 | |
| 2927 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2928 | ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
| 2929 | } |
| 2930 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2931 | /** |
| 2932 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2933 | * @adapter: board private structure |
| 2934 | **/ |
| 2935 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 2936 | { |
| 2937 | int i; |
| 2938 | |
| 2939 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2940 | ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
| 2941 | } |
| 2942 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2943 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 2944 | { |
| 2945 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2946 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2947 | u32 rxctrl; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2948 | u32 txdctl; |
| 2949 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2950 | |
| 2951 | /* signal that we are down to the interrupt handler */ |
| 2952 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 2953 | |
| 2954 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2955 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2956 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2957 | |
| 2958 | netif_tx_disable(netdev); |
| 2959 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2960 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2961 | msleep(10); |
| 2962 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2963 | netif_tx_stop_all_queues(netdev); |
| 2964 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2965 | ixgbe_irq_disable(adapter); |
| 2966 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2967 | ixgbe_napi_disable_all(adapter); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2968 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 2969 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 2970 | del_timer_sync(&adapter->sfp_timer); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2971 | del_timer_sync(&adapter->watchdog_timer); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2972 | cancel_work_sync(&adapter->watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2973 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2974 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 2975 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 2976 | cancel_work_sync(&adapter->fdir_reinit_task); |
| 2977 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2978 | /* disable transmits in the hardware now that interrupts are off */ |
| 2979 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2980 | j = adapter->tx_ring[i].reg_idx; |
| 2981 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2982 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), |
| 2983 | (txdctl & ~IXGBE_TXDCTL_ENABLE)); |
| 2984 | } |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 2985 | /* Disable the Tx DMA engine on 82599 */ |
| 2986 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 2987 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
| 2988 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 2989 | ~IXGBE_DMATXCTL_TE)); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2990 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2991 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2992 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 2993 | if (!pci_channel_offline(adapter->pdev)) |
| 2994 | ixgbe_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2995 | ixgbe_clean_all_tx_rings(adapter); |
| 2996 | ixgbe_clean_all_rx_rings(adapter); |
| 2997 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2998 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 2999 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 3000 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 3001 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3002 | } |
| 3003 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3004 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3005 | * ixgbe_poll - NAPI Rx polling callback |
| 3006 | * @napi: structure for representing this polling device |
| 3007 | * @budget: how many packets driver is allowed to clean |
| 3008 | * |
| 3009 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3010 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3011 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3012 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3013 | struct ixgbe_q_vector *q_vector = |
| 3014 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3015 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3016 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3017 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3018 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 3019 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 3020 | ixgbe_update_tx_dca(adapter, adapter->tx_ring); |
| 3021 | ixgbe_update_rx_dca(adapter, adapter->rx_ring); |
| 3022 | } |
| 3023 | #endif |
| 3024 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3025 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 3026 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3027 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3028 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3029 | work_done = budget; |
| 3030 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 3031 | /* If budget not fully consumed, exit the polling mode */ |
| 3032 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3033 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 3034 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 3035 | ixgbe_set_itr(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3036 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3037 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3038 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3039 | return work_done; |
| 3040 | } |
| 3041 | |
| 3042 | /** |
| 3043 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 3044 | * @netdev: network interface device structure |
| 3045 | **/ |
| 3046 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 3047 | { |
| 3048 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3049 | |
| 3050 | /* Do the reset outside of interrupt context */ |
| 3051 | schedule_work(&adapter->reset_task); |
| 3052 | } |
| 3053 | |
| 3054 | static void ixgbe_reset_task(struct work_struct *work) |
| 3055 | { |
| 3056 | struct ixgbe_adapter *adapter; |
| 3057 | adapter = container_of(work, struct ixgbe_adapter, reset_task); |
| 3058 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3059 | /* If we're already down or resetting, just bail */ |
| 3060 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 3061 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 3062 | return; |
| 3063 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3064 | adapter->tx_timeout_count++; |
| 3065 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3066 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3067 | } |
| 3068 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3069 | #ifdef CONFIG_IXGBE_DCB |
| 3070 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3071 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3072 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3073 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB]; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3074 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3075 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 3076 | return ret; |
| 3077 | |
| 3078 | f->mask = 0x7 << 3; |
| 3079 | adapter->num_rx_queues = f->indices; |
| 3080 | adapter->num_tx_queues = f->indices; |
| 3081 | ret = true; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3082 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3083 | return ret; |
| 3084 | } |
| 3085 | #endif |
| 3086 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3087 | /** |
| 3088 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 3089 | * @adapter: board private structure to initialize |
| 3090 | * |
| 3091 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 3092 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 3093 | * |
| 3094 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3095 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 3096 | { |
| 3097 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3098 | 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] | 3099 | |
| 3100 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3101 | f->mask = 0xF; |
| 3102 | adapter->num_rx_queues = f->indices; |
| 3103 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3104 | ret = true; |
| 3105 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3106 | ret = false; |
| 3107 | } |
| 3108 | |
| 3109 | return ret; |
| 3110 | } |
| 3111 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3112 | /** |
| 3113 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 3114 | * @adapter: board private structure to initialize |
| 3115 | * |
| 3116 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 3117 | * to the original CPU that initiated the Tx session. This runs in addition |
| 3118 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 3119 | * Rx load across CPUs using RSS. |
| 3120 | * |
| 3121 | **/ |
| 3122 | static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter) |
| 3123 | { |
| 3124 | bool ret = false; |
| 3125 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 3126 | |
| 3127 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 3128 | f_fdir->mask = 0; |
| 3129 | |
| 3130 | /* Flow Director must have RSS enabled */ |
| 3131 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3132 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3133 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) { |
| 3134 | adapter->num_tx_queues = f_fdir->indices; |
| 3135 | adapter->num_rx_queues = f_fdir->indices; |
| 3136 | ret = true; |
| 3137 | } else { |
| 3138 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3139 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3140 | } |
| 3141 | return ret; |
| 3142 | } |
| 3143 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3144 | #ifdef IXGBE_FCOE |
| 3145 | /** |
| 3146 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 3147 | * @adapter: board private structure to initialize |
| 3148 | * |
| 3149 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 3150 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 3151 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 3152 | * index of the first rx queue used by FCoE. |
| 3153 | * |
| 3154 | **/ |
| 3155 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 3156 | { |
| 3157 | bool ret = false; |
| 3158 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3159 | |
| 3160 | f->indices = min((int)num_online_cpus(), f->indices); |
| 3161 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3162 | adapter->num_rx_queues = 1; |
| 3163 | adapter->num_tx_queues = 1; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3164 | #ifdef CONFIG_IXGBE_DCB |
| 3165 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3166 | DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n"); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3167 | ixgbe_set_dcb_queues(adapter); |
| 3168 | } |
| 3169 | #endif |
| 3170 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3171 | DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n"); |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3172 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3173 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3174 | ixgbe_set_fdir_queues(adapter); |
| 3175 | else |
| 3176 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3177 | } |
| 3178 | /* adding FCoE rx rings to the end */ |
| 3179 | f->mask = adapter->num_rx_queues; |
| 3180 | adapter->num_rx_queues += f->indices; |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3181 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3182 | |
| 3183 | ret = true; |
| 3184 | } |
| 3185 | |
| 3186 | return ret; |
| 3187 | } |
| 3188 | |
| 3189 | #endif /* IXGBE_FCOE */ |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3190 | /* |
| 3191 | * ixgbe_set_num_queues: Allocate queues for device, feature dependant |
| 3192 | * @adapter: board private structure to initialize |
| 3193 | * |
| 3194 | * This is the top level queue allocation routine. The order here is very |
| 3195 | * important, starting with the "most" number of features turned on at once, |
| 3196 | * and ending with the smallest set of features. This way large combinations |
| 3197 | * can be allocated if they're turned on, and smaller combinations are the |
| 3198 | * fallthrough conditions. |
| 3199 | * |
| 3200 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3201 | static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
| 3202 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3203 | #ifdef IXGBE_FCOE |
| 3204 | if (ixgbe_set_fcoe_queues(adapter)) |
| 3205 | goto done; |
| 3206 | |
| 3207 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3208 | #ifdef CONFIG_IXGBE_DCB |
| 3209 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3210 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3211 | |
| 3212 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3213 | if (ixgbe_set_fdir_queues(adapter)) |
| 3214 | goto done; |
| 3215 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3216 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3217 | goto done; |
| 3218 | |
| 3219 | /* fallback to base case */ |
| 3220 | adapter->num_rx_queues = 1; |
| 3221 | adapter->num_tx_queues = 1; |
| 3222 | |
| 3223 | done: |
| 3224 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ |
| 3225 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3226 | } |
| 3227 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3228 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3229 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3230 | { |
| 3231 | int err, vector_threshold; |
| 3232 | |
| 3233 | /* We'll want at least 3 (vector_threshold): |
| 3234 | * 1) TxQ[0] Cleanup |
| 3235 | * 2) RxQ[0] Cleanup |
| 3236 | * 3) Other (Link Status Change, etc.) |
| 3237 | * 4) TCP Timer (optional) |
| 3238 | */ |
| 3239 | vector_threshold = MIN_MSIX_COUNT; |
| 3240 | |
| 3241 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 3242 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 3243 | * Right now, we simply care about how many we'll get; we'll |
| 3244 | * set them up later while requesting irq's. |
| 3245 | */ |
| 3246 | while (vectors >= vector_threshold) { |
| 3247 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3248 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3249 | if (!err) /* Success in acquiring all requested vectors. */ |
| 3250 | break; |
| 3251 | else if (err < 0) |
| 3252 | vectors = 0; /* Nasty failure, quit now */ |
| 3253 | else /* err == number of vectors we should try again with */ |
| 3254 | vectors = err; |
| 3255 | } |
| 3256 | |
| 3257 | if (vectors < vector_threshold) { |
| 3258 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 3259 | * This just means we'll go with either a single MSI |
| 3260 | * vector or fall back to legacy interrupts. |
| 3261 | */ |
| 3262 | DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n"); |
| 3263 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3264 | kfree(adapter->msix_entries); |
| 3265 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3266 | } else { |
| 3267 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 3268 | /* |
| 3269 | * Adjust for only the vectors we'll use, which is minimum |
| 3270 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 3271 | * vectors we were allocated. |
| 3272 | */ |
| 3273 | adapter->num_msix_vectors = min(vectors, |
| 3274 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3275 | } |
| 3276 | } |
| 3277 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3278 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3279 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3280 | * @adapter: board private structure to initialize |
| 3281 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3282 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 3283 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3284 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3285 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3286 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3287 | int i; |
| 3288 | bool ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3289 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3290 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 3291 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3292 | adapter->rx_ring[i].reg_idx = i; |
| 3293 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3294 | adapter->tx_ring[i].reg_idx = i; |
| 3295 | ret = true; |
| 3296 | } else { |
| 3297 | ret = false; |
| 3298 | } |
| 3299 | |
| 3300 | return ret; |
| 3301 | } |
| 3302 | |
| 3303 | #ifdef CONFIG_IXGBE_DCB |
| 3304 | /** |
| 3305 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 3306 | * @adapter: board private structure to initialize |
| 3307 | * |
| 3308 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 3309 | * |
| 3310 | **/ |
| 3311 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 3312 | { |
| 3313 | int i; |
| 3314 | bool ret = false; |
| 3315 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 3316 | |
| 3317 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3318 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3319 | /* the number of queues is assumed to be symmetric */ |
| 3320 | for (i = 0; i < dcb_i; i++) { |
| 3321 | adapter->rx_ring[i].reg_idx = i << 3; |
| 3322 | adapter->tx_ring[i].reg_idx = i << 2; |
| 3323 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3324 | ret = true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3325 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3326 | if (dcb_i == 8) { |
| 3327 | /* |
| 3328 | * Tx TC0 starts at: descriptor queue 0 |
| 3329 | * Tx TC1 starts at: descriptor queue 32 |
| 3330 | * Tx TC2 starts at: descriptor queue 64 |
| 3331 | * Tx TC3 starts at: descriptor queue 80 |
| 3332 | * Tx TC4 starts at: descriptor queue 96 |
| 3333 | * Tx TC5 starts at: descriptor queue 104 |
| 3334 | * Tx TC6 starts at: descriptor queue 112 |
| 3335 | * Tx TC7 starts at: descriptor queue 120 |
| 3336 | * |
| 3337 | * Rx TC0-TC7 are offset by 16 queues each |
| 3338 | */ |
| 3339 | for (i = 0; i < 3; i++) { |
| 3340 | adapter->tx_ring[i].reg_idx = i << 5; |
| 3341 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3342 | } |
| 3343 | for ( ; i < 5; i++) { |
| 3344 | adapter->tx_ring[i].reg_idx = |
| 3345 | ((i + 2) << 4); |
| 3346 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3347 | } |
| 3348 | for ( ; i < dcb_i; i++) { |
| 3349 | adapter->tx_ring[i].reg_idx = |
| 3350 | ((i + 8) << 3); |
| 3351 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3352 | } |
| 3353 | |
| 3354 | ret = true; |
| 3355 | } else if (dcb_i == 4) { |
| 3356 | /* |
| 3357 | * Tx TC0 starts at: descriptor queue 0 |
| 3358 | * Tx TC1 starts at: descriptor queue 64 |
| 3359 | * Tx TC2 starts at: descriptor queue 96 |
| 3360 | * Tx TC3 starts at: descriptor queue 112 |
| 3361 | * |
| 3362 | * Rx TC0-TC3 are offset by 32 queues each |
| 3363 | */ |
| 3364 | adapter->tx_ring[0].reg_idx = 0; |
| 3365 | adapter->tx_ring[1].reg_idx = 64; |
| 3366 | adapter->tx_ring[2].reg_idx = 96; |
| 3367 | adapter->tx_ring[3].reg_idx = 112; |
| 3368 | for (i = 0 ; i < dcb_i; i++) |
| 3369 | adapter->rx_ring[i].reg_idx = i << 5; |
| 3370 | |
| 3371 | ret = true; |
| 3372 | } else { |
| 3373 | ret = false; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3374 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3375 | } else { |
| 3376 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3377 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3378 | } else { |
| 3379 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3380 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3381 | |
| 3382 | return ret; |
| 3383 | } |
| 3384 | #endif |
| 3385 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3386 | /** |
| 3387 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 3388 | * @adapter: board private structure to initialize |
| 3389 | * |
| 3390 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 3391 | * |
| 3392 | **/ |
| 3393 | static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter) |
| 3394 | { |
| 3395 | int i; |
| 3396 | bool ret = false; |
| 3397 | |
| 3398 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3399 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3400 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) { |
| 3401 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3402 | adapter->rx_ring[i].reg_idx = i; |
| 3403 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3404 | adapter->tx_ring[i].reg_idx = i; |
| 3405 | ret = true; |
| 3406 | } |
| 3407 | |
| 3408 | return ret; |
| 3409 | } |
| 3410 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3411 | #ifdef IXGBE_FCOE |
| 3412 | /** |
| 3413 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 3414 | * @adapter: board private structure to initialize |
| 3415 | * |
| 3416 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 3417 | * |
| 3418 | */ |
| 3419 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 3420 | { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3421 | int i, fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3422 | bool ret = false; |
| 3423 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3424 | |
| 3425 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 3426 | #ifdef CONFIG_IXGBE_DCB |
| 3427 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3428 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 3429 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3430 | ixgbe_cache_ring_dcb(adapter); |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3431 | /* find out queues in TC for FCoE */ |
| 3432 | fcoe_rx_i = adapter->rx_ring[fcoe->tc].reg_idx + 1; |
| 3433 | fcoe_tx_i = adapter->tx_ring[fcoe->tc].reg_idx + 1; |
| 3434 | /* |
| 3435 | * In 82599, the number of Tx queues for each traffic |
| 3436 | * class for both 8-TC and 4-TC modes are: |
| 3437 | * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7 |
| 3438 | * 8 TCs: 32 32 16 16 8 8 8 8 |
| 3439 | * 4 TCs: 64 64 32 32 |
| 3440 | * We have max 8 queues for FCoE, where 8 the is |
| 3441 | * FCoE redirection table size. If TC for FCoE is |
| 3442 | * less than or equal to TC3, we have enough queues |
| 3443 | * to add max of 8 queues for FCoE, so we start FCoE |
| 3444 | * tx descriptor from the next one, i.e., reg_idx + 1. |
| 3445 | * If TC for FCoE is above TC3, implying 8 TC mode, |
| 3446 | * and we need 8 for FCoE, we have to take all queues |
| 3447 | * in that traffic class for FCoE. |
| 3448 | */ |
| 3449 | if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3)) |
| 3450 | fcoe_tx_i--; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3451 | } |
| 3452 | #endif /* CONFIG_IXGBE_DCB */ |
| 3453 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3454 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3455 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3456 | ixgbe_cache_ring_fdir(adapter); |
| 3457 | else |
| 3458 | ixgbe_cache_ring_rss(adapter); |
| 3459 | |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3460 | fcoe_rx_i = f->mask; |
| 3461 | fcoe_tx_i = f->mask; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3462 | } |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3463 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 3464 | adapter->rx_ring[f->mask + i].reg_idx = fcoe_rx_i; |
| 3465 | adapter->tx_ring[f->mask + i].reg_idx = fcoe_tx_i; |
| 3466 | } |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3467 | ret = true; |
| 3468 | } |
| 3469 | return ret; |
| 3470 | } |
| 3471 | |
| 3472 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3473 | /** |
| 3474 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 3475 | * @adapter: board private structure to initialize |
| 3476 | * |
| 3477 | * Once we know the feature-set enabled for the device, we'll cache |
| 3478 | * the register offset the descriptor ring is assigned to. |
| 3479 | * |
| 3480 | * Note, the order the various feature calls is important. It must start with |
| 3481 | * the "most" features enabled at the same time, then trickle down to the |
| 3482 | * least amount of features turned on at once. |
| 3483 | **/ |
| 3484 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 3485 | { |
| 3486 | /* start with default case */ |
| 3487 | adapter->rx_ring[0].reg_idx = 0; |
| 3488 | adapter->tx_ring[0].reg_idx = 0; |
| 3489 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3490 | #ifdef IXGBE_FCOE |
| 3491 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 3492 | return; |
| 3493 | |
| 3494 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3495 | #ifdef CONFIG_IXGBE_DCB |
| 3496 | if (ixgbe_cache_ring_dcb(adapter)) |
| 3497 | return; |
| 3498 | |
| 3499 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3500 | if (ixgbe_cache_ring_fdir(adapter)) |
| 3501 | return; |
| 3502 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3503 | if (ixgbe_cache_ring_rss(adapter)) |
| 3504 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3505 | } |
| 3506 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3507 | /** |
| 3508 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 3509 | * @adapter: board private structure to initialize |
| 3510 | * |
| 3511 | * 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] | 3512 | * number of queues at compile-time. The polling_netdev array is |
| 3513 | * intended for Multiqueue, but should work fine with a single queue. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3514 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3515 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3516 | { |
| 3517 | int i; |
| 3518 | |
| 3519 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3520 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3521 | if (!adapter->tx_ring) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3522 | goto err_tx_ring_allocation; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3523 | |
| 3524 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3525 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3526 | if (!adapter->rx_ring) |
| 3527 | goto err_rx_ring_allocation; |
| 3528 | |
| 3529 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3530 | adapter->tx_ring[i].count = adapter->tx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3531 | adapter->tx_ring[i].queue_index = i; |
| 3532 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3533 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3534 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3535 | adapter->rx_ring[i].count = adapter->rx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3536 | adapter->rx_ring[i].queue_index = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3539 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3540 | |
| 3541 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3542 | |
| 3543 | err_rx_ring_allocation: |
| 3544 | kfree(adapter->tx_ring); |
| 3545 | err_tx_ring_allocation: |
| 3546 | return -ENOMEM; |
| 3547 | } |
| 3548 | |
| 3549 | /** |
| 3550 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 3551 | * @adapter: board private structure to initialize |
| 3552 | * |
| 3553 | * Attempt to configure the interrupts using the best available |
| 3554 | * capabilities of the hardware and the kernel. |
| 3555 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 3556 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3557 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3558 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3559 | int err = 0; |
| 3560 | int vector, v_budget; |
| 3561 | |
| 3562 | /* |
| 3563 | * It's easy to be greedy for MSI-X vectors, but it really |
| 3564 | * doesn't do us much good if we have a lot more vectors |
| 3565 | * than CPU's. So let's be conservative and only ask for |
| 3566 | * (roughly) twice the number of vectors as there are CPU's. |
| 3567 | */ |
| 3568 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3569 | (int)(num_online_cpus() * 2)) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3570 | |
| 3571 | /* |
| 3572 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3573 | * hw.mac->max_msix_vectors vectors. With features |
| 3574 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 3575 | * descriptor queues supported by our device. Thus, we cap it off in |
| 3576 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3577 | */ |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3578 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3579 | |
| 3580 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 3581 | * mean we disable MSI-X capabilities of the adapter. */ |
| 3582 | adapter->msix_entries = kcalloc(v_budget, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3583 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3584 | if (adapter->msix_entries) { |
| 3585 | for (vector = 0; vector < v_budget; vector++) |
| 3586 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3587 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3588 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 3589 | |
| 3590 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3591 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3592 | } |
| 3593 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3594 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 3595 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3596 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3597 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3598 | adapter->atr_sample_rate = 0; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3599 | ixgbe_set_num_queues(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3600 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3601 | err = pci_enable_msi(adapter->pdev); |
| 3602 | if (!err) { |
| 3603 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 3604 | } else { |
| 3605 | DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3606 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3607 | /* reset err */ |
| 3608 | err = 0; |
| 3609 | } |
| 3610 | |
| 3611 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3612 | return err; |
| 3613 | } |
| 3614 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3615 | /** |
| 3616 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 3617 | * @adapter: board private structure to initialize |
| 3618 | * |
| 3619 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 3620 | * return -ENOMEM. |
| 3621 | **/ |
| 3622 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 3623 | { |
| 3624 | int q_idx, num_q_vectors; |
| 3625 | struct ixgbe_q_vector *q_vector; |
| 3626 | int napi_vectors; |
| 3627 | int (*poll)(struct napi_struct *, int); |
| 3628 | |
| 3629 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3630 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3631 | napi_vectors = adapter->num_rx_queues; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3632 | poll = &ixgbe_clean_rxtx_many; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3633 | } else { |
| 3634 | num_q_vectors = 1; |
| 3635 | napi_vectors = 1; |
| 3636 | poll = &ixgbe_poll; |
| 3637 | } |
| 3638 | |
| 3639 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3640 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL); |
| 3641 | if (!q_vector) |
| 3642 | goto err_out; |
| 3643 | q_vector->adapter = adapter; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 3644 | if (q_vector->txr_count && !q_vector->rxr_count) |
| 3645 | q_vector->eitr = adapter->tx_eitr_param; |
| 3646 | else |
| 3647 | q_vector->eitr = adapter->rx_eitr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3648 | q_vector->v_idx = q_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3649 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3650 | adapter->q_vector[q_idx] = q_vector; |
| 3651 | } |
| 3652 | |
| 3653 | return 0; |
| 3654 | |
| 3655 | err_out: |
| 3656 | while (q_idx) { |
| 3657 | q_idx--; |
| 3658 | q_vector = adapter->q_vector[q_idx]; |
| 3659 | netif_napi_del(&q_vector->napi); |
| 3660 | kfree(q_vector); |
| 3661 | adapter->q_vector[q_idx] = NULL; |
| 3662 | } |
| 3663 | return -ENOMEM; |
| 3664 | } |
| 3665 | |
| 3666 | /** |
| 3667 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 3668 | * @adapter: board private structure to initialize |
| 3669 | * |
| 3670 | * This function frees the memory allocated to the q_vectors. In addition if |
| 3671 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 3672 | * to freeing the q_vector. |
| 3673 | **/ |
| 3674 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 3675 | { |
| 3676 | int q_idx, num_q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3677 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3678 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3679 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3680 | else |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3681 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3682 | |
| 3683 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3684 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3685 | adapter->q_vector[q_idx] = NULL; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3686 | netif_napi_del(&q_vector->napi); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3687 | kfree(q_vector); |
| 3688 | } |
| 3689 | } |
| 3690 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 3691 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3692 | { |
| 3693 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3694 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3695 | pci_disable_msix(adapter->pdev); |
| 3696 | kfree(adapter->msix_entries); |
| 3697 | adapter->msix_entries = NULL; |
| 3698 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 3699 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 3700 | pci_disable_msi(adapter->pdev); |
| 3701 | } |
| 3702 | return; |
| 3703 | } |
| 3704 | |
| 3705 | /** |
| 3706 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 3707 | * @adapter: board private structure to initialize |
| 3708 | * |
| 3709 | * We determine which interrupt scheme to use based on... |
| 3710 | * - Kernel support (MSI, MSI-X) |
| 3711 | * - which can be user-defined (via MODULE_PARAM) |
| 3712 | * - Hardware queue count (num_*_queues) |
| 3713 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 3714 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3715 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3716 | { |
| 3717 | int err; |
| 3718 | |
| 3719 | /* Number of supported queues */ |
| 3720 | ixgbe_set_num_queues(adapter); |
| 3721 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3722 | err = ixgbe_set_interrupt_capability(adapter); |
| 3723 | if (err) { |
| 3724 | DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n"); |
| 3725 | goto err_set_interrupt; |
| 3726 | } |
| 3727 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3728 | err = ixgbe_alloc_q_vectors(adapter); |
| 3729 | if (err) { |
| 3730 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queue " |
| 3731 | "vectors\n"); |
| 3732 | goto err_alloc_q_vectors; |
| 3733 | } |
| 3734 | |
| 3735 | err = ixgbe_alloc_queues(adapter); |
| 3736 | if (err) { |
| 3737 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 3738 | goto err_alloc_queues; |
| 3739 | } |
| 3740 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3741 | DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3742 | "Tx Queue count = %u\n", |
| 3743 | (adapter->num_rx_queues > 1) ? "Enabled" : |
| 3744 | "Disabled", adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3745 | |
| 3746 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3747 | |
| 3748 | return 0; |
| 3749 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3750 | err_alloc_queues: |
| 3751 | ixgbe_free_q_vectors(adapter); |
| 3752 | err_alloc_q_vectors: |
| 3753 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3754 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3755 | return err; |
| 3756 | } |
| 3757 | |
| 3758 | /** |
| 3759 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 3760 | * @adapter: board private structure to clear interrupt scheme on |
| 3761 | * |
| 3762 | * We go through and clear interrupt specific resources and reset the structure |
| 3763 | * to pre-load conditions |
| 3764 | **/ |
| 3765 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 3766 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3767 | kfree(adapter->tx_ring); |
| 3768 | kfree(adapter->rx_ring); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3769 | adapter->tx_ring = NULL; |
| 3770 | adapter->rx_ring = NULL; |
| 3771 | |
| 3772 | ixgbe_free_q_vectors(adapter); |
| 3773 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | /** |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3777 | * ixgbe_sfp_timer - worker thread to find a missing module |
| 3778 | * @data: pointer to our adapter struct |
| 3779 | **/ |
| 3780 | static void ixgbe_sfp_timer(unsigned long data) |
| 3781 | { |
| 3782 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 3783 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3784 | /* |
| 3785 | * Do the sfp_timer outside of interrupt context due to the |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3786 | * delays that sfp+ detection requires |
| 3787 | */ |
| 3788 | schedule_work(&adapter->sfp_task); |
| 3789 | } |
| 3790 | |
| 3791 | /** |
| 3792 | * ixgbe_sfp_task - worker thread to find a missing module |
| 3793 | * @work: pointer to work_struct containing our data |
| 3794 | **/ |
| 3795 | static void ixgbe_sfp_task(struct work_struct *work) |
| 3796 | { |
| 3797 | struct ixgbe_adapter *adapter = container_of(work, |
| 3798 | struct ixgbe_adapter, |
| 3799 | sfp_task); |
| 3800 | struct ixgbe_hw *hw = &adapter->hw; |
| 3801 | |
| 3802 | if ((hw->phy.type == ixgbe_phy_nl) && |
| 3803 | (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) { |
| 3804 | s32 ret = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 3805 | if (ret == IXGBE_ERR_SFP_NOT_PRESENT) |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3806 | goto reschedule; |
| 3807 | ret = hw->phy.ops.reset(hw); |
| 3808 | if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 3809 | dev_err(&adapter->pdev->dev, "failed to initialize " |
| 3810 | "because an unsupported SFP+ module type " |
| 3811 | "was detected.\n" |
| 3812 | "Reload the driver after installing a " |
| 3813 | "supported module.\n"); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3814 | unregister_netdev(adapter->netdev); |
| 3815 | } else { |
| 3816 | DPRINTK(PROBE, INFO, "detected SFP+: %d\n", |
| 3817 | hw->phy.sfp_type); |
| 3818 | } |
| 3819 | /* don't need this routine any more */ |
| 3820 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3821 | } |
| 3822 | return; |
| 3823 | reschedule: |
| 3824 | if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state)) |
| 3825 | mod_timer(&adapter->sfp_timer, |
| 3826 | round_jiffies(jiffies + (2 * HZ))); |
| 3827 | } |
| 3828 | |
| 3829 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3830 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 3831 | * @adapter: board private structure to initialize |
| 3832 | * |
| 3833 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 3834 | * Fields are initialized based on PCI device information and |
| 3835 | * OS network device settings (MTU size). |
| 3836 | **/ |
| 3837 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 3838 | { |
| 3839 | struct ixgbe_hw *hw = &adapter->hw; |
| 3840 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3841 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3842 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3843 | int j; |
| 3844 | struct tc_configuration *tc; |
| 3845 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3846 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3847 | /* PCI config space info */ |
| 3848 | |
| 3849 | hw->vendor_id = pdev->vendor; |
| 3850 | hw->device_id = pdev->device; |
| 3851 | hw->revision_id = pdev->revision; |
| 3852 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 3853 | hw->subsystem_device_id = pdev->subsystem_device; |
| 3854 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3855 | /* Set capability flags */ |
| 3856 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 3857 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 3858 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3859 | adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3860 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3861 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 3862 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3863 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3864 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3865 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 3866 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 3867 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3868 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3869 | adapter->ring_feature[RING_F_FDIR].indices = |
| 3870 | IXGBE_MAX_FDIR_INDICES; |
| 3871 | adapter->atr_sample_rate = 20; |
| 3872 | adapter->fdir_pballoc = 0; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3873 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 3874 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 3875 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 3876 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 3877 | /* Default traffic class to use for FCoE */ |
| 3878 | adapter->fcoe.tc = IXGBE_FCOE_DEFTC; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3879 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3880 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3881 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3882 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3883 | /* Configure DCB traffic classes */ |
| 3884 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 3885 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 3886 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 3887 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3888 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 3889 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3890 | tc->dcb_pfc = pfc_disabled; |
| 3891 | } |
| 3892 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 3893 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 3894 | adapter->dcb_cfg.rx_pba_cfg = pba_equal; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 3895 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3896 | adapter->dcb_cfg.round_robin_enable = false; |
| 3897 | adapter->dcb_set_bitmap = 0x00; |
| 3898 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
| 3899 | adapter->ring_feature[RING_F_DCB].indices); |
| 3900 | |
| 3901 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3902 | |
| 3903 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 3904 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 3905 | 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] | 3906 | #ifdef CONFIG_DCB |
| 3907 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 3908 | #endif |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 3909 | hw->fc.high_water = IXGBE_DEFAULT_FCRTH; |
| 3910 | hw->fc.low_water = IXGBE_DEFAULT_FCRTL; |
| 3911 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 3912 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 3913 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3914 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 3915 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 3916 | adapter->rx_itr_setting = 1; |
| 3917 | adapter->rx_eitr_param = 20000; |
| 3918 | adapter->tx_itr_setting = 1; |
| 3919 | adapter->tx_eitr_param = 10000; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 3920 | |
| 3921 | /* set defaults for eitr in MegaBytes */ |
| 3922 | adapter->eitr_low = 10; |
| 3923 | adapter->eitr_high = 20; |
| 3924 | |
| 3925 | /* set default ring sizes */ |
| 3926 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 3927 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 3928 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3929 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3930 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3931 | dev_err(&pdev->dev, "EEPROM initialization failed\n"); |
| 3932 | return -EIO; |
| 3933 | } |
| 3934 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3935 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3936 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 3937 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3938 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3939 | |
| 3940 | return 0; |
| 3941 | } |
| 3942 | |
| 3943 | /** |
| 3944 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
| 3945 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3946 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3947 | * |
| 3948 | * Return 0 on success, negative on failure |
| 3949 | **/ |
| 3950 | int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3951 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3952 | { |
| 3953 | struct pci_dev *pdev = adapter->pdev; |
| 3954 | int size; |
| 3955 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3956 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 3957 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3958 | if (!tx_ring->tx_buffer_info) |
| 3959 | goto err; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3960 | memset(tx_ring->tx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3961 | |
| 3962 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 3963 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3964 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3965 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3966 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, |
| 3967 | &tx_ring->dma); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3968 | if (!tx_ring->desc) |
| 3969 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3970 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3971 | tx_ring->next_to_use = 0; |
| 3972 | tx_ring->next_to_clean = 0; |
| 3973 | tx_ring->work_limit = tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3974 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3975 | |
| 3976 | err: |
| 3977 | vfree(tx_ring->tx_buffer_info); |
| 3978 | tx_ring->tx_buffer_info = NULL; |
| 3979 | DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit " |
| 3980 | "descriptor ring\n"); |
| 3981 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3982 | } |
| 3983 | |
| 3984 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 3985 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 3986 | * @adapter: board private structure |
| 3987 | * |
| 3988 | * If this function returns with an error, then it's possible one or |
| 3989 | * more of the rings is populated (while the rest are not). It is the |
| 3990 | * callers duty to clean those orphaned rings. |
| 3991 | * |
| 3992 | * Return 0 on success, negative on failure |
| 3993 | **/ |
| 3994 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 3995 | { |
| 3996 | int i, err = 0; |
| 3997 | |
| 3998 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3999 | err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 4000 | if (!err) |
| 4001 | continue; |
| 4002 | DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i); |
| 4003 | break; |
| 4004 | } |
| 4005 | |
| 4006 | return err; |
| 4007 | } |
| 4008 | |
| 4009 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4010 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
| 4011 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4012 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4013 | * |
| 4014 | * Returns 0 on success, negative on failure |
| 4015 | **/ |
| 4016 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4017 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4018 | { |
| 4019 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4020 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4021 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4022 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4023 | rx_ring->rx_buffer_info = vmalloc(size); |
| 4024 | if (!rx_ring->rx_buffer_info) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4025 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4026 | "vmalloc allocation failed for the rx desc ring\n"); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4027 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4028 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4029 | memset(rx_ring->rx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4030 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4031 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4032 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 4033 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4034 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4035 | 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] | 4036 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4037 | if (!rx_ring->desc) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4038 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4039 | "Memory allocation failed for the rx desc ring\n"); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4040 | vfree(rx_ring->rx_buffer_info); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4041 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4042 | } |
| 4043 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4044 | rx_ring->next_to_clean = 0; |
| 4045 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4046 | |
| 4047 | return 0; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4048 | |
| 4049 | alloc_failed: |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4050 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4054 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 4055 | * @adapter: board private structure |
| 4056 | * |
| 4057 | * If this function returns with an error, then it's possible one or |
| 4058 | * more of the rings is populated (while the rest are not). It is the |
| 4059 | * callers duty to clean those orphaned rings. |
| 4060 | * |
| 4061 | * Return 0 on success, negative on failure |
| 4062 | **/ |
| 4063 | |
| 4064 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4065 | { |
| 4066 | int i, err = 0; |
| 4067 | |
| 4068 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 4069 | err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 4070 | if (!err) |
| 4071 | continue; |
| 4072 | DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i); |
| 4073 | break; |
| 4074 | } |
| 4075 | |
| 4076 | return err; |
| 4077 | } |
| 4078 | |
| 4079 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4080 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
| 4081 | * @adapter: board private structure |
| 4082 | * @tx_ring: Tx descriptor ring for a specific queue |
| 4083 | * |
| 4084 | * Free all transmit software resources |
| 4085 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4086 | void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter, |
| 4087 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4088 | { |
| 4089 | struct pci_dev *pdev = adapter->pdev; |
| 4090 | |
| 4091 | ixgbe_clean_tx_ring(adapter, tx_ring); |
| 4092 | |
| 4093 | vfree(tx_ring->tx_buffer_info); |
| 4094 | tx_ring->tx_buffer_info = NULL; |
| 4095 | |
| 4096 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 4097 | |
| 4098 | tx_ring->desc = NULL; |
| 4099 | } |
| 4100 | |
| 4101 | /** |
| 4102 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 4103 | * @adapter: board private structure |
| 4104 | * |
| 4105 | * Free all transmit software resources |
| 4106 | **/ |
| 4107 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4108 | { |
| 4109 | int i; |
| 4110 | |
| 4111 | for (i = 0; i < adapter->num_tx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4112 | if (adapter->tx_ring[i].desc) |
| 4113 | ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4114 | } |
| 4115 | |
| 4116 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4117 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4118 | * @adapter: board private structure |
| 4119 | * @rx_ring: ring to clean the resources from |
| 4120 | * |
| 4121 | * Free all receive software resources |
| 4122 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4123 | void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter, |
| 4124 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4125 | { |
| 4126 | struct pci_dev *pdev = adapter->pdev; |
| 4127 | |
| 4128 | ixgbe_clean_rx_ring(adapter, rx_ring); |
| 4129 | |
| 4130 | vfree(rx_ring->rx_buffer_info); |
| 4131 | rx_ring->rx_buffer_info = NULL; |
| 4132 | |
| 4133 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 4134 | |
| 4135 | rx_ring->desc = NULL; |
| 4136 | } |
| 4137 | |
| 4138 | /** |
| 4139 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 4140 | * @adapter: board private structure |
| 4141 | * |
| 4142 | * Free all receive software resources |
| 4143 | **/ |
| 4144 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4145 | { |
| 4146 | int i; |
| 4147 | |
| 4148 | for (i = 0; i < adapter->num_rx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4149 | if (adapter->rx_ring[i].desc) |
| 4150 | ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4151 | } |
| 4152 | |
| 4153 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4154 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 4155 | * @netdev: network interface device structure |
| 4156 | * @new_mtu: new value for maximum frame size |
| 4157 | * |
| 4158 | * Returns 0 on success, negative on failure |
| 4159 | **/ |
| 4160 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 4161 | { |
| 4162 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4163 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4164 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 4165 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 4166 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4167 | return -EINVAL; |
| 4168 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4169 | DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n", |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4170 | netdev->mtu, new_mtu); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4171 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4172 | netdev->mtu = new_mtu; |
| 4173 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4174 | if (netif_running(netdev)) |
| 4175 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4176 | |
| 4177 | return 0; |
| 4178 | } |
| 4179 | |
| 4180 | /** |
| 4181 | * ixgbe_open - Called when a network interface is made active |
| 4182 | * @netdev: network interface device structure |
| 4183 | * |
| 4184 | * Returns 0 on success, negative value on failure |
| 4185 | * |
| 4186 | * The open entry point is called when a network interface is made |
| 4187 | * active by the system (IFF_UP). At this point all resources needed |
| 4188 | * for transmit and receive operations are allocated, the interrupt |
| 4189 | * handler is registered with the OS, the watchdog timer is started, |
| 4190 | * and the stack is notified that the interface is ready. |
| 4191 | **/ |
| 4192 | static int ixgbe_open(struct net_device *netdev) |
| 4193 | { |
| 4194 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4195 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4196 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 4197 | /* disallow open during test */ |
| 4198 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 4199 | return -EBUSY; |
| 4200 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 4201 | netif_carrier_off(netdev); |
| 4202 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4203 | /* allocate transmit descriptors */ |
| 4204 | err = ixgbe_setup_all_tx_resources(adapter); |
| 4205 | if (err) |
| 4206 | goto err_setup_tx; |
| 4207 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4208 | /* allocate receive descriptors */ |
| 4209 | err = ixgbe_setup_all_rx_resources(adapter); |
| 4210 | if (err) |
| 4211 | goto err_setup_rx; |
| 4212 | |
| 4213 | ixgbe_configure(adapter); |
| 4214 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4215 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4216 | if (err) |
| 4217 | goto err_req_irq; |
| 4218 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4219 | err = ixgbe_up_complete(adapter); |
| 4220 | if (err) |
| 4221 | goto err_up; |
| 4222 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 4223 | netif_tx_start_all_queues(netdev); |
| 4224 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4225 | return 0; |
| 4226 | |
| 4227 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4228 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4229 | ixgbe_free_irq(adapter); |
| 4230 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4231 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4232 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4233 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4234 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4235 | ixgbe_reset(adapter); |
| 4236 | |
| 4237 | return err; |
| 4238 | } |
| 4239 | |
| 4240 | /** |
| 4241 | * ixgbe_close - Disables a network interface |
| 4242 | * @netdev: network interface device structure |
| 4243 | * |
| 4244 | * Returns 0, this is not allowed to fail |
| 4245 | * |
| 4246 | * The close entry point is called when an interface is de-activated |
| 4247 | * by the OS. The hardware is still under the drivers control, but |
| 4248 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4249 | * hardware, and all transmit and receive resources are freed. |
| 4250 | **/ |
| 4251 | static int ixgbe_close(struct net_device *netdev) |
| 4252 | { |
| 4253 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4254 | |
| 4255 | ixgbe_down(adapter); |
| 4256 | ixgbe_free_irq(adapter); |
| 4257 | |
| 4258 | ixgbe_free_all_tx_resources(adapter); |
| 4259 | ixgbe_free_all_rx_resources(adapter); |
| 4260 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4261 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4262 | |
| 4263 | return 0; |
| 4264 | } |
| 4265 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4266 | #ifdef CONFIG_PM |
| 4267 | static int ixgbe_resume(struct pci_dev *pdev) |
| 4268 | { |
| 4269 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4270 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4271 | u32 err; |
| 4272 | |
| 4273 | pci_set_power_state(pdev, PCI_D0); |
| 4274 | pci_restore_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 4275 | |
| 4276 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4277 | if (err) { |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4278 | printk(KERN_ERR "ixgbe: Cannot enable PCI device from " |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4279 | "suspend\n"); |
| 4280 | return err; |
| 4281 | } |
| 4282 | pci_set_master(pdev); |
| 4283 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4284 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4285 | |
| 4286 | err = ixgbe_init_interrupt_scheme(adapter); |
| 4287 | if (err) { |
| 4288 | printk(KERN_ERR "ixgbe: Cannot initialize interrupts for " |
| 4289 | "device\n"); |
| 4290 | return err; |
| 4291 | } |
| 4292 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4293 | ixgbe_reset(adapter); |
| 4294 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 4295 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 4296 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4297 | if (netif_running(netdev)) { |
| 4298 | err = ixgbe_open(adapter->netdev); |
| 4299 | if (err) |
| 4300 | return err; |
| 4301 | } |
| 4302 | |
| 4303 | netif_device_attach(netdev); |
| 4304 | |
| 4305 | return 0; |
| 4306 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4307 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4308 | |
| 4309 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4310 | { |
| 4311 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4312 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4313 | struct ixgbe_hw *hw = &adapter->hw; |
| 4314 | u32 ctrl, fctrl; |
| 4315 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4316 | #ifdef CONFIG_PM |
| 4317 | int retval = 0; |
| 4318 | #endif |
| 4319 | |
| 4320 | netif_device_detach(netdev); |
| 4321 | |
| 4322 | if (netif_running(netdev)) { |
| 4323 | ixgbe_down(adapter); |
| 4324 | ixgbe_free_irq(adapter); |
| 4325 | ixgbe_free_all_tx_resources(adapter); |
| 4326 | ixgbe_free_all_rx_resources(adapter); |
| 4327 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4328 | ixgbe_clear_interrupt_scheme(adapter); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4329 | |
| 4330 | #ifdef CONFIG_PM |
| 4331 | retval = pci_save_state(pdev); |
| 4332 | if (retval) |
| 4333 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4334 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4335 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4336 | if (wufc) { |
| 4337 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4338 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4339 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 4340 | if (wufc & IXGBE_WUFC_MC) { |
| 4341 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4342 | fctrl |= IXGBE_FCTRL_MPE; |
| 4343 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 4344 | } |
| 4345 | |
| 4346 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 4347 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 4348 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 4349 | |
| 4350 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 4351 | } else { |
| 4352 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 4353 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 4354 | } |
| 4355 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4356 | if (wufc && hw->mac.type == ixgbe_mac_82599EB) |
| 4357 | pci_wake_from_d3(pdev, true); |
| 4358 | else |
| 4359 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4360 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4361 | *enable_wake = !!wufc; |
| 4362 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4363 | ixgbe_release_hw_control(adapter); |
| 4364 | |
| 4365 | pci_disable_device(pdev); |
| 4366 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4367 | return 0; |
| 4368 | } |
| 4369 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4370 | #ifdef CONFIG_PM |
| 4371 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4372 | { |
| 4373 | int retval; |
| 4374 | bool wake; |
| 4375 | |
| 4376 | retval = __ixgbe_shutdown(pdev, &wake); |
| 4377 | if (retval) |
| 4378 | return retval; |
| 4379 | |
| 4380 | if (wake) { |
| 4381 | pci_prepare_to_sleep(pdev); |
| 4382 | } else { |
| 4383 | pci_wake_from_d3(pdev, false); |
| 4384 | pci_set_power_state(pdev, PCI_D3hot); |
| 4385 | } |
| 4386 | |
| 4387 | return 0; |
| 4388 | } |
| 4389 | #endif /* CONFIG_PM */ |
| 4390 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4391 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 4392 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4393 | bool wake; |
| 4394 | |
| 4395 | __ixgbe_shutdown(pdev, &wake); |
| 4396 | |
| 4397 | if (system_state == SYSTEM_POWER_OFF) { |
| 4398 | pci_wake_from_d3(pdev, wake); |
| 4399 | pci_set_power_state(pdev, PCI_D3hot); |
| 4400 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4404 | * ixgbe_update_stats - Update the board statistics counters. |
| 4405 | * @adapter: board private structure |
| 4406 | **/ |
| 4407 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 4408 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4409 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4410 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4411 | u64 total_mpc = 0; |
| 4412 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4413 | |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4414 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4415 | u64 rsc_count = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4416 | for (i = 0; i < 16; i++) |
| 4417 | adapter->hw_rx_no_dma_resources += |
| 4418 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4419 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4420 | rsc_count += adapter->rx_ring[i].rsc_count; |
| 4421 | adapter->rsc_count = rsc_count; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4422 | } |
| 4423 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4424 | adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4425 | for (i = 0; i < 8; i++) { |
| 4426 | /* for packet buffers not used, the register should read 0 */ |
| 4427 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 4428 | missed_rx += mpc; |
| 4429 | adapter->stats.mpc[i] += mpc; |
| 4430 | total_mpc += adapter->stats.mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4431 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4432 | adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4433 | adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 4434 | adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 4435 | adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 4436 | adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4437 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4438 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4439 | IXGBE_PXONRXCNT(i)); |
| 4440 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4441 | IXGBE_PXOFFRXCNT(i)); |
| 4442 | adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4443 | } else { |
| 4444 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4445 | IXGBE_PXONRXC(i)); |
| 4446 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4447 | IXGBE_PXOFFRXC(i)); |
| 4448 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4449 | adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw, |
| 4450 | IXGBE_PXONTXC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4451 | adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4452 | IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4453 | } |
| 4454 | adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
| 4455 | /* work around hardware counting issue */ |
| 4456 | adapter->stats.gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4457 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4458 | /* 82598 hardware only has a 32 bit counter in the high register */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4459 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4460 | u64 tmp; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4461 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4462 | tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */ |
| 4463 | adapter->stats.gorc += (tmp << 32); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4464 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4465 | tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */ |
| 4466 | adapter->stats.gotc += (tmp << 32); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4467 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
| 4468 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
| 4469 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
| 4470 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4471 | adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 4472 | adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 4473 | #ifdef IXGBE_FCOE |
| 4474 | adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 4475 | adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 4476 | adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 4477 | adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 4478 | adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 4479 | adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
| 4480 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4481 | } else { |
| 4482 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
| 4483 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 4484 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 4485 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 4486 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 4487 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4488 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
| 4489 | adapter->stats.bprc += bprc; |
| 4490 | adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4491 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4492 | adapter->stats.mprc -= bprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4493 | adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 4494 | adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 4495 | adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 4496 | adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 4497 | adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 4498 | adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 4499 | adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4500 | adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4501 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
| 4502 | adapter->stats.lxontxc += lxon; |
| 4503 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
| 4504 | adapter->stats.lxofftxc += lxoff; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4505 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4506 | adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4507 | adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
| 4508 | /* |
| 4509 | * 82598 errata - tx of flow control packets is included in tx counters |
| 4510 | */ |
| 4511 | xon_off_tot = lxon + lxoff; |
| 4512 | adapter->stats.gptc -= xon_off_tot; |
| 4513 | adapter->stats.mptc -= xon_off_tot; |
| 4514 | adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4515 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4516 | adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 4517 | adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4518 | adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 4519 | adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4520 | adapter->stats.ptc64 -= xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4521 | adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 4522 | adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 4523 | adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 4524 | adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 4525 | adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4526 | adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
| 4527 | |
| 4528 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4529 | netdev->stats.multicast = adapter->stats.mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4530 | |
| 4531 | /* Rx Errors */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4532 | netdev->stats.rx_errors = adapter->stats.crcerrs + |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4533 | adapter->stats.rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4534 | netdev->stats.rx_dropped = 0; |
| 4535 | netdev->stats.rx_length_errors = adapter->stats.rlec; |
| 4536 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4537 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | /** |
| 4541 | * ixgbe_watchdog - Timer Call-back |
| 4542 | * @data: pointer to adapter cast into an unsigned long |
| 4543 | **/ |
| 4544 | static void ixgbe_watchdog(unsigned long data) |
| 4545 | { |
| 4546 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4547 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4548 | u64 eics = 0; |
| 4549 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4550 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4551 | /* |
| 4552 | * Do the watchdog outside of interrupt context due to the lovely |
| 4553 | * delays that some of the newer hardware requires |
| 4554 | */ |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4555 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4556 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 4557 | goto watchdog_short_circuit; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4558 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4559 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 4560 | /* |
| 4561 | * for legacy and MSI interrupts don't set any bits |
| 4562 | * that are enabled for EIAM, because this operation |
| 4563 | * would set *both* EIMS and EICS for any bit in EIAM |
| 4564 | */ |
| 4565 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 4566 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
| 4567 | goto watchdog_reschedule; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4568 | } |
| 4569 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4570 | /* get one bit for every active tx/rx interrupt vector */ |
| 4571 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 4572 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
| 4573 | if (qv->rxr_count || qv->txr_count) |
| 4574 | eics |= ((u64)1 << i); |
| 4575 | } |
| 4576 | |
| 4577 | /* Cause software interrupt to ensure rx rings are cleaned */ |
| 4578 | ixgbe_irq_rearm_queues(adapter, eics); |
| 4579 | |
| 4580 | watchdog_reschedule: |
| 4581 | /* Reset the timer */ |
| 4582 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
| 4583 | |
| 4584 | watchdog_short_circuit: |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4585 | schedule_work(&adapter->watchdog_task); |
| 4586 | } |
| 4587 | |
| 4588 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4589 | * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber |
| 4590 | * @work: pointer to work_struct containing our data |
| 4591 | **/ |
| 4592 | static void ixgbe_multispeed_fiber_task(struct work_struct *work) |
| 4593 | { |
| 4594 | struct ixgbe_adapter *adapter = container_of(work, |
| 4595 | struct ixgbe_adapter, |
| 4596 | multispeed_fiber_task); |
| 4597 | struct ixgbe_hw *hw = &adapter->hw; |
| 4598 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4599 | bool negotiation; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4600 | |
| 4601 | adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK; |
Mallikarjuna R Chilakala | a1f2532 | 2009-06-30 11:44:36 +0000 | [diff] [blame] | 4602 | autoneg = hw->phy.autoneg_advertised; |
| 4603 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4604 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
| 4605 | if (hw->mac.ops.setup_link) |
| 4606 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4607 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4608 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK; |
| 4609 | } |
| 4610 | |
| 4611 | /** |
| 4612 | * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module |
| 4613 | * @work: pointer to work_struct containing our data |
| 4614 | **/ |
| 4615 | static void ixgbe_sfp_config_module_task(struct work_struct *work) |
| 4616 | { |
| 4617 | struct ixgbe_adapter *adapter = container_of(work, |
| 4618 | struct ixgbe_adapter, |
| 4619 | sfp_config_module_task); |
| 4620 | struct ixgbe_hw *hw = &adapter->hw; |
| 4621 | u32 err; |
| 4622 | |
| 4623 | adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK; |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4624 | |
| 4625 | /* Time for electrical oscillations to settle down */ |
| 4626 | msleep(100); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4627 | err = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4628 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4629 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 4630 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 4631 | "an unsupported SFP+ module type was detected.\n" |
| 4632 | "Reload the driver after installing a supported " |
| 4633 | "module.\n"); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4634 | unregister_netdev(adapter->netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4635 | return; |
| 4636 | } |
| 4637 | hw->mac.ops.setup_sfp(hw); |
| 4638 | |
Tony Breeds | 8d1c3c0 | 2009-04-09 22:29:10 +0000 | [diff] [blame] | 4639 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4640 | /* This will also work for DA Twinax connections */ |
| 4641 | schedule_work(&adapter->multispeed_fiber_task); |
| 4642 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK; |
| 4643 | } |
| 4644 | |
| 4645 | /** |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4646 | * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table |
| 4647 | * @work: pointer to work_struct containing our data |
| 4648 | **/ |
| 4649 | static void ixgbe_fdir_reinit_task(struct work_struct *work) |
| 4650 | { |
| 4651 | struct ixgbe_adapter *adapter = container_of(work, |
| 4652 | struct ixgbe_adapter, |
| 4653 | fdir_reinit_task); |
| 4654 | struct ixgbe_hw *hw = &adapter->hw; |
| 4655 | int i; |
| 4656 | |
| 4657 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 4658 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4659 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 4660 | &(adapter->tx_ring[i].reinit_state)); |
| 4661 | } else { |
| 4662 | DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, " |
| 4663 | "ignored adding FDIR ATR filters \n"); |
| 4664 | } |
| 4665 | /* Done FDIR Re-initialization, enable transmits */ |
| 4666 | netif_tx_start_all_queues(adapter->netdev); |
| 4667 | } |
| 4668 | |
| 4669 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4670 | * ixgbe_watchdog_task - worker thread to bring link up |
| 4671 | * @work: pointer to work_struct containing our data |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4672 | **/ |
| 4673 | static void ixgbe_watchdog_task(struct work_struct *work) |
| 4674 | { |
| 4675 | struct ixgbe_adapter *adapter = container_of(work, |
| 4676 | struct ixgbe_adapter, |
| 4677 | watchdog_task); |
| 4678 | struct net_device *netdev = adapter->netdev; |
| 4679 | struct ixgbe_hw *hw = &adapter->hw; |
| 4680 | u32 link_speed = adapter->link_speed; |
| 4681 | bool link_up = adapter->link_up; |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4682 | int i; |
| 4683 | struct ixgbe_ring *tx_ring; |
| 4684 | int some_tx_pending = 0; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4685 | |
| 4686 | adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK; |
| 4687 | |
| 4688 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) { |
| 4689 | 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] | 4690 | if (link_up) { |
| 4691 | #ifdef CONFIG_DCB |
| 4692 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 4693 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4694 | hw->mac.ops.fc_enable(hw, i); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4695 | } else { |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4696 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4697 | } |
| 4698 | #else |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4699 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4700 | #endif |
| 4701 | } |
| 4702 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4703 | if (link_up || |
| 4704 | time_after(jiffies, (adapter->link_check_timeout + |
| 4705 | IXGBE_TRY_LINK_TIMEOUT))) { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4706 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4707 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4708 | } |
| 4709 | adapter->link_up = link_up; |
| 4710 | adapter->link_speed = link_speed; |
| 4711 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4712 | |
| 4713 | if (link_up) { |
| 4714 | if (!netif_carrier_ok(netdev)) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4715 | bool flow_rx, flow_tx; |
| 4716 | |
| 4717 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4718 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 4719 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 4720 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 4721 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4722 | } else { |
| 4723 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4724 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 4725 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 4726 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4727 | } |
| 4728 | |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4729 | printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, " |
| 4730 | "Flow Control: %s\n", |
| 4731 | netdev->name, |
| 4732 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 4733 | "10 Gbps" : |
| 4734 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 4735 | "1 Gbps" : "unknown speed")), |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4736 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 4737 | (flow_rx ? "RX" : |
| 4738 | (flow_tx ? "TX" : "None")))); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4739 | |
| 4740 | netif_carrier_on(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4741 | } else { |
| 4742 | /* Force detection of hung controller */ |
| 4743 | adapter->detect_tx_hung = true; |
| 4744 | } |
| 4745 | } else { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4746 | adapter->link_up = false; |
| 4747 | adapter->link_speed = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4748 | if (netif_carrier_ok(netdev)) { |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4749 | printk(KERN_INFO "ixgbe: %s NIC Link is Down\n", |
| 4750 | netdev->name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4751 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4752 | } |
| 4753 | } |
| 4754 | |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4755 | if (!netif_carrier_ok(netdev)) { |
| 4756 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4757 | tx_ring = &adapter->tx_ring[i]; |
| 4758 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 4759 | some_tx_pending = 1; |
| 4760 | break; |
| 4761 | } |
| 4762 | } |
| 4763 | |
| 4764 | if (some_tx_pending) { |
| 4765 | /* We've lost link, so the controller stops DMA, |
| 4766 | * but we've got queued Tx work that's never going |
| 4767 | * to get done, so reset controller to flush Tx. |
| 4768 | * (Do the reset outside of interrupt context). |
| 4769 | */ |
| 4770 | schedule_work(&adapter->reset_task); |
| 4771 | } |
| 4772 | } |
| 4773 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4774 | ixgbe_update_stats(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4775 | adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4776 | } |
| 4777 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4778 | static int ixgbe_tso(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4779 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 4780 | u32 tx_flags, u8 *hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4781 | { |
| 4782 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4783 | unsigned int i; |
| 4784 | int err; |
| 4785 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4786 | u32 vlan_macip_lens = 0, type_tucmd_mlhl; |
| 4787 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4788 | |
| 4789 | if (skb_is_gso(skb)) { |
| 4790 | if (skb_header_cloned(skb)) { |
| 4791 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4792 | if (err) |
| 4793 | return err; |
| 4794 | } |
| 4795 | l4len = tcp_hdrlen(skb); |
| 4796 | *hdr_len += l4len; |
| 4797 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4798 | if (skb->protocol == htons(ETH_P_IP)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4799 | struct iphdr *iph = ip_hdr(skb); |
| 4800 | iph->tot_len = 0; |
| 4801 | iph->check = 0; |
| 4802 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4803 | iph->daddr, 0, |
| 4804 | IPPROTO_TCP, |
| 4805 | 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4806 | adapter->hw_tso_ctxt++; |
| 4807 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { |
| 4808 | ipv6_hdr(skb)->payload_len = 0; |
| 4809 | tcp_hdr(skb)->check = |
| 4810 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4811 | &ipv6_hdr(skb)->daddr, |
| 4812 | 0, IPPROTO_TCP, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4813 | adapter->hw_tso6_ctxt++; |
| 4814 | } |
| 4815 | |
| 4816 | i = tx_ring->next_to_use; |
| 4817 | |
| 4818 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4819 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4820 | |
| 4821 | /* VLAN MACLEN IPLEN */ |
| 4822 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4823 | vlan_macip_lens |= |
| 4824 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4825 | vlan_macip_lens |= ((skb_network_offset(skb)) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4826 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4827 | *hdr_len += skb_network_offset(skb); |
| 4828 | vlan_macip_lens |= |
| 4829 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4830 | *hdr_len += |
| 4831 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4832 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4833 | context_desc->seqnum_seed = 0; |
| 4834 | |
| 4835 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4836 | type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4837 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4838 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4839 | if (skb->protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4840 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 4841 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 4842 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
| 4843 | |
| 4844 | /* MSS L4LEN IDX */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4845 | mss_l4len_idx = |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4846 | (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT); |
| 4847 | mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4848 | /* use index 1 for TSO */ |
| 4849 | mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4850 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 4851 | |
| 4852 | tx_buffer_info->time_stamp = jiffies; |
| 4853 | tx_buffer_info->next_to_watch = i; |
| 4854 | |
| 4855 | i++; |
| 4856 | if (i == tx_ring->count) |
| 4857 | i = 0; |
| 4858 | tx_ring->next_to_use = i; |
| 4859 | |
| 4860 | return true; |
| 4861 | } |
| 4862 | return false; |
| 4863 | } |
| 4864 | |
| 4865 | static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4866 | struct ixgbe_ring *tx_ring, |
| 4867 | struct sk_buff *skb, u32 tx_flags) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4868 | { |
| 4869 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4870 | unsigned int i; |
| 4871 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4872 | u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0; |
| 4873 | |
| 4874 | if (skb->ip_summed == CHECKSUM_PARTIAL || |
| 4875 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) { |
| 4876 | i = tx_ring->next_to_use; |
| 4877 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4878 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4879 | |
| 4880 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4881 | vlan_macip_lens |= |
| 4882 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4883 | vlan_macip_lens |= (skb_network_offset(skb) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4884 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4885 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 4886 | vlan_macip_lens |= (skb_transport_header(skb) - |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4887 | skb_network_header(skb)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4888 | |
| 4889 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4890 | context_desc->seqnum_seed = 0; |
| 4891 | |
| 4892 | type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4893 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4894 | |
| 4895 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4896 | switch (skb->protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4897 | case cpu_to_be16(ETH_P_IP): |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4898 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4899 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 4900 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4901 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 4902 | else if (ip_hdr(skb)->protocol == IPPROTO_SCTP) |
| 4903 | type_tucmd_mlhl |= |
| 4904 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4905 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4906 | case cpu_to_be16(ETH_P_IPV6): |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4907 | /* XXX what about other V6 headers?? */ |
| 4908 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 4909 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4910 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 4911 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP) |
| 4912 | type_tucmd_mlhl |= |
| 4913 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4914 | break; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4915 | default: |
| 4916 | if (unlikely(net_ratelimit())) { |
| 4917 | DPRINTK(PROBE, WARNING, |
| 4918 | "partial checksum but proto=%x!\n", |
| 4919 | skb->protocol); |
| 4920 | } |
| 4921 | break; |
| 4922 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4926 | /* use index zero for tx checksum offload */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4927 | context_desc->mss_l4len_idx = 0; |
| 4928 | |
| 4929 | tx_buffer_info->time_stamp = jiffies; |
| 4930 | tx_buffer_info->next_to_watch = i; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4931 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4932 | adapter->hw_csum_tx_good++; |
| 4933 | i++; |
| 4934 | if (i == tx_ring->count) |
| 4935 | i = 0; |
| 4936 | tx_ring->next_to_use = i; |
| 4937 | |
| 4938 | return true; |
| 4939 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4940 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4941 | return false; |
| 4942 | } |
| 4943 | |
| 4944 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4945 | struct ixgbe_ring *tx_ring, |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4946 | struct sk_buff *skb, u32 tx_flags, |
| 4947 | unsigned int first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4948 | { |
| 4949 | struct ixgbe_tx_buffer *tx_buffer_info; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4950 | unsigned int len; |
| 4951 | unsigned int total = skb->len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4952 | unsigned int offset = 0, size, count = 0, i; |
| 4953 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 4954 | unsigned int f; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4955 | dma_addr_t *map; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4956 | |
| 4957 | i = tx_ring->next_to_use; |
| 4958 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4959 | if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) { |
| 4960 | dev_err(&adapter->pdev->dev, "TX DMA map failed\n"); |
| 4961 | return 0; |
| 4962 | } |
| 4963 | |
| 4964 | map = skb_shinfo(skb)->dma_maps; |
| 4965 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4966 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
| 4967 | /* excluding fcoe_crc_eof for FCoE */ |
| 4968 | total -= sizeof(struct fcoe_crc_eof); |
| 4969 | |
| 4970 | len = min(skb_headlen(skb), total); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4971 | while (len) { |
| 4972 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4973 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 4974 | |
| 4975 | tx_buffer_info->length = size; |
Eric Dumazet | 042a53a | 2009-06-05 04:04:16 +0000 | [diff] [blame] | 4976 | tx_buffer_info->dma = skb_shinfo(skb)->dma_head + offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4977 | tx_buffer_info->time_stamp = jiffies; |
| 4978 | tx_buffer_info->next_to_watch = i; |
| 4979 | |
| 4980 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4981 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4982 | offset += size; |
| 4983 | count++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4984 | |
| 4985 | if (len) { |
| 4986 | i++; |
| 4987 | if (i == tx_ring->count) |
| 4988 | i = 0; |
| 4989 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4990 | } |
| 4991 | |
| 4992 | for (f = 0; f < nr_frags; f++) { |
| 4993 | struct skb_frag_struct *frag; |
| 4994 | |
| 4995 | frag = &skb_shinfo(skb)->frags[f]; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4996 | len = min((unsigned int)frag->size, total); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4997 | offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4998 | |
| 4999 | while (len) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5000 | i++; |
| 5001 | if (i == tx_ring->count) |
| 5002 | i = 0; |
| 5003 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5004 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5005 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 5006 | |
| 5007 | tx_buffer_info->length = size; |
Eric Dumazet | 042a53a | 2009-06-05 04:04:16 +0000 | [diff] [blame] | 5008 | tx_buffer_info->dma = map[f] + offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5009 | tx_buffer_info->time_stamp = jiffies; |
| 5010 | tx_buffer_info->next_to_watch = i; |
| 5011 | |
| 5012 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5013 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5014 | offset += size; |
| 5015 | count++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5016 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5017 | if (total == 0) |
| 5018 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5019 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5020 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5021 | tx_ring->tx_buffer_info[i].skb = skb; |
| 5022 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 5023 | |
| 5024 | return count; |
| 5025 | } |
| 5026 | |
| 5027 | static void ixgbe_tx_queue(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5028 | struct ixgbe_ring *tx_ring, |
| 5029 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5030 | { |
| 5031 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 5032 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 5033 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 5034 | unsigned int i; |
| 5035 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 5036 | |
| 5037 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 5038 | |
| 5039 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 5040 | |
| 5041 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 5042 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 5043 | |
| 5044 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 5045 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 5046 | |
| 5047 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5048 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5049 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 5050 | /* use index 1 context for tso */ |
| 5051 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5052 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 5053 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5054 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5055 | |
| 5056 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 5057 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5058 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5059 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5060 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5061 | olinfo_status |= IXGBE_ADVTXD_CC; |
| 5062 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 5063 | if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 5064 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 5065 | } |
| 5066 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5067 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 5068 | |
| 5069 | i = tx_ring->next_to_use; |
| 5070 | while (count--) { |
| 5071 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5072 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 5073 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 5074 | tx_desc->read.cmd_type_len = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5075 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5076 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5077 | i++; |
| 5078 | if (i == tx_ring->count) |
| 5079 | i = 0; |
| 5080 | } |
| 5081 | |
| 5082 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 5083 | |
| 5084 | /* |
| 5085 | * Force memory writes to complete before letting h/w |
| 5086 | * know there are new descriptors to fetch. (Only |
| 5087 | * applicable for weak-ordered memory model archs, |
| 5088 | * such as IA-64). |
| 5089 | */ |
| 5090 | wmb(); |
| 5091 | |
| 5092 | tx_ring->next_to_use = i; |
| 5093 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
| 5094 | } |
| 5095 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5096 | static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb, |
| 5097 | int queue, u32 tx_flags) |
| 5098 | { |
| 5099 | /* Right now, we support IPv4 only */ |
| 5100 | struct ixgbe_atr_input atr_input; |
| 5101 | struct tcphdr *th; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5102 | struct iphdr *iph = ip_hdr(skb); |
| 5103 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 5104 | u16 vlan_id, src_port, dst_port, flex_bytes; |
| 5105 | u32 src_ipv4_addr, dst_ipv4_addr; |
| 5106 | u8 l4type = 0; |
| 5107 | |
| 5108 | /* check if we're UDP or TCP */ |
| 5109 | if (iph->protocol == IPPROTO_TCP) { |
| 5110 | th = tcp_hdr(skb); |
| 5111 | src_port = th->source; |
| 5112 | dst_port = th->dest; |
| 5113 | l4type |= IXGBE_ATR_L4TYPE_TCP; |
| 5114 | /* l4type IPv4 type is 0, no need to assign */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5115 | } else { |
| 5116 | /* Unsupported L4 header, just bail here */ |
| 5117 | return; |
| 5118 | } |
| 5119 | |
| 5120 | memset(&atr_input, 0, sizeof(struct ixgbe_atr_input)); |
| 5121 | |
| 5122 | vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >> |
| 5123 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5124 | src_ipv4_addr = iph->saddr; |
| 5125 | dst_ipv4_addr = iph->daddr; |
| 5126 | flex_bytes = eth->h_proto; |
| 5127 | |
| 5128 | ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id); |
| 5129 | ixgbe_atr_set_src_port_82599(&atr_input, dst_port); |
| 5130 | ixgbe_atr_set_dst_port_82599(&atr_input, src_port); |
| 5131 | ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes); |
| 5132 | ixgbe_atr_set_l4type_82599(&atr_input, l4type); |
| 5133 | /* src and dst are inverted, think how the receiver sees them */ |
| 5134 | ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr); |
| 5135 | ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr); |
| 5136 | |
| 5137 | /* This assumes the Rx queue and Tx queue are bound to the same CPU */ |
| 5138 | ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue); |
| 5139 | } |
| 5140 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5141 | static int __ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5142 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5143 | { |
| 5144 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5145 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5146 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5147 | /* Herbert's original patch had: |
| 5148 | * smp_mb__after_netif_stop_queue(); |
| 5149 | * but since that doesn't exist yet, just open code it. */ |
| 5150 | smp_mb(); |
| 5151 | |
| 5152 | /* We need to check again in a case another CPU has just |
| 5153 | * made room available. */ |
| 5154 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) |
| 5155 | return -EBUSY; |
| 5156 | |
| 5157 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Jesse Brandeburg | af72166 | 2008-09-11 19:54:23 -0700 | [diff] [blame] | 5158 | netif_start_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5159 | ++adapter->restart_queue; |
| 5160 | return 0; |
| 5161 | } |
| 5162 | |
| 5163 | static int ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5164 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5165 | { |
| 5166 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) |
| 5167 | return 0; |
| 5168 | return __ixgbe_maybe_stop_tx(netdev, tx_ring, size); |
| 5169 | } |
| 5170 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5171 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 5172 | { |
| 5173 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5174 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5175 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
| 5176 | return smp_processor_id(); |
| 5177 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5178 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
Lucy Liu | 36e89d7 | 2009-08-05 13:06:34 -0700 | [diff] [blame] | 5179 | return (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) >> 13; |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5180 | |
| 5181 | return skb_tx_hash(dev, skb); |
| 5182 | } |
| 5183 | |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 5184 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 5185 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5186 | { |
| 5187 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5188 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5189 | unsigned int first; |
| 5190 | unsigned int tx_flags = 0; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5191 | u8 hdr_len = 0; |
| 5192 | int r_idx = 0, tso; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5193 | int count = 0; |
| 5194 | unsigned int f; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5195 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5196 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 5197 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5198 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5199 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
| 5200 | tx_flags |= (skb->queue_mapping << 13); |
| 5201 | } |
| 5202 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5203 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5204 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5205 | if (skb->priority != TC_PRIO_CONTROL) { |
| 5206 | tx_flags |= (skb->queue_mapping << 13); |
| 5207 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5208 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5209 | } else { |
| 5210 | skb->queue_mapping = |
| 5211 | adapter->ring_feature[RING_F_DCB].indices-1; |
| 5212 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5213 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5214 | |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5215 | r_idx = skb->queue_mapping; |
| 5216 | tx_ring = &adapter->tx_ring[r_idx]; |
| 5217 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5218 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5219 | (skb->protocol == htons(ETH_P_FCOE))) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5220 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5221 | #ifdef IXGBE_FCOE |
| 5222 | r_idx = smp_processor_id(); |
| 5223 | r_idx &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 5224 | r_idx += adapter->ring_feature[RING_F_FCOE].mask; |
| 5225 | tx_ring = &adapter->tx_ring[r_idx]; |
| 5226 | #endif |
| 5227 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5228 | /* four things can cause us to need a context descriptor */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5229 | if (skb_is_gso(skb) || |
| 5230 | (skb->ip_summed == CHECKSUM_PARTIAL) || |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5231 | (tx_flags & IXGBE_TX_FLAGS_VLAN) || |
| 5232 | (tx_flags & IXGBE_TX_FLAGS_FCOE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5233 | count++; |
| 5234 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5235 | count += TXD_USE_COUNT(skb_headlen(skb)); |
| 5236 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5237 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 5238 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5239 | if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5240 | adapter->tx_busy++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5241 | return NETDEV_TX_BUSY; |
| 5242 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5243 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5244 | first = tx_ring->next_to_use; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5245 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5246 | #ifdef IXGBE_FCOE |
| 5247 | /* setup tx offload for FCoE */ |
| 5248 | tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5249 | if (tso < 0) { |
| 5250 | dev_kfree_skb_any(skb); |
| 5251 | return NETDEV_TX_OK; |
| 5252 | } |
| 5253 | if (tso) |
| 5254 | tx_flags |= IXGBE_TX_FLAGS_FSO; |
| 5255 | #endif /* IXGBE_FCOE */ |
| 5256 | } else { |
| 5257 | if (skb->protocol == htons(ETH_P_IP)) |
| 5258 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
| 5259 | tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5260 | if (tso < 0) { |
| 5261 | dev_kfree_skb_any(skb); |
| 5262 | return NETDEV_TX_OK; |
| 5263 | } |
| 5264 | |
| 5265 | if (tso) |
| 5266 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
| 5267 | else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) && |
| 5268 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5269 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5270 | } |
| 5271 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5272 | count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5273 | if (count) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5274 | /* add the ATR filter if ATR is on */ |
| 5275 | if (tx_ring->atr_sample_rate) { |
| 5276 | ++tx_ring->atr_count; |
| 5277 | if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) && |
| 5278 | test_bit(__IXGBE_FDIR_INIT_DONE, |
| 5279 | &tx_ring->reinit_state)) { |
| 5280 | ixgbe_atr(adapter, skb, tx_ring->queue_index, |
| 5281 | tx_flags); |
| 5282 | tx_ring->atr_count = 0; |
| 5283 | } |
| 5284 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5285 | ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len, |
| 5286 | hdr_len); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5287 | ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5288 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5289 | } else { |
| 5290 | dev_kfree_skb_any(skb); |
| 5291 | tx_ring->tx_buffer_info[first].time_stamp = 0; |
| 5292 | tx_ring->next_to_use = first; |
| 5293 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5294 | |
| 5295 | return NETDEV_TX_OK; |
| 5296 | } |
| 5297 | |
| 5298 | /** |
| 5299 | * ixgbe_get_stats - Get System Network Statistics |
| 5300 | * @netdev: network interface device structure |
| 5301 | * |
| 5302 | * Returns the address of the device statistics structure. |
| 5303 | * The statistics are actually updated from the timer callback. |
| 5304 | **/ |
| 5305 | static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev) |
| 5306 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5307 | /* only return the current stats */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5308 | return &netdev->stats; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5309 | } |
| 5310 | |
| 5311 | /** |
| 5312 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 5313 | * @netdev: network interface device structure |
| 5314 | * @p: pointer to an address structure |
| 5315 | * |
| 5316 | * Returns 0 on success, negative on failure |
| 5317 | **/ |
| 5318 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 5319 | { |
| 5320 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5321 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5322 | struct sockaddr *addr = p; |
| 5323 | |
| 5324 | if (!is_valid_ether_addr(addr->sa_data)) |
| 5325 | return -EADDRNOTAVAIL; |
| 5326 | |
| 5327 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5328 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5329 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5330 | 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] | 5331 | |
| 5332 | return 0; |
| 5333 | } |
| 5334 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5335 | static int |
| 5336 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 5337 | { |
| 5338 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5339 | struct ixgbe_hw *hw = &adapter->hw; |
| 5340 | u16 value; |
| 5341 | int rc; |
| 5342 | |
| 5343 | if (prtad != hw->phy.mdio.prtad) |
| 5344 | return -EINVAL; |
| 5345 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 5346 | if (!rc) |
| 5347 | rc = value; |
| 5348 | return rc; |
| 5349 | } |
| 5350 | |
| 5351 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 5352 | u16 addr, u16 value) |
| 5353 | { |
| 5354 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5355 | struct ixgbe_hw *hw = &adapter->hw; |
| 5356 | |
| 5357 | if (prtad != hw->phy.mdio.prtad) |
| 5358 | return -EINVAL; |
| 5359 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 5360 | } |
| 5361 | |
| 5362 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 5363 | { |
| 5364 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5365 | |
| 5366 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 5367 | } |
| 5368 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5369 | /** |
| 5370 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5371 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5372 | * @netdev: network interface device structure |
| 5373 | * |
| 5374 | * Returns non-zero on failure |
| 5375 | **/ |
| 5376 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 5377 | { |
| 5378 | int err = 0; |
| 5379 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5380 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5381 | |
| 5382 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5383 | rtnl_lock(); |
| 5384 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5385 | rtnl_unlock(); |
| 5386 | } |
| 5387 | return err; |
| 5388 | } |
| 5389 | |
| 5390 | /** |
| 5391 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5392 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5393 | * @netdev: network interface device structure |
| 5394 | * |
| 5395 | * Returns non-zero on failure |
| 5396 | **/ |
| 5397 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 5398 | { |
| 5399 | int err = 0; |
| 5400 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5401 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5402 | |
| 5403 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5404 | rtnl_lock(); |
| 5405 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5406 | rtnl_unlock(); |
| 5407 | } |
| 5408 | return err; |
| 5409 | } |
| 5410 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5411 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5412 | /* |
| 5413 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5414 | * without having to re-enable interrupts. It's not called while |
| 5415 | * the interrupt routine is executing. |
| 5416 | */ |
| 5417 | static void ixgbe_netpoll(struct net_device *netdev) |
| 5418 | { |
| 5419 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 5420 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5421 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5422 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 5423 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 5424 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 5425 | for (i = 0; i < num_q_vectors; i++) { |
| 5426 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 5427 | ixgbe_msix_clean_many(0, q_vector); |
| 5428 | } |
| 5429 | } else { |
| 5430 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 5431 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5432 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5433 | } |
| 5434 | #endif |
| 5435 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5436 | static const struct net_device_ops ixgbe_netdev_ops = { |
| 5437 | .ndo_open = ixgbe_open, |
| 5438 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5439 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5440 | .ndo_select_queue = ixgbe_select_queue, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5441 | .ndo_get_stats = ixgbe_get_stats, |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 5442 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5443 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 5444 | .ndo_validate_addr = eth_validate_addr, |
| 5445 | .ndo_set_mac_address = ixgbe_set_mac, |
| 5446 | .ndo_change_mtu = ixgbe_change_mtu, |
| 5447 | .ndo_tx_timeout = ixgbe_tx_timeout, |
| 5448 | .ndo_vlan_rx_register = ixgbe_vlan_rx_register, |
| 5449 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 5450 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5451 | .ndo_do_ioctl = ixgbe_ioctl, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5452 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5453 | .ndo_poll_controller = ixgbe_netpoll, |
| 5454 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5455 | #ifdef IXGBE_FCOE |
| 5456 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
| 5457 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 5458 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 5459 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5460 | #endif /* IXGBE_FCOE */ |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5461 | }; |
| 5462 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5463 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5464 | * ixgbe_probe - Device Initialization Routine |
| 5465 | * @pdev: PCI device information struct |
| 5466 | * @ent: entry in ixgbe_pci_tbl |
| 5467 | * |
| 5468 | * Returns 0 on success, negative on failure |
| 5469 | * |
| 5470 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 5471 | * The OS initialization, configuring of the adapter private structure, |
| 5472 | * and a hardware reset occur. |
| 5473 | **/ |
| 5474 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5475 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5476 | { |
| 5477 | struct net_device *netdev; |
| 5478 | struct ixgbe_adapter *adapter = NULL; |
| 5479 | struct ixgbe_hw *hw; |
| 5480 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5481 | static int cards_found; |
| 5482 | int i, err, pci_using_dac; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5483 | #ifdef IXGBE_FCOE |
| 5484 | u16 device_caps; |
| 5485 | #endif |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5486 | u32 part_num, eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5487 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5488 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5489 | if (err) |
| 5490 | return err; |
| 5491 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 5492 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 5493 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5494 | pci_using_dac = 1; |
| 5495 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5496 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5497 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5498 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5499 | if (err) { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5500 | dev_err(&pdev->dev, "No usable DMA " |
| 5501 | "configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5502 | goto err_dma; |
| 5503 | } |
| 5504 | } |
| 5505 | pci_using_dac = 0; |
| 5506 | } |
| 5507 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5508 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 5509 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5510 | if (err) { |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5511 | dev_err(&pdev->dev, |
| 5512 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5513 | goto err_pci_reg; |
| 5514 | } |
| 5515 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 5516 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5517 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5518 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 5519 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5520 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5521 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5522 | if (!netdev) { |
| 5523 | err = -ENOMEM; |
| 5524 | goto err_alloc_etherdev; |
| 5525 | } |
| 5526 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5527 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 5528 | |
| 5529 | pci_set_drvdata(pdev, netdev); |
| 5530 | adapter = netdev_priv(netdev); |
| 5531 | |
| 5532 | adapter->netdev = netdev; |
| 5533 | adapter->pdev = pdev; |
| 5534 | hw = &adapter->hw; |
| 5535 | hw->back = adapter; |
| 5536 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 5537 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 5538 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 5539 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5540 | if (!hw->hw_addr) { |
| 5541 | err = -EIO; |
| 5542 | goto err_ioremap; |
| 5543 | } |
| 5544 | |
| 5545 | for (i = 1; i <= 5; i++) { |
| 5546 | if (pci_resource_len(pdev, i) == 0) |
| 5547 | continue; |
| 5548 | } |
| 5549 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5550 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5551 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5552 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5553 | strcpy(netdev->name, pci_name(pdev)); |
| 5554 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5555 | adapter->bd_number = cards_found; |
| 5556 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5557 | /* Setup hw api */ |
| 5558 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5559 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5560 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5561 | /* EEPROM */ |
| 5562 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 5563 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 5564 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 5565 | if (!(eec & (1 << 8))) |
| 5566 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 5567 | |
| 5568 | /* PHY */ |
| 5569 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5570 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5571 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 5572 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 5573 | hw->phy.mdio.mmds = 0; |
| 5574 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 5575 | hw->phy.mdio.dev = netdev; |
| 5576 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 5577 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5578 | |
| 5579 | /* set up this timer and work struct before calling get_invariants |
| 5580 | * which might start the timer |
| 5581 | */ |
| 5582 | init_timer(&adapter->sfp_timer); |
| 5583 | adapter->sfp_timer.function = &ixgbe_sfp_timer; |
| 5584 | adapter->sfp_timer.data = (unsigned long) adapter; |
| 5585 | |
| 5586 | INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5587 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5588 | /* multispeed fiber has its own tasklet, called from GPI SDP1 context */ |
| 5589 | INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task); |
| 5590 | |
| 5591 | /* a new SFP+ module arrival, called from GPI SDP2 context */ |
| 5592 | INIT_WORK(&adapter->sfp_config_module_task, |
| 5593 | ixgbe_sfp_config_module_task); |
| 5594 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5595 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5596 | |
| 5597 | /* setup the private structure */ |
| 5598 | err = ixgbe_sw_init(adapter); |
| 5599 | if (err) |
| 5600 | goto err_sw_init; |
| 5601 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5602 | /* |
| 5603 | * If there is a fan on this device and it has failed log the |
| 5604 | * failure. |
| 5605 | */ |
| 5606 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5607 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5608 | if (esdp & IXGBE_ESDP_SDP1) |
| 5609 | DPRINTK(PROBE, CRIT, |
| 5610 | "Fan has stopped, replace the adapter\n"); |
| 5611 | } |
| 5612 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5613 | /* reset_hw fills in the perm_addr as well */ |
| 5614 | err = hw->mac.ops.reset_hw(hw); |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5615 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 5616 | hw->mac.type == ixgbe_mac_82598EB) { |
| 5617 | /* |
| 5618 | * Start a kernel thread to watch for a module to arrive. |
| 5619 | * Only do this for 82598, since 82599 will generate |
| 5620 | * interrupts on module arrival. |
| 5621 | */ |
| 5622 | set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5623 | mod_timer(&adapter->sfp_timer, |
| 5624 | round_jiffies(jiffies + (2 * HZ))); |
| 5625 | err = 0; |
| 5626 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 5627 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 5628 | "an unsupported SFP+ module type was detected.\n" |
| 5629 | "Reload the driver after installing a supported " |
| 5630 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5631 | goto err_sw_init; |
| 5632 | } else if (err) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5633 | dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err); |
| 5634 | goto err_sw_init; |
| 5635 | } |
| 5636 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5637 | netdev->features = NETIF_F_SG | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5638 | NETIF_F_IP_CSUM | |
| 5639 | NETIF_F_HW_VLAN_TX | |
| 5640 | NETIF_F_HW_VLAN_RX | |
| 5641 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5642 | |
Jesse Brandeburg | e9990a9 | 2008-08-26 04:27:24 -0700 | [diff] [blame] | 5643 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5644 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5645 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 5646 | netdev->features |= NETIF_F_GRO; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5647 | |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5648 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 5649 | netdev->features |= NETIF_F_SCTP_CSUM; |
| 5650 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5651 | netdev->vlan_features |= NETIF_F_TSO; |
| 5652 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 5653 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 5654 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5655 | netdev->vlan_features |= NETIF_F_SG; |
| 5656 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5657 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 5658 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
| 5659 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5660 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5661 | netdev->dcbnl_ops = &dcbnl_ops; |
| 5662 | #endif |
| 5663 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5664 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5665 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5666 | if (hw->mac.ops.get_device_caps) { |
| 5667 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5668 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 5669 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5670 | } |
| 5671 | } |
| 5672 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5673 | if (pci_using_dac) |
| 5674 | netdev->features |= NETIF_F_HIGHDMA; |
| 5675 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5676 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5677 | netdev->features |= NETIF_F_LRO; |
| 5678 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5679 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5680 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5681 | dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); |
| 5682 | err = -EIO; |
| 5683 | goto err_eeprom; |
| 5684 | } |
| 5685 | |
| 5686 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5687 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5688 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5689 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
| 5690 | dev_err(&pdev->dev, "invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5691 | err = -EIO; |
| 5692 | goto err_eeprom; |
| 5693 | } |
| 5694 | |
| 5695 | init_timer(&adapter->watchdog_timer); |
| 5696 | adapter->watchdog_timer.function = &ixgbe_watchdog; |
| 5697 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 5698 | |
| 5699 | INIT_WORK(&adapter->reset_task, ixgbe_reset_task); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5700 | INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5701 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5702 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5703 | if (err) |
| 5704 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5705 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5706 | switch (pdev->device) { |
| 5707 | case IXGBE_DEV_ID_82599_KX4: |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5708 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
| 5709 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
Peter P Waskiewicz Jr | bdf0a55 | 2009-06-04 11:09:58 +0000 | [diff] [blame] | 5710 | /* Enable ACPI wakeup in GRC */ |
| 5711 | IXGBE_WRITE_REG(hw, IXGBE_GRC, |
| 5712 | (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5713 | break; |
| 5714 | default: |
| 5715 | adapter->wol = 0; |
| 5716 | break; |
| 5717 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5718 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 5719 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5720 | /* pick up the PCI bus settings for reporting later */ |
| 5721 | hw->mac.ops.get_bus_info(hw); |
| 5722 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5723 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5724 | dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n", |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5725 | ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s": |
| 5726 | (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"), |
| 5727 | ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" : |
| 5728 | (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" : |
| 5729 | (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" : |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5730 | "Unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5731 | netdev->dev_addr); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5732 | ixgbe_read_pba_num_generic(hw, &part_num); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5733 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 5734 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n", |
| 5735 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
| 5736 | (part_num >> 8), (part_num & 0xff)); |
| 5737 | else |
| 5738 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", |
| 5739 | hw->mac.type, hw->phy.type, |
| 5740 | (part_num >> 8), (part_num & 0xff)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5741 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5742 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5743 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5744 | "this card is not sufficient for optimal " |
| 5745 | "performance.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5746 | dev_warn(&pdev->dev, "For optimal performance a x8 " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5747 | "PCI-Express slot is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5748 | } |
| 5749 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 5750 | /* save off EEPROM version number */ |
| 5751 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 5752 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5753 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5754 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5755 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5756 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 5757 | /* We are running on a pre-production device, log a warning */ |
| 5758 | dev_warn(&pdev->dev, "This device is a pre-production " |
| 5759 | "adapter/LOM. Please be aware there may be issues " |
| 5760 | "associated with your hardware. If you are " |
| 5761 | "experiencing problems please contact your Intel or " |
| 5762 | "hardware representative who provided you with this " |
| 5763 | "hardware.\n"); |
| 5764 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5765 | strcpy(netdev->name, "eth%d"); |
| 5766 | err = register_netdev(netdev); |
| 5767 | if (err) |
| 5768 | goto err_register; |
| 5769 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5770 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 5771 | netif_carrier_off(netdev); |
| 5772 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5773 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5774 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5775 | INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task); |
| 5776 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5777 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 5778 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5779 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5780 | ixgbe_setup_dca(adapter); |
| 5781 | } |
| 5782 | #endif |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5783 | /* add san mac addr to netdev */ |
| 5784 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5785 | |
| 5786 | dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n"); |
| 5787 | cards_found++; |
| 5788 | return 0; |
| 5789 | |
| 5790 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5791 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5792 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5793 | err_sw_init: |
| 5794 | err_eeprom: |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5795 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5796 | del_timer_sync(&adapter->sfp_timer); |
| 5797 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5798 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5799 | cancel_work_sync(&adapter->sfp_config_module_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5800 | iounmap(hw->hw_addr); |
| 5801 | err_ioremap: |
| 5802 | free_netdev(netdev); |
| 5803 | err_alloc_etherdev: |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5804 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 5805 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5806 | err_pci_reg: |
| 5807 | err_dma: |
| 5808 | pci_disable_device(pdev); |
| 5809 | return err; |
| 5810 | } |
| 5811 | |
| 5812 | /** |
| 5813 | * ixgbe_remove - Device Removal Routine |
| 5814 | * @pdev: PCI device information struct |
| 5815 | * |
| 5816 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 5817 | * that it should release a PCI device. The could be caused by a |
| 5818 | * Hot-Plug event, or because the driver is going to be removed from |
| 5819 | * memory. |
| 5820 | **/ |
| 5821 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 5822 | { |
| 5823 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5824 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5825 | |
| 5826 | set_bit(__IXGBE_DOWN, &adapter->state); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5827 | /* clear the module not found bit to make sure the worker won't |
| 5828 | * reschedule |
| 5829 | */ |
| 5830 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5831 | del_timer_sync(&adapter->watchdog_timer); |
| 5832 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5833 | del_timer_sync(&adapter->sfp_timer); |
| 5834 | cancel_work_sync(&adapter->watchdog_task); |
| 5835 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5836 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5837 | cancel_work_sync(&adapter->sfp_config_module_task); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5838 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5839 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5840 | cancel_work_sync(&adapter->fdir_reinit_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5841 | flush_scheduled_work(); |
| 5842 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5843 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5844 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 5845 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 5846 | dca_remove_requester(&pdev->dev); |
| 5847 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 5848 | } |
| 5849 | |
| 5850 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5851 | #ifdef IXGBE_FCOE |
| 5852 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 5853 | ixgbe_cleanup_fcoe(adapter); |
| 5854 | |
| 5855 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5856 | |
| 5857 | /* remove the added san mac */ |
| 5858 | ixgbe_del_sanmac_netdev(netdev); |
| 5859 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5860 | if (netdev->reg_state == NETREG_REGISTERED) |
| 5861 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5862 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5863 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5864 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5865 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5866 | |
| 5867 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5868 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 5869 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5870 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5871 | DPRINTK(PROBE, INFO, "complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5872 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5873 | free_netdev(netdev); |
| 5874 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 5875 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5876 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5877 | pci_disable_device(pdev); |
| 5878 | } |
| 5879 | |
| 5880 | /** |
| 5881 | * ixgbe_io_error_detected - called when PCI error is detected |
| 5882 | * @pdev: Pointer to PCI device |
| 5883 | * @state: The current pci connection state |
| 5884 | * |
| 5885 | * This function is called after a PCI bus error affecting |
| 5886 | * this device has been detected. |
| 5887 | */ |
| 5888 | 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] | 5889 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5890 | { |
| 5891 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 5892 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5893 | |
| 5894 | netif_device_detach(netdev); |
| 5895 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 5896 | if (state == pci_channel_io_perm_failure) |
| 5897 | return PCI_ERS_RESULT_DISCONNECT; |
| 5898 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5899 | if (netif_running(netdev)) |
| 5900 | ixgbe_down(adapter); |
| 5901 | pci_disable_device(pdev); |
| 5902 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5903 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5904 | return PCI_ERS_RESULT_NEED_RESET; |
| 5905 | } |
| 5906 | |
| 5907 | /** |
| 5908 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 5909 | * @pdev: Pointer to PCI device |
| 5910 | * |
| 5911 | * Restart the card from scratch, as if from a cold-boot. |
| 5912 | */ |
| 5913 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 5914 | { |
| 5915 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 5916 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5917 | pci_ers_result_t result; |
| 5918 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5919 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5920 | if (pci_enable_device_mem(pdev)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5921 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5922 | "Cannot re-enable PCI device after reset.\n"); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5923 | result = PCI_ERS_RESULT_DISCONNECT; |
| 5924 | } else { |
| 5925 | pci_set_master(pdev); |
| 5926 | pci_restore_state(pdev); |
| 5927 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5928 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5929 | |
| 5930 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 5931 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5932 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5933 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5934 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5935 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 5936 | if (err) { |
| 5937 | dev_err(&pdev->dev, |
| 5938 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err); |
| 5939 | /* non-fatal, continue */ |
| 5940 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5941 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5942 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5943 | } |
| 5944 | |
| 5945 | /** |
| 5946 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 5947 | * @pdev: Pointer to PCI device |
| 5948 | * |
| 5949 | * This callback is called when the error recovery driver tells us that |
| 5950 | * its OK to resume normal operation. |
| 5951 | */ |
| 5952 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 5953 | { |
| 5954 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 5955 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5956 | |
| 5957 | if (netif_running(netdev)) { |
| 5958 | if (ixgbe_up(adapter)) { |
| 5959 | DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n"); |
| 5960 | return; |
| 5961 | } |
| 5962 | } |
| 5963 | |
| 5964 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | static struct pci_error_handlers ixgbe_err_handler = { |
| 5968 | .error_detected = ixgbe_io_error_detected, |
| 5969 | .slot_reset = ixgbe_io_slot_reset, |
| 5970 | .resume = ixgbe_io_resume, |
| 5971 | }; |
| 5972 | |
| 5973 | static struct pci_driver ixgbe_driver = { |
| 5974 | .name = ixgbe_driver_name, |
| 5975 | .id_table = ixgbe_pci_tbl, |
| 5976 | .probe = ixgbe_probe, |
| 5977 | .remove = __devexit_p(ixgbe_remove), |
| 5978 | #ifdef CONFIG_PM |
| 5979 | .suspend = ixgbe_suspend, |
| 5980 | .resume = ixgbe_resume, |
| 5981 | #endif |
| 5982 | .shutdown = ixgbe_shutdown, |
| 5983 | .err_handler = &ixgbe_err_handler |
| 5984 | }; |
| 5985 | |
| 5986 | /** |
| 5987 | * ixgbe_init_module - Driver Registration Routine |
| 5988 | * |
| 5989 | * ixgbe_init_module is the first routine called when the driver is |
| 5990 | * loaded. All it does is register with the PCI subsystem. |
| 5991 | **/ |
| 5992 | static int __init ixgbe_init_module(void) |
| 5993 | { |
| 5994 | int ret; |
| 5995 | printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name, |
| 5996 | ixgbe_driver_string, ixgbe_driver_version); |
| 5997 | |
| 5998 | printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright); |
| 5999 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6000 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6001 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6002 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6003 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6004 | ret = pci_register_driver(&ixgbe_driver); |
| 6005 | return ret; |
| 6006 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6007 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6008 | module_init(ixgbe_init_module); |
| 6009 | |
| 6010 | /** |
| 6011 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 6012 | * |
| 6013 | * ixgbe_exit_module is called just before the driver is removed |
| 6014 | * from memory. |
| 6015 | **/ |
| 6016 | static void __exit ixgbe_exit_module(void) |
| 6017 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6018 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6019 | dca_unregister_notify(&dca_notifier); |
| 6020 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6021 | pci_unregister_driver(&ixgbe_driver); |
| 6022 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6023 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6024 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6025 | 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] | 6026 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6027 | { |
| 6028 | int ret_val; |
| 6029 | |
| 6030 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6031 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6032 | |
| 6033 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 6034 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6035 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 6036 | #endif /* CONFIG_IXGBE_DCA */ |
| 6037 | #ifdef DEBUG |
| 6038 | /** |
| 6039 | * ixgbe_get_hw_dev_name - return device name string |
| 6040 | * used by hardware layer to print debugging information |
| 6041 | **/ |
| 6042 | char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw) |
| 6043 | { |
| 6044 | struct ixgbe_adapter *adapter = hw->back; |
| 6045 | return adapter->netdev->name; |
| 6046 | } |
| 6047 | |
| 6048 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6049 | module_exit(ixgbe_exit_module); |
| 6050 | |
| 6051 | /* ixgbe_main.c */ |