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