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> |
| 42 | |
| 43 | #include "ixgbe.h" |
| 44 | #include "ixgbe_common.h" |
| 45 | |
| 46 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 47 | static const char ixgbe_driver_string[] = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 48 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 49 | |
Peter P Waskiewicz Jr | 3efac5a | 2009-02-01 01:19:20 -0800 | [diff] [blame] | 50 | #define DRV_VERSION "1.3.56-k2" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 51 | const char ixgbe_driver_version[] = DRV_VERSION; |
Peter P Waskiewicz Jr | 3efac5a | 2009-02-01 01:19:20 -0800 | [diff] [blame] | 52 | static char ixgbe_copyright[] = "Copyright (c) 1999-2009 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 53 | |
| 54 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 55 | [board_82598] = &ixgbe_82598_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 59 | * |
| 60 | * Wildcard entries (PCI_ANY_ID) should come last |
| 61 | * Last entry must be all 0s |
| 62 | * |
| 63 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 64 | * Class, Class Mask, private data (not used) } |
| 65 | */ |
| 66 | static struct pci_device_id ixgbe_pci_tbl[] = { |
Don Skidmore | 1e336d0 | 2009-01-26 20:57:51 -0800 | [diff] [blame] | 67 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), |
| 68 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 69 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 70 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 71 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 72 | board_82598 }, |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 73 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), |
| 74 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 75 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 76 | board_82598 }, |
Jesse Brandeburg | 8d792cd | 2008-08-08 16:24:19 -0700 | [diff] [blame] | 77 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), |
| 78 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 79 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), |
| 80 | board_82598 }, |
| 81 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), |
| 82 | board_82598 }, |
Jesse Brandeburg | b95f5fc | 2008-09-11 19:58:59 -0700 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), |
| 84 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), |
| 86 | board_82598 }, |
Don Skidmore | 2f21bdd | 2009-02-01 01:18:23 -0800 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), |
| 88 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 89 | |
| 90 | /* required last entry */ |
| 91 | {0, } |
| 92 | }; |
| 93 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 94 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 95 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 96 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 97 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 98 | static struct notifier_block dca_notifier = { |
| 99 | .notifier_call = ixgbe_notify_dca, |
| 100 | .next = NULL, |
| 101 | .priority = 0 |
| 102 | }; |
| 103 | #endif |
| 104 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 105 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 106 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 107 | MODULE_LICENSE("GPL"); |
| 108 | MODULE_VERSION(DRV_VERSION); |
| 109 | |
| 110 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 111 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 112 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 113 | { |
| 114 | u32 ctrl_ext; |
| 115 | |
| 116 | /* Let firmware take over control of h/w */ |
| 117 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 118 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 119 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 123 | { |
| 124 | u32 ctrl_ext; |
| 125 | |
| 126 | /* Let firmware know the driver has taken over */ |
| 127 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 128 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 129 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 130 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 131 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 132 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, u16 int_alloc_entry, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 133 | u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 134 | { |
| 135 | u32 ivar, index; |
| 136 | |
| 137 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 138 | index = (int_alloc_entry >> 2) & 0x1F; |
| 139 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR(index)); |
| 140 | ivar &= ~(0xFF << (8 * (int_alloc_entry & 0x3))); |
| 141 | ivar |= (msix_vector << (8 * (int_alloc_entry & 0x3))); |
| 142 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR(index), ivar); |
| 143 | } |
| 144 | |
| 145 | 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] | 146 | struct ixgbe_tx_buffer |
| 147 | *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 148 | { |
| 149 | if (tx_buffer_info->dma) { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 150 | pci_unmap_page(adapter->pdev, tx_buffer_info->dma, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 151 | tx_buffer_info->length, PCI_DMA_TODEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 152 | tx_buffer_info->dma = 0; |
| 153 | } |
| 154 | if (tx_buffer_info->skb) { |
| 155 | dev_kfree_skb_any(tx_buffer_info->skb); |
| 156 | tx_buffer_info->skb = NULL; |
| 157 | } |
| 158 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 159 | } |
| 160 | |
| 161 | static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 162 | struct ixgbe_ring *tx_ring, |
| 163 | unsigned int eop) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 164 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 165 | struct ixgbe_hw *hw = &adapter->hw; |
| 166 | u32 head, tail; |
| 167 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 168 | /* Detect a transmit hang in hardware, this serializes the |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 169 | * check with the clearing of time_stamp and movement of eop */ |
| 170 | head = IXGBE_READ_REG(hw, tx_ring->head); |
| 171 | tail = IXGBE_READ_REG(hw, tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 172 | adapter->detect_tx_hung = false; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 173 | if ((head != tail) && |
| 174 | tx_ring->tx_buffer_info[eop].time_stamp && |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 175 | time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) && |
| 176 | !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) { |
| 177 | /* detected Tx unit hang */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 178 | union ixgbe_adv_tx_desc *tx_desc; |
| 179 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 180 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 181 | " Tx Queue <%d>\n" |
| 182 | " TDH, TDT <%x>, <%x>\n" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 183 | " next_to_use <%x>\n" |
| 184 | " next_to_clean <%x>\n" |
| 185 | "tx_buffer_info[next_to_clean]\n" |
| 186 | " time_stamp <%lx>\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 187 | " jiffies <%lx>\n", |
| 188 | tx_ring->queue_index, |
| 189 | head, tail, |
| 190 | tx_ring->next_to_use, eop, |
| 191 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 192 | return true; |
| 193 | } |
| 194 | |
| 195 | return false; |
| 196 | } |
| 197 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 198 | #define IXGBE_MAX_TXD_PWR 14 |
| 199 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 200 | |
| 201 | /* Tx Descriptors needed, worst case */ |
| 202 | #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \ |
| 203 | (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) |
| 204 | #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] | 205 | MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 206 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 207 | static void ixgbe_tx_timeout(struct net_device *netdev); |
| 208 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 209 | /** |
| 210 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
| 211 | * @adapter: board private structure |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 212 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 213 | **/ |
| 214 | static bool ixgbe_clean_tx_irq(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 215 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 216 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 217 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 218 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 219 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 220 | unsigned int i, eop, count = 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 221 | unsigned int total_bytes = 0, total_packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 222 | |
| 223 | i = tx_ring->next_to_clean; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 224 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 225 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 226 | |
| 227 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
| 228 | (count < tx_ring->count)) { |
| 229 | bool cleaned = false; |
| 230 | for ( ; !cleaned; count++) { |
| 231 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 232 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 233 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 234 | cleaned = (i == eop); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 235 | skb = tx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 236 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 237 | if (cleaned && skb) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 238 | unsigned int segs, bytecount; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 239 | |
| 240 | /* gso_segs is currently only valid for tcp */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 241 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
| 242 | /* multiply data chunks by size of headers */ |
| 243 | bytecount = ((segs - 1) * skb_headlen(skb)) + |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 244 | skb->len; |
| 245 | total_packets += segs; |
| 246 | total_bytes += bytecount; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 247 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 248 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 249 | ixgbe_unmap_and_free_tx_resource(adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 250 | tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 251 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 252 | tx_desc->wb.status = 0; |
| 253 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 254 | i++; |
| 255 | if (i == tx_ring->count) |
| 256 | i = 0; |
| 257 | } |
| 258 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 259 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 260 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 261 | } |
| 262 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 263 | tx_ring->next_to_clean = i; |
| 264 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 265 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 266 | if (unlikely(count && netif_carrier_ok(netdev) && |
| 267 | (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 268 | /* Make sure that anybody stopping the queue after this |
| 269 | * sees the new next_to_clean. |
| 270 | */ |
| 271 | smp_mb(); |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 272 | if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) && |
| 273 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 274 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 275 | ++adapter->restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 276 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 277 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 278 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 279 | if (adapter->detect_tx_hung) { |
| 280 | if (ixgbe_check_tx_hang(adapter, tx_ring, i)) { |
| 281 | /* schedule immediate reset if we believe we hung */ |
| 282 | DPRINTK(PROBE, INFO, |
| 283 | "tx hang %d detected, resetting adapter\n", |
| 284 | adapter->tx_timeout_count + 1); |
| 285 | ixgbe_tx_timeout(adapter->netdev); |
| 286 | } |
| 287 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 288 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 289 | /* re-arm the interrupt */ |
| 290 | if ((total_packets >= tx_ring->work_limit) || |
| 291 | (count == tx_ring->count)) |
| 292 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, tx_ring->v_idx); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 293 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 294 | tx_ring->total_bytes += total_bytes; |
| 295 | tx_ring->total_packets += total_packets; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 296 | tx_ring->stats.packets += total_packets; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 297 | tx_ring->stats.bytes += total_bytes; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 298 | adapter->net_stats.tx_bytes += total_bytes; |
| 299 | adapter->net_stats.tx_packets += total_packets; |
| 300 | return (total_packets ? true : false); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 303 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 304 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 305 | struct ixgbe_ring *rx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 306 | { |
| 307 | u32 rxctrl; |
| 308 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 309 | int q = rx_ring - adapter->rx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 310 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 311 | if (rx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 312 | rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q)); |
| 313 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 314 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 315 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 316 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
Don Skidmore | 15005a3 | 2009-01-19 16:54:13 -0800 | [diff] [blame] | 317 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
| 318 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | |
| 319 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 320 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 321 | rx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 322 | } |
| 323 | put_cpu(); |
| 324 | } |
| 325 | |
| 326 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 327 | struct ixgbe_ring *tx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 328 | { |
| 329 | u32 txctrl; |
| 330 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 331 | int q = tx_ring - adapter->tx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 332 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 333 | if (tx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 334 | txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q)); |
| 335 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 336 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 337 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 338 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 339 | tx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 340 | } |
| 341 | put_cpu(); |
| 342 | } |
| 343 | |
| 344 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 345 | { |
| 346 | int i; |
| 347 | |
| 348 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 349 | return; |
| 350 | |
| 351 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 352 | adapter->tx_ring[i].cpu = -1; |
| 353 | ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]); |
| 354 | } |
| 355 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 356 | adapter->rx_ring[i].cpu = -1; |
| 357 | ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 362 | { |
| 363 | struct net_device *netdev = dev_get_drvdata(dev); |
| 364 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 365 | unsigned long event = *(unsigned long *)data; |
| 366 | |
| 367 | switch (event) { |
| 368 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 369 | /* if we're already enabled, don't do it again */ |
| 370 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 371 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 372 | /* Always use CB2 mode, difference is masked |
| 373 | * in the CB driver. */ |
| 374 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 375 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 376 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 377 | ixgbe_setup_dca(adapter); |
| 378 | break; |
| 379 | } |
| 380 | /* Fall Through since DCA is disabled. */ |
| 381 | case DCA_PROVIDER_REMOVE: |
| 382 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 383 | dca_remove_requester(dev); |
| 384 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 385 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 386 | } |
| 387 | break; |
| 388 | } |
| 389 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 390 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 391 | } |
| 392 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 393 | #endif /* CONFIG_IXGBE_DCA */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 394 | /** |
| 395 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 396 | * @adapter: board private structure |
| 397 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 398 | * @status: hardware indication of status of receive |
| 399 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 400 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 401 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 402 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 403 | struct sk_buff *skb, u8 status, |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 404 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 405 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 406 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 407 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 408 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 409 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 410 | |
David S. Miller | 0c8dfc8 | 2009-01-27 16:22:32 -0800 | [diff] [blame] | 411 | skb_record_rx_queue(skb, q_vector - &adapter->q_vector[0]); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 412 | if (skb->ip_summed == CHECKSUM_UNNECESSARY) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 413 | if (adapter->vlgrp && is_vlan && (tag != 0)) |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 414 | vlan_gro_receive(napi, adapter->vlgrp, tag, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 415 | else |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 416 | napi_gro_receive(napi, skb); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 417 | } else { |
| 418 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 419 | if (adapter->vlgrp && is_vlan && (tag != 0)) |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 420 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, tag); |
| 421 | else |
| 422 | netif_receive_skb(skb); |
| 423 | } else { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 424 | if (adapter->vlgrp && is_vlan && (tag != 0)) |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 425 | vlan_hwaccel_rx(skb, adapter->vlgrp, tag); |
| 426 | else |
| 427 | netif_rx(skb); |
| 428 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 432 | /** |
| 433 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 434 | * @adapter: address of board private structure |
| 435 | * @status_err: hardware indication of status of receive |
| 436 | * @skb: skb currently being received and modified |
| 437 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 438 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 439 | u32 status_err, struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 440 | { |
| 441 | skb->ip_summed = CHECKSUM_NONE; |
| 442 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 443 | /* Rx csum disabled */ |
| 444 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 445 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 446 | |
| 447 | /* if IP and error */ |
| 448 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 449 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 450 | adapter->hw_csum_rx_error++; |
| 451 | return; |
| 452 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 453 | |
| 454 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 455 | return; |
| 456 | |
| 457 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
| 458 | adapter->hw_csum_rx_error++; |
| 459 | return; |
| 460 | } |
| 461 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 462 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 463 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 464 | adapter->hw_csum_rx_good++; |
| 465 | } |
| 466 | |
| 467 | /** |
| 468 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
| 469 | * @adapter: address of board private structure |
| 470 | **/ |
| 471 | static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 472 | struct ixgbe_ring *rx_ring, |
| 473 | int cleaned_count) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 474 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 475 | struct pci_dev *pdev = adapter->pdev; |
| 476 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 477 | struct ixgbe_rx_buffer *bi; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 478 | unsigned int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 479 | |
| 480 | i = rx_ring->next_to_use; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 481 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 482 | |
| 483 | while (cleaned_count--) { |
| 484 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 485 | |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 486 | if (!bi->page_dma && |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 487 | (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 488 | if (!bi->page) { |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 489 | bi->page = alloc_page(GFP_ATOMIC); |
| 490 | if (!bi->page) { |
| 491 | adapter->alloc_rx_page_failed++; |
| 492 | goto no_buffers; |
| 493 | } |
| 494 | bi->page_offset = 0; |
| 495 | } else { |
| 496 | /* use a half page if we're re-using */ |
| 497 | bi->page_offset ^= (PAGE_SIZE / 2); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 498 | } |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 499 | |
| 500 | bi->page_dma = pci_map_page(pdev, bi->page, |
| 501 | bi->page_offset, |
| 502 | (PAGE_SIZE / 2), |
| 503 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 506 | if (!bi->skb) { |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 507 | struct sk_buff *skb; |
| 508 | skb = netdev_alloc_skb(adapter->netdev, |
| 509 | (rx_ring->rx_buf_len + |
| 510 | NET_IP_ALIGN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 511 | |
| 512 | if (!skb) { |
| 513 | adapter->alloc_rx_buff_failed++; |
| 514 | goto no_buffers; |
| 515 | } |
| 516 | |
| 517 | /* |
| 518 | * Make buffer alignment 2 beyond a 16 byte boundary |
| 519 | * this will result in a 16 byte aligned IP header after |
| 520 | * the 14 byte MAC header is removed |
| 521 | */ |
| 522 | skb_reserve(skb, NET_IP_ALIGN); |
| 523 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 524 | bi->skb = skb; |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 525 | bi->dma = pci_map_single(pdev, skb->data, |
| 526 | rx_ring->rx_buf_len, |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 527 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 528 | } |
| 529 | /* Refresh the desc even if buffer_addrs didn't change because |
| 530 | * each write-back erases this info. */ |
| 531 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 532 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 533 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 534 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 535 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | i++; |
| 539 | if (i == rx_ring->count) |
| 540 | i = 0; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 541 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 542 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 543 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 544 | no_buffers: |
| 545 | if (rx_ring->next_to_use != i) { |
| 546 | rx_ring->next_to_use = i; |
| 547 | if (i-- == 0) |
| 548 | i = (rx_ring->count - 1); |
| 549 | |
| 550 | /* |
| 551 | * Force memory writes to complete before letting h/w |
| 552 | * know there are new descriptors to fetch. (Only |
| 553 | * applicable for weak-ordered memory model archs, |
| 554 | * such as IA-64). |
| 555 | */ |
| 556 | wmb(); |
| 557 | writel(i, adapter->hw.hw_addr + rx_ring->tail); |
| 558 | } |
| 559 | } |
| 560 | |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 561 | static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc) |
| 562 | { |
| 563 | return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 564 | } |
| 565 | |
| 566 | static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc) |
| 567 | { |
| 568 | return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 569 | } |
| 570 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 571 | 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] | 572 | struct ixgbe_ring *rx_ring, |
| 573 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 574 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 575 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 576 | struct pci_dev *pdev = adapter->pdev; |
| 577 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 578 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 579 | struct sk_buff *skb; |
| 580 | unsigned int i; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 581 | u32 len, staterr; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 582 | u16 hdr_info; |
| 583 | bool cleaned = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 584 | int cleaned_count = 0; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 585 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 586 | |
| 587 | i = rx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 588 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 589 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 590 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 591 | |
| 592 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 593 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 594 | if (*work_done >= work_to_do) |
| 595 | break; |
| 596 | (*work_done)++; |
| 597 | |
| 598 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 599 | hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc)); |
| 600 | len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 601 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 602 | if (hdr_info & IXGBE_RXDADV_SPH) |
| 603 | adapter->rx_hdr_split++; |
| 604 | if (len > IXGBE_RX_HDR_SIZE) |
| 605 | len = IXGBE_RX_HDR_SIZE; |
| 606 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 607 | } else { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 608 | len = le16_to_cpu(rx_desc->wb.upper.length); |
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 | |
| 611 | cleaned = true; |
| 612 | skb = rx_buffer_info->skb; |
| 613 | prefetch(skb->data - NET_IP_ALIGN); |
| 614 | rx_buffer_info->skb = NULL; |
| 615 | |
| 616 | if (len && !skb_shinfo(skb)->nr_frags) { |
| 617 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 618 | rx_ring->rx_buf_len, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 619 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 620 | skb_put(skb, len); |
| 621 | } |
| 622 | |
| 623 | if (upper_len) { |
| 624 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 625 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 626 | rx_buffer_info->page_dma = 0; |
| 627 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 628 | rx_buffer_info->page, |
| 629 | rx_buffer_info->page_offset, |
| 630 | upper_len); |
| 631 | |
| 632 | if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) || |
| 633 | (page_count(rx_buffer_info->page) != 1)) |
| 634 | rx_buffer_info->page = NULL; |
| 635 | else |
| 636 | get_page(rx_buffer_info->page); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 637 | |
| 638 | skb->len += upper_len; |
| 639 | skb->data_len += upper_len; |
| 640 | skb->truesize += upper_len; |
| 641 | } |
| 642 | |
| 643 | i++; |
| 644 | if (i == rx_ring->count) |
| 645 | i = 0; |
| 646 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 647 | |
| 648 | next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 649 | prefetch(next_rxd); |
| 650 | |
| 651 | cleaned_count++; |
| 652 | if (staterr & IXGBE_RXD_STAT_EOP) { |
| 653 | rx_ring->stats.packets++; |
| 654 | rx_ring->stats.bytes += skb->len; |
| 655 | } else { |
| 656 | rx_buffer_info->skb = next_buffer->skb; |
| 657 | rx_buffer_info->dma = next_buffer->dma; |
| 658 | next_buffer->skb = skb; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 659 | next_buffer->dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 660 | adapter->non_eop_descs++; |
| 661 | goto next_desc; |
| 662 | } |
| 663 | |
| 664 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { |
| 665 | dev_kfree_skb_irq(skb); |
| 666 | goto next_desc; |
| 667 | } |
| 668 | |
| 669 | ixgbe_rx_checksum(adapter, staterr, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 670 | |
| 671 | /* probably a little skewed due to removing CRC */ |
| 672 | total_rx_bytes += skb->len; |
| 673 | total_rx_packets++; |
| 674 | |
Jesse Brandeburg | 74ce8dd | 2008-09-11 20:03:23 -0700 | [diff] [blame] | 675 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 676 | ixgbe_receive_skb(q_vector, skb, staterr, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 677 | |
| 678 | next_desc: |
| 679 | rx_desc->wb.upper.status_error = 0; |
| 680 | |
| 681 | /* return some buffers to hardware, one at a time is too slow */ |
| 682 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 683 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 684 | cleaned_count = 0; |
| 685 | } |
| 686 | |
| 687 | /* use prefetched values */ |
| 688 | rx_desc = next_rxd; |
| 689 | rx_buffer_info = next_buffer; |
| 690 | |
| 691 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 694 | rx_ring->next_to_clean = i; |
| 695 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); |
| 696 | |
| 697 | if (cleaned_count) |
| 698 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 699 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 700 | rx_ring->total_packets += total_rx_packets; |
| 701 | rx_ring->total_bytes += total_rx_bytes; |
| 702 | adapter->net_stats.rx_bytes += total_rx_bytes; |
| 703 | adapter->net_stats.rx_packets += total_rx_packets; |
| 704 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 705 | return cleaned; |
| 706 | } |
| 707 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 708 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 709 | /** |
| 710 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 711 | * @adapter: board private structure |
| 712 | * |
| 713 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 714 | * interrupts. |
| 715 | **/ |
| 716 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 717 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 718 | struct ixgbe_q_vector *q_vector; |
| 719 | int i, j, q_vectors, v_idx, r_idx; |
| 720 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 721 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 722 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 723 | |
| 724 | /* Populate the IVAR table and set the ITR values to the |
| 725 | * corresponding register. |
| 726 | */ |
| 727 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
| 728 | q_vector = &adapter->q_vector[v_idx]; |
| 729 | /* XXX for_each_bit(...) */ |
| 730 | r_idx = find_first_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 731 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 732 | |
| 733 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 734 | j = adapter->rx_ring[r_idx].reg_idx; |
| 735 | ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(j), v_idx); |
| 736 | r_idx = find_next_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 737 | adapter->num_rx_queues, |
| 738 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 739 | } |
| 740 | r_idx = find_first_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 741 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 742 | |
| 743 | for (i = 0; i < q_vector->txr_count; i++) { |
| 744 | j = adapter->tx_ring[r_idx].reg_idx; |
| 745 | ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(j), v_idx); |
| 746 | r_idx = find_next_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 747 | adapter->num_tx_queues, |
| 748 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 749 | } |
| 750 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 751 | /* if this is a tx only vector halve the interrupt rate */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 752 | if (q_vector->txr_count && !q_vector->rxr_count) |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 753 | q_vector->eitr = (adapter->eitr_param >> 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 754 | else |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 755 | /* rx only */ |
| 756 | q_vector->eitr = adapter->eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 757 | |
| 758 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 759 | EITR_INTS_PER_SEC_TO_REG(q_vector->eitr)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 762 | ixgbe_set_ivar(adapter, IXGBE_IVAR_OTHER_CAUSES_INDEX, v_idx); |
| 763 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 764 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 765 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 766 | mask = IXGBE_EIMS_ENABLE_MASK; |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 767 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 768 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 771 | enum latency_range { |
| 772 | lowest_latency = 0, |
| 773 | low_latency = 1, |
| 774 | bulk_latency = 2, |
| 775 | latency_invalid = 255 |
| 776 | }; |
| 777 | |
| 778 | /** |
| 779 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
| 780 | * @adapter: pointer to adapter |
| 781 | * @eitr: eitr setting (ints per sec) to give last timeslice |
| 782 | * @itr_setting: current throttle rate in ints/second |
| 783 | * @packets: the number of packets during this measurement interval |
| 784 | * @bytes: the number of bytes during this measurement interval |
| 785 | * |
| 786 | * Stores a new ITR value based on packets and byte |
| 787 | * counts during the last interrupt. The advantage of per interrupt |
| 788 | * computation is faster updates and more accurate ITR for the current |
| 789 | * traffic pattern. Constants in this function were computed |
| 790 | * based on theoretical maximum wire speed and thresholds were set based |
| 791 | * on testing data as well as attempting to minimize response time |
| 792 | * while increasing bulk throughput. |
| 793 | * this functionality is controlled by the InterruptThrottleRate module |
| 794 | * parameter (see ixgbe_param.c) |
| 795 | **/ |
| 796 | static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 797 | u32 eitr, u8 itr_setting, |
| 798 | int packets, int bytes) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 799 | { |
| 800 | unsigned int retval = itr_setting; |
| 801 | u32 timepassed_us; |
| 802 | u64 bytes_perint; |
| 803 | |
| 804 | if (packets == 0) |
| 805 | goto update_itr_done; |
| 806 | |
| 807 | |
| 808 | /* simple throttlerate management |
| 809 | * 0-20MB/s lowest (100000 ints/s) |
| 810 | * 20-100MB/s low (20000 ints/s) |
| 811 | * 100-1249MB/s bulk (8000 ints/s) |
| 812 | */ |
| 813 | /* what was last interrupt timeslice? */ |
| 814 | timepassed_us = 1000000/eitr; |
| 815 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 816 | |
| 817 | switch (itr_setting) { |
| 818 | case lowest_latency: |
| 819 | if (bytes_perint > adapter->eitr_low) |
| 820 | retval = low_latency; |
| 821 | break; |
| 822 | case low_latency: |
| 823 | if (bytes_perint > adapter->eitr_high) |
| 824 | retval = bulk_latency; |
| 825 | else if (bytes_perint <= adapter->eitr_low) |
| 826 | retval = lowest_latency; |
| 827 | break; |
| 828 | case bulk_latency: |
| 829 | if (bytes_perint <= adapter->eitr_high) |
| 830 | retval = low_latency; |
| 831 | break; |
| 832 | } |
| 833 | |
| 834 | update_itr_done: |
| 835 | return retval; |
| 836 | } |
| 837 | |
| 838 | static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector) |
| 839 | { |
| 840 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 841 | struct ixgbe_hw *hw = &adapter->hw; |
| 842 | u32 new_itr; |
| 843 | u8 current_itr, ret_itr; |
| 844 | int i, r_idx, v_idx = ((void *)q_vector - (void *)(adapter->q_vector)) / |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 845 | sizeof(struct ixgbe_q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 846 | struct ixgbe_ring *rx_ring, *tx_ring; |
| 847 | |
| 848 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 849 | for (i = 0; i < q_vector->txr_count; i++) { |
| 850 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 851 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 852 | q_vector->tx_itr, |
| 853 | tx_ring->total_packets, |
| 854 | tx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 855 | /* if the result for this queue would decrease interrupt |
| 856 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 857 | q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 858 | q_vector->tx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 859 | 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] | 860 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 864 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 865 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 866 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 867 | q_vector->rx_itr, |
| 868 | rx_ring->total_packets, |
| 869 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 870 | /* if the result for this queue would decrease interrupt |
| 871 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 872 | q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 873 | q_vector->rx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 874 | 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] | 875 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 876 | } |
| 877 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 878 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 879 | |
| 880 | switch (current_itr) { |
| 881 | /* counts and packets in update_itr are dependent on these numbers */ |
| 882 | case lowest_latency: |
| 883 | new_itr = 100000; |
| 884 | break; |
| 885 | case low_latency: |
| 886 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 887 | break; |
| 888 | case bulk_latency: |
| 889 | default: |
| 890 | new_itr = 8000; |
| 891 | break; |
| 892 | } |
| 893 | |
| 894 | if (new_itr != q_vector->eitr) { |
| 895 | u32 itr_reg; |
| 896 | /* do an exponential smoothing */ |
| 897 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
| 898 | q_vector->eitr = new_itr; |
| 899 | itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr); |
| 900 | /* must write high and low 16 bits to reset counter */ |
| 901 | DPRINTK(TX_ERR, DEBUG, "writing eitr(%d): %08X\n", v_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 902 | itr_reg); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 903 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg | (itr_reg)<<16); |
| 904 | } |
| 905 | |
| 906 | return; |
| 907 | } |
| 908 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 909 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 910 | { |
| 911 | struct ixgbe_hw *hw = &adapter->hw; |
| 912 | |
| 913 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 914 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
| 915 | DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n"); |
| 916 | /* write to clear the interrupt */ |
| 917 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 918 | } |
| 919 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 920 | |
| 921 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 922 | { |
| 923 | struct ixgbe_hw *hw = &adapter->hw; |
| 924 | |
| 925 | adapter->lsc_int++; |
| 926 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 927 | adapter->link_check_timeout = jiffies; |
| 928 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 929 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
| 930 | schedule_work(&adapter->watchdog_task); |
| 931 | } |
| 932 | } |
| 933 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 934 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 935 | { |
| 936 | struct net_device *netdev = data; |
| 937 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 938 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame^] | 939 | u32 eicr; |
| 940 | |
| 941 | /* |
| 942 | * Workaround for Silicon errata. Use clear-by-write instead |
| 943 | * of clear-by-read. Reading with EICS will return the |
| 944 | * interrupt causes without clearing, which later be done |
| 945 | * with the write to EICR. |
| 946 | */ |
| 947 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 948 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 949 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 950 | if (eicr & IXGBE_EICR_LSC) |
| 951 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 952 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 953 | ixgbe_check_fan_failure(adapter, eicr); |
| 954 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 955 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 956 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 957 | |
| 958 | return IRQ_HANDLED; |
| 959 | } |
| 960 | |
| 961 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 962 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 963 | struct ixgbe_q_vector *q_vector = data; |
| 964 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 965 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 966 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 967 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 968 | if (!q_vector->txr_count) |
| 969 | return IRQ_HANDLED; |
| 970 | |
| 971 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 972 | for (i = 0; i < q_vector->txr_count; i++) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 973 | tx_ring = &(adapter->tx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 974 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 975 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 976 | ixgbe_update_tx_dca(adapter, tx_ring); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 977 | #endif |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 978 | tx_ring->total_bytes = 0; |
| 979 | tx_ring->total_packets = 0; |
| 980 | ixgbe_clean_tx_irq(adapter, tx_ring); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 981 | 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] | 982 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 983 | } |
| 984 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 985 | return IRQ_HANDLED; |
| 986 | } |
| 987 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 988 | /** |
| 989 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 990 | * @irq: unused |
| 991 | * @data: pointer to our q_vector struct for this interrupt vector |
| 992 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 993 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 994 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 995 | struct ixgbe_q_vector *q_vector = data; |
| 996 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 997 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 998 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 999 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1000 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1001 | 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] | 1002 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1003 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1004 | rx_ring->total_bytes = 0; |
| 1005 | rx_ring->total_packets = 0; |
| 1006 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1007 | r_idx + 1); |
| 1008 | } |
| 1009 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1010 | if (!q_vector->rxr_count) |
| 1011 | return IRQ_HANDLED; |
| 1012 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1013 | 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] | 1014 | rx_ring = &(adapter->rx_ring[r_idx]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1015 | /* disable interrupts on this vector only */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1016 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rx_ring->v_idx); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1017 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1018 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1019 | return IRQ_HANDLED; |
| 1020 | } |
| 1021 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1022 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 1023 | { |
| 1024 | ixgbe_msix_clean_rx(irq, data); |
| 1025 | ixgbe_msix_clean_tx(irq, data); |
| 1026 | |
| 1027 | return IRQ_HANDLED; |
| 1028 | } |
| 1029 | |
| 1030 | /** |
| 1031 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 1032 | * @napi: napi struct with our devices info in it |
| 1033 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1034 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1035 | * This function is optimized for cleaning one queue only on a single |
| 1036 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1037 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1038 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 1039 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1040 | struct ixgbe_q_vector *q_vector = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1041 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1042 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1043 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1044 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1045 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1046 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1047 | 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] | 1048 | rx_ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1049 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1050 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1051 | ixgbe_update_rx_dca(adapter, rx_ring); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1052 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1053 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1054 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1055 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1056 | /* If all Rx work done, exit the polling mode */ |
| 1057 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1058 | napi_complete(napi); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1059 | if (adapter->itr_setting & 3) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1060 | ixgbe_set_itr_msix(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1061 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1062 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rx_ring->v_idx); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | return work_done; |
| 1066 | } |
| 1067 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1068 | /** |
| 1069 | * ixgbe_clean_rxonly_many - msix (aka one shot) rx clean routine |
| 1070 | * @napi: napi struct with our devices info in it |
| 1071 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1072 | * |
| 1073 | * This function will clean more than one rx queue associated with a |
| 1074 | * q_vector. |
| 1075 | **/ |
| 1076 | static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget) |
| 1077 | { |
| 1078 | struct ixgbe_q_vector *q_vector = |
| 1079 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1080 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1081 | struct ixgbe_ring *rx_ring = NULL; |
| 1082 | int work_done = 0, i; |
| 1083 | long r_idx; |
| 1084 | u16 enable_mask = 0; |
| 1085 | |
| 1086 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 1087 | * the budget to go below 1 because we'll exit polling */ |
| 1088 | budget /= (q_vector->rxr_count ?: 1); |
| 1089 | budget = max(budget, 1); |
| 1090 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1091 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1092 | rx_ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1093 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1094 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1095 | ixgbe_update_rx_dca(adapter, rx_ring); |
| 1096 | #endif |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1097 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1098 | enable_mask |= rx_ring->v_idx; |
| 1099 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1100 | r_idx + 1); |
| 1101 | } |
| 1102 | |
| 1103 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1104 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1105 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 1106 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1107 | napi_complete(napi); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1108 | if (adapter->itr_setting & 3) |
| 1109 | ixgbe_set_itr_msix(q_vector); |
| 1110 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1111 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, enable_mask); |
| 1112 | return 0; |
| 1113 | } |
| 1114 | |
| 1115 | return work_done; |
| 1116 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1117 | 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] | 1118 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1119 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1120 | a->q_vector[v_idx].adapter = a; |
| 1121 | set_bit(r_idx, a->q_vector[v_idx].rxr_idx); |
| 1122 | a->q_vector[v_idx].rxr_count++; |
| 1123 | a->rx_ring[r_idx].v_idx = 1 << v_idx; |
| 1124 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1125 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1126 | static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1127 | int r_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1128 | { |
| 1129 | a->q_vector[v_idx].adapter = a; |
| 1130 | set_bit(r_idx, a->q_vector[v_idx].txr_idx); |
| 1131 | a->q_vector[v_idx].txr_count++; |
| 1132 | a->tx_ring[r_idx].v_idx = 1 << v_idx; |
| 1133 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1134 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1135 | /** |
| 1136 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 1137 | * @adapter: board private structure to initialize |
| 1138 | * @vectors: allotted vector count for descriptor rings |
| 1139 | * |
| 1140 | * This function maps descriptor rings to the queue-specific vectors |
| 1141 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 1142 | * one vector per ring/queue, but on a constrained vector budget, we |
| 1143 | * group the rings as "efficiently" as possible. You would add new |
| 1144 | * mapping configurations in here. |
| 1145 | **/ |
| 1146 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1147 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1148 | { |
| 1149 | int v_start = 0; |
| 1150 | int rxr_idx = 0, txr_idx = 0; |
| 1151 | int rxr_remaining = adapter->num_rx_queues; |
| 1152 | int txr_remaining = adapter->num_tx_queues; |
| 1153 | int i, j; |
| 1154 | int rqpv, tqpv; |
| 1155 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1156 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1157 | /* No mapping required if MSI-X is disabled. */ |
| 1158 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1159 | goto out; |
| 1160 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1161 | /* |
| 1162 | * The ideal configuration... |
| 1163 | * We have enough vectors to map one per queue. |
| 1164 | */ |
| 1165 | if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
| 1166 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 1167 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 1168 | |
| 1169 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 1170 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 1171 | |
| 1172 | goto out; |
| 1173 | } |
| 1174 | |
| 1175 | /* |
| 1176 | * If we don't have enough vectors for a 1-to-1 |
| 1177 | * mapping, we'll have to group them so there are |
| 1178 | * multiple queues per vector. |
| 1179 | */ |
| 1180 | /* Re-adjusting *qpv takes care of the remainder. */ |
| 1181 | for (i = v_start; i < vectors; i++) { |
| 1182 | rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i); |
| 1183 | for (j = 0; j < rqpv; j++) { |
| 1184 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 1185 | rxr_idx++; |
| 1186 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1187 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1188 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1189 | for (i = v_start; i < vectors; i++) { |
| 1190 | tqpv = DIV_ROUND_UP(txr_remaining, vectors - i); |
| 1191 | for (j = 0; j < tqpv; j++) { |
| 1192 | map_vector_to_txq(adapter, i, txr_idx); |
| 1193 | txr_idx++; |
| 1194 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1195 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1198 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1199 | return err; |
| 1200 | } |
| 1201 | |
| 1202 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1203 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 1204 | * @adapter: board private structure |
| 1205 | * |
| 1206 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 1207 | * interrupts from the kernel. |
| 1208 | **/ |
| 1209 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 1210 | { |
| 1211 | struct net_device *netdev = adapter->netdev; |
| 1212 | irqreturn_t (*handler)(int, void *); |
| 1213 | int i, vector, q_vectors, err; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1214 | int ri=0, ti=0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1215 | |
| 1216 | /* Decrement for Other and TCP Timer vectors */ |
| 1217 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1218 | |
| 1219 | /* Map the Tx/Rx rings to the vectors we were allotted. */ |
| 1220 | err = ixgbe_map_rings_to_vectors(adapter, q_vectors); |
| 1221 | if (err) |
| 1222 | goto out; |
| 1223 | |
| 1224 | #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1225 | (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \ |
| 1226 | &ixgbe_msix_clean_many) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1227 | for (vector = 0; vector < q_vectors; vector++) { |
| 1228 | handler = SET_HANDLER(&adapter->q_vector[vector]); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1229 | |
| 1230 | if(handler == &ixgbe_msix_clean_rx) { |
| 1231 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1232 | netdev->name, "rx", ri++); |
| 1233 | } |
| 1234 | else if(handler == &ixgbe_msix_clean_tx) { |
| 1235 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1236 | netdev->name, "tx", ti++); |
| 1237 | } |
| 1238 | else |
| 1239 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1240 | netdev->name, "TxRx", vector); |
| 1241 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1242 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1243 | handler, 0, adapter->name[vector], |
| 1244 | &(adapter->q_vector[vector])); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1245 | if (err) { |
| 1246 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1247 | "request_irq failed for MSIX interrupt " |
| 1248 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1249 | goto free_queue_irqs; |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | sprintf(adapter->name[vector], "%s:lsc", netdev->name); |
| 1254 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1255 | &ixgbe_msix_lsc, 0, adapter->name[vector], netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1256 | if (err) { |
| 1257 | DPRINTK(PROBE, ERR, |
| 1258 | "request_irq for msix_lsc failed: %d\n", err); |
| 1259 | goto free_queue_irqs; |
| 1260 | } |
| 1261 | |
| 1262 | return 0; |
| 1263 | |
| 1264 | free_queue_irqs: |
| 1265 | for (i = vector - 1; i >= 0; i--) |
| 1266 | free_irq(adapter->msix_entries[--vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1267 | &(adapter->q_vector[i])); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1268 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 1269 | pci_disable_msix(adapter->pdev); |
| 1270 | kfree(adapter->msix_entries); |
| 1271 | adapter->msix_entries = NULL; |
| 1272 | out: |
| 1273 | return err; |
| 1274 | } |
| 1275 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1276 | static void ixgbe_set_itr(struct ixgbe_adapter *adapter) |
| 1277 | { |
| 1278 | struct ixgbe_hw *hw = &adapter->hw; |
| 1279 | struct ixgbe_q_vector *q_vector = adapter->q_vector; |
| 1280 | u8 current_itr; |
| 1281 | u32 new_itr = q_vector->eitr; |
| 1282 | struct ixgbe_ring *rx_ring = &adapter->rx_ring[0]; |
| 1283 | struct ixgbe_ring *tx_ring = &adapter->tx_ring[0]; |
| 1284 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1285 | q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1286 | q_vector->tx_itr, |
| 1287 | tx_ring->total_packets, |
| 1288 | tx_ring->total_bytes); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1289 | q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1290 | q_vector->rx_itr, |
| 1291 | rx_ring->total_packets, |
| 1292 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1293 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1294 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1295 | |
| 1296 | switch (current_itr) { |
| 1297 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1298 | case lowest_latency: |
| 1299 | new_itr = 100000; |
| 1300 | break; |
| 1301 | case low_latency: |
| 1302 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1303 | break; |
| 1304 | case bulk_latency: |
| 1305 | new_itr = 8000; |
| 1306 | break; |
| 1307 | default: |
| 1308 | break; |
| 1309 | } |
| 1310 | |
| 1311 | if (new_itr != q_vector->eitr) { |
| 1312 | u32 itr_reg; |
| 1313 | /* do an exponential smoothing */ |
| 1314 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
| 1315 | q_vector->eitr = new_itr; |
| 1316 | itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr); |
| 1317 | /* must write high and low 16 bits to reset counter */ |
| 1318 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), itr_reg | (itr_reg)<<16); |
| 1319 | } |
| 1320 | |
| 1321 | return; |
| 1322 | } |
| 1323 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1324 | /** |
| 1325 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 1326 | * @adapter: board private structure |
| 1327 | **/ |
| 1328 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 1329 | { |
| 1330 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
| 1331 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1332 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1333 | int i; |
| 1334 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 1335 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1336 | } else { |
| 1337 | synchronize_irq(adapter->pdev->irq); |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | /** |
| 1342 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 1343 | * @adapter: board private structure |
| 1344 | **/ |
| 1345 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter) |
| 1346 | { |
| 1347 | u32 mask; |
| 1348 | mask = IXGBE_EIMS_ENABLE_MASK; |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 1349 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 1350 | mask |= IXGBE_EIMS_GPI_SDP1; |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1351 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 1352 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1353 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1354 | |
| 1355 | /** |
| 1356 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1357 | * @irq: interrupt number |
| 1358 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1359 | **/ |
| 1360 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 1361 | { |
| 1362 | struct net_device *netdev = data; |
| 1363 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1364 | struct ixgbe_hw *hw = &adapter->hw; |
| 1365 | u32 eicr; |
| 1366 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame^] | 1367 | /* |
| 1368 | * Workaround for silicon errata. Mask the interrupts |
| 1369 | * before the read of EICR. |
| 1370 | */ |
| 1371 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 1372 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1373 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 1374 | * therefore no explict interrupt disable is necessary */ |
| 1375 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1376 | if (!eicr) { |
| 1377 | /* shared interrupt alert! |
| 1378 | * make sure interrupts are enabled because the read will |
| 1379 | * have disabled interrupts due to EIAM */ |
| 1380 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1381 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1382 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1383 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1384 | if (eicr & IXGBE_EICR_LSC) |
| 1385 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1386 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1387 | ixgbe_check_fan_failure(adapter, eicr); |
| 1388 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1389 | if (napi_schedule_prep(&adapter->q_vector[0].napi)) { |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1390 | adapter->tx_ring[0].total_packets = 0; |
| 1391 | adapter->tx_ring[0].total_bytes = 0; |
| 1392 | adapter->rx_ring[0].total_packets = 0; |
| 1393 | adapter->rx_ring[0].total_bytes = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1394 | /* would disable interrupts here but EIAM disabled it */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1395 | __napi_schedule(&adapter->q_vector[0].napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | return IRQ_HANDLED; |
| 1399 | } |
| 1400 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1401 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 1402 | { |
| 1403 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1404 | |
| 1405 | for (i = 0; i < q_vectors; i++) { |
| 1406 | struct ixgbe_q_vector *q_vector = &adapter->q_vector[i]; |
| 1407 | bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES); |
| 1408 | bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES); |
| 1409 | q_vector->rxr_count = 0; |
| 1410 | q_vector->txr_count = 0; |
| 1411 | } |
| 1412 | } |
| 1413 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1414 | /** |
| 1415 | * ixgbe_request_irq - initialize interrupts |
| 1416 | * @adapter: board private structure |
| 1417 | * |
| 1418 | * Attempts to configure interrupts using the best available |
| 1419 | * capabilities of the hardware and kernel. |
| 1420 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1421 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1422 | { |
| 1423 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1424 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1425 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1426 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1427 | err = ixgbe_request_msix_irqs(adapter); |
| 1428 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 1429 | err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1430 | netdev->name, netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1431 | } else { |
| 1432 | err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1433 | netdev->name, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1436 | if (err) |
| 1437 | DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err); |
| 1438 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1439 | return err; |
| 1440 | } |
| 1441 | |
| 1442 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 1443 | { |
| 1444 | struct net_device *netdev = adapter->netdev; |
| 1445 | |
| 1446 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1447 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1448 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1449 | q_vectors = adapter->num_msix_vectors; |
| 1450 | |
| 1451 | i = q_vectors - 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1452 | free_irq(adapter->msix_entries[i].vector, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1453 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1454 | i--; |
| 1455 | for (; i >= 0; i--) { |
| 1456 | free_irq(adapter->msix_entries[i].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1457 | &(adapter->q_vector[i])); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | ixgbe_reset_q_vectors(adapter); |
| 1461 | } else { |
| 1462 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1463 | } |
| 1464 | } |
| 1465 | |
| 1466 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1467 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 1468 | * |
| 1469 | **/ |
| 1470 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 1471 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1472 | struct ixgbe_hw *hw = &adapter->hw; |
| 1473 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1474 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1475 | EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1476 | |
| 1477 | ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(0), 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1478 | ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(0), 0); |
| 1479 | |
| 1480 | map_vector_to_rxq(adapter, 0, 0); |
| 1481 | map_vector_to_txq(adapter, 0, 0); |
| 1482 | |
| 1483 | DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1487 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1488 | * @adapter: board private structure |
| 1489 | * |
| 1490 | * Configure the Tx unit of the MAC after a reset. |
| 1491 | **/ |
| 1492 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 1493 | { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1494 | u64 tdba; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1495 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1496 | u32 i, j, tdlen, txctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1497 | |
| 1498 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1499 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1500 | struct ixgbe_ring *ring = &adapter->tx_ring[i]; |
| 1501 | j = ring->reg_idx; |
| 1502 | tdba = ring->dma; |
| 1503 | tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1504 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j), |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1505 | (tdba & DMA_32BIT_MASK)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1506 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32)); |
| 1507 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen); |
| 1508 | IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0); |
| 1509 | IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0); |
| 1510 | adapter->tx_ring[i].head = IXGBE_TDH(j); |
| 1511 | adapter->tx_ring[i].tail = IXGBE_TDT(j); |
| 1512 | /* Disable Tx Head Writeback RO bit, since this hoses |
| 1513 | * bookkeeping if things aren't delivered in order. |
| 1514 | */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1515 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1516 | txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1517 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1518 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1521 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1522 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1523 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index) |
| 1524 | { |
| 1525 | struct ixgbe_ring *rx_ring; |
| 1526 | u32 srrctl; |
| 1527 | int queue0; |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1528 | unsigned long mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1529 | |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1530 | /* program one srrctl register per VMDq index */ |
| 1531 | if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) { |
| 1532 | long shift, len; |
| 1533 | mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask; |
| 1534 | len = sizeof(adapter->ring_feature[RING_F_VMDQ].mask) * 8; |
| 1535 | shift = find_first_bit(&mask, len); |
| 1536 | queue0 = index & mask; |
| 1537 | index = (index & mask) >> shift; |
| 1538 | /* program one srrctl per RSS queue since RDRXCTL.MVMEN is enabled */ |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1539 | } else { |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1540 | mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask; |
| 1541 | queue0 = index & mask; |
| 1542 | index = index & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1543 | } |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1544 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1545 | rx_ring = &adapter->rx_ring[queue0]; |
| 1546 | |
| 1547 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index)); |
| 1548 | |
| 1549 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 1550 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
| 1551 | |
| 1552 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
| 1553 | srrctl |= IXGBE_RXBUFFER_2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1554 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
| 1555 | srrctl |= ((IXGBE_RX_HDR_SIZE << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1556 | IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 1557 | IXGBE_SRRCTL_BSIZEHDR_MASK); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1558 | } else { |
| 1559 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
| 1560 | |
| 1561 | if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE) |
| 1562 | srrctl |= IXGBE_RXBUFFER_2048 >> |
| 1563 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1564 | else |
| 1565 | srrctl |= rx_ring->rx_buf_len >> |
| 1566 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1567 | } |
| 1568 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl); |
| 1569 | } |
| 1570 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1571 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1572 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1573 | * @adapter: board private structure |
| 1574 | * |
| 1575 | * Configure the Rx unit of the MAC after a reset. |
| 1576 | **/ |
| 1577 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 1578 | { |
| 1579 | u64 rdba; |
| 1580 | struct ixgbe_hw *hw = &adapter->hw; |
| 1581 | struct net_device *netdev = adapter->netdev; |
| 1582 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1583 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1584 | u32 rdlen, rxctrl, rxcsum; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1585 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
| 1586 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 1587 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1588 | u32 fctrl, hlreg0; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1589 | u32 reta = 0, mrqc; |
| 1590 | u32 rdrxctl; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1591 | int rx_buf_len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1592 | |
| 1593 | /* Decide whether to use packet split mode or not */ |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 1594 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1595 | |
| 1596 | /* Set the RX buffer length according to the mode */ |
| 1597 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1598 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1599 | } else { |
| 1600 | if (netdev->mtu <= ETH_DATA_LEN) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1601 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1602 | else |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1603 | rx_buf_len = ALIGN(max_frame, 1024); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); |
| 1607 | fctrl |= IXGBE_FCTRL_BAM; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1608 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1609 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl); |
| 1610 | |
| 1611 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
| 1612 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 1613 | hlreg0 &= ~IXGBE_HLREG0_JUMBOEN; |
| 1614 | else |
| 1615 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
| 1616 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 1617 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1618 | rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc); |
| 1619 | /* disable receives while setting up the descriptors */ |
| 1620 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 1621 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 1622 | |
| 1623 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 1624 | * the Base and Length of the Rx Descriptor Ring */ |
| 1625 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 1626 | rdba = adapter->rx_ring[i].dma; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1627 | j = adapter->rx_ring[i].reg_idx; |
| 1628 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_32BIT_MASK)); |
| 1629 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32)); |
| 1630 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen); |
| 1631 | IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0); |
| 1632 | IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0); |
| 1633 | adapter->rx_ring[i].head = IXGBE_RDH(j); |
| 1634 | adapter->rx_ring[i].tail = IXGBE_RDT(j); |
| 1635 | adapter->rx_ring[i].rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1636 | |
| 1637 | ixgbe_configure_srrctl(adapter, j); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1638 | } |
| 1639 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1640 | /* |
| 1641 | * For VMDq support of different descriptor types or |
| 1642 | * buffer sizes through the use of multiple SRRCTL |
| 1643 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 1644 | * |
| 1645 | * also, the manual doesn't mention it clearly but DCA hints |
| 1646 | * will only use queue 0's tags unless this bit is set. Side |
| 1647 | * effects of setting this bit are only that SRRCTL must be |
| 1648 | * fully programmed [0..15] |
| 1649 | */ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1650 | if (adapter->flags & |
| 1651 | (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_VMDQ_ENABLED)) { |
| 1652 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 1653 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 1654 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 1655 | } |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1656 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1657 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1658 | /* Fill out redirection table */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1659 | for (i = 0, j = 0; i < 128; i++, j++) { |
| 1660 | if (j == adapter->ring_feature[RING_F_RSS].indices) |
| 1661 | j = 0; |
| 1662 | /* reta = 4-byte sliding window of |
| 1663 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 1664 | reta = (reta << 8) | (j * 0x11); |
| 1665 | if ((i & 3) == 3) |
| 1666 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | /* Fill out hash function seeds */ |
| 1670 | for (i = 0; i < 10; i++) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1671 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1672 | |
| 1673 | mrqc = IXGBE_MRQC_RSSEN |
| 1674 | /* Perform hash on these packet types */ |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1675 | | IXGBE_MRQC_RSS_FIELD_IPV4 |
| 1676 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 1677 | | IXGBE_MRQC_RSS_FIELD_IPV4_UDP |
| 1678 | | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP |
| 1679 | | IXGBE_MRQC_RSS_FIELD_IPV6_EX |
| 1680 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 1681 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP |
| 1682 | | IXGBE_MRQC_RSS_FIELD_IPV6_UDP |
| 1683 | | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1684 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1685 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1686 | |
| 1687 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 1688 | |
| 1689 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED || |
| 1690 | adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) { |
| 1691 | /* Disable indicating checksum in descriptor, enables |
| 1692 | * RSS hash */ |
| 1693 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 1694 | } |
| 1695 | if (!(rxcsum & IXGBE_RXCSUM_PCSD)) { |
| 1696 | /* Enable IPv4 payload checksum for UDP fragments |
| 1697 | * if PCSD is not set */ |
| 1698 | rxcsum |= IXGBE_RXCSUM_IPPCSE; |
| 1699 | } |
| 1700 | |
| 1701 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1702 | } |
| 1703 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1704 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 1705 | { |
| 1706 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1707 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1708 | |
| 1709 | /* add VID to filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1710 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 1714 | { |
| 1715 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1716 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1717 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1718 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1719 | ixgbe_irq_disable(adapter); |
| 1720 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1721 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1722 | |
| 1723 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1724 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1725 | |
| 1726 | /* remove VID from filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1727 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 1730 | static void ixgbe_vlan_rx_register(struct net_device *netdev, |
| 1731 | struct vlan_group *grp) |
| 1732 | { |
| 1733 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1734 | u32 ctrl; |
| 1735 | |
| 1736 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1737 | ixgbe_irq_disable(adapter); |
| 1738 | adapter->vlgrp = grp; |
| 1739 | |
| 1740 | /* |
| 1741 | * For a DCB driver, always enable VLAN tag stripping so we can |
| 1742 | * still receive traffic from a DCB-enabled host even if we're |
| 1743 | * not in DCB mode. |
| 1744 | */ |
| 1745 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
| 1746 | ctrl |= IXGBE_VLNCTRL_VME; |
| 1747 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 1748 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
| 1749 | ixgbe_vlan_rx_add_vid(netdev, 0); |
| 1750 | |
| 1751 | if (grp) { |
| 1752 | /* enable VLAN tag insert/strip */ |
| 1753 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
| 1754 | ctrl |= IXGBE_VLNCTRL_VME; |
| 1755 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 1756 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
| 1757 | } |
| 1758 | |
| 1759 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1760 | ixgbe_irq_enable(adapter); |
| 1761 | } |
| 1762 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1763 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 1764 | { |
| 1765 | ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 1766 | |
| 1767 | if (adapter->vlgrp) { |
| 1768 | u16 vid; |
| 1769 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 1770 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 1771 | continue; |
| 1772 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
| 1773 | } |
| 1774 | } |
| 1775 | } |
| 1776 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1777 | static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq) |
| 1778 | { |
| 1779 | struct dev_mc_list *mc_ptr; |
| 1780 | u8 *addr = *mc_addr_ptr; |
| 1781 | *vmdq = 0; |
| 1782 | |
| 1783 | mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]); |
| 1784 | if (mc_ptr->next) |
| 1785 | *mc_addr_ptr = mc_ptr->next->dmi_addr; |
| 1786 | else |
| 1787 | *mc_addr_ptr = NULL; |
| 1788 | |
| 1789 | return addr; |
| 1790 | } |
| 1791 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1792 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1793 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1794 | * @netdev: network interface device structure |
| 1795 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1796 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 1797 | * address list or the network interface flags are updated. This routine is |
| 1798 | * responsible for configuring the hardware for proper unicast, multicast and |
| 1799 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1800 | **/ |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1801 | static void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1802 | { |
| 1803 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1804 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 1805 | u32 fctrl, vlnctrl; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1806 | u8 *addr_list = NULL; |
| 1807 | int addr_count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1808 | |
| 1809 | /* Check for Promiscuous and All Multicast modes */ |
| 1810 | |
| 1811 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 1812 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1813 | |
| 1814 | if (netdev->flags & IFF_PROMISC) { |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1815 | hw->addr_ctrl.user_set_promisc = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1816 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 1817 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1818 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 1819 | if (netdev->flags & IFF_ALLMULTI) { |
| 1820 | fctrl |= IXGBE_FCTRL_MPE; |
| 1821 | fctrl &= ~IXGBE_FCTRL_UPE; |
| 1822 | } else { |
| 1823 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 1824 | } |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 1825 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1826 | hw->addr_ctrl.user_set_promisc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 1830 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1831 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1832 | /* reprogram secondary unicast list */ |
| 1833 | addr_count = netdev->uc_count; |
| 1834 | if (addr_count) |
| 1835 | addr_list = netdev->uc_list->dmi_addr; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1836 | hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count, |
| 1837 | ixgbe_addr_list_itr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1838 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1839 | /* reprogram multicast list */ |
| 1840 | addr_count = netdev->mc_count; |
| 1841 | if (addr_count) |
| 1842 | addr_list = netdev->mc_list->dmi_addr; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1843 | hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count, |
| 1844 | ixgbe_addr_list_itr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1847 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 1848 | { |
| 1849 | int q_idx; |
| 1850 | struct ixgbe_q_vector *q_vector; |
| 1851 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1852 | |
| 1853 | /* legacy and MSI only use one vector */ |
| 1854 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 1855 | q_vectors = 1; |
| 1856 | |
| 1857 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1858 | struct napi_struct *napi; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1859 | q_vector = &adapter->q_vector[q_idx]; |
| 1860 | if (!q_vector->rxr_count) |
| 1861 | continue; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1862 | napi = &q_vector->napi; |
| 1863 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) && |
| 1864 | (q_vector->rxr_count > 1)) |
| 1865 | napi->poll = &ixgbe_clean_rxonly_many; |
| 1866 | |
| 1867 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 1872 | { |
| 1873 | int q_idx; |
| 1874 | struct ixgbe_q_vector *q_vector; |
| 1875 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1876 | |
| 1877 | /* legacy and MSI only use one vector */ |
| 1878 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 1879 | q_vectors = 1; |
| 1880 | |
| 1881 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 1882 | q_vector = &adapter->q_vector[q_idx]; |
| 1883 | if (!q_vector->rxr_count) |
| 1884 | continue; |
| 1885 | napi_disable(&q_vector->napi); |
| 1886 | } |
| 1887 | } |
| 1888 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 1889 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1890 | /* |
| 1891 | * ixgbe_configure_dcb - Configure DCB hardware |
| 1892 | * @adapter: ixgbe adapter struct |
| 1893 | * |
| 1894 | * This is called by the driver on open to configure the DCB hardware. |
| 1895 | * This is also called by the gennetlink interface when reconfiguring |
| 1896 | * the DCB state. |
| 1897 | */ |
| 1898 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 1899 | { |
| 1900 | struct ixgbe_hw *hw = &adapter->hw; |
| 1901 | u32 txdctl, vlnctrl; |
| 1902 | int i, j; |
| 1903 | |
| 1904 | ixgbe_dcb_check_config(&adapter->dcb_cfg); |
| 1905 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG); |
| 1906 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG); |
| 1907 | |
| 1908 | /* reconfigure the hardware */ |
| 1909 | ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg); |
| 1910 | |
| 1911 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1912 | j = adapter->tx_ring[i].reg_idx; |
| 1913 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 1914 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 1915 | txdctl |= 32; |
| 1916 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 1917 | } |
| 1918 | /* Enable VLAN tag insert/strip */ |
| 1919 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 1920 | vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
| 1921 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 1922 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 1923 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
| 1924 | } |
| 1925 | |
| 1926 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1927 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 1928 | { |
| 1929 | struct net_device *netdev = adapter->netdev; |
| 1930 | int i; |
| 1931 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1932 | ixgbe_set_rx_mode(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1933 | |
| 1934 | ixgbe_restore_vlan(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 1935 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1936 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 1937 | netif_set_gso_max_size(netdev, 32768); |
| 1938 | ixgbe_configure_dcb(adapter); |
| 1939 | } else { |
| 1940 | netif_set_gso_max_size(netdev, 65536); |
| 1941 | } |
| 1942 | #else |
| 1943 | netif_set_gso_max_size(netdev, 65536); |
| 1944 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1945 | |
| 1946 | ixgbe_configure_tx(adapter); |
| 1947 | ixgbe_configure_rx(adapter); |
| 1948 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 1949 | ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i], |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1950 | (adapter->rx_ring[i].count - 1)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1953 | /** |
| 1954 | * ixgbe_link_config - set up initial link with default speed and duplex |
| 1955 | * @hw: pointer to private hardware struct |
| 1956 | * |
| 1957 | * Returns 0 on success, negative on failure |
| 1958 | **/ |
| 1959 | static int ixgbe_link_config(struct ixgbe_hw *hw) |
| 1960 | { |
| 1961 | u32 autoneg; |
| 1962 | bool link_up = false; |
| 1963 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 1964 | |
| 1965 | if (hw->mac.ops.check_link) |
| 1966 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 1967 | |
| 1968 | if (ret) |
| 1969 | goto link_cfg_out; |
| 1970 | |
| 1971 | if (hw->mac.ops.get_link_capabilities) |
| 1972 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 1973 | &hw->mac.autoneg); |
| 1974 | if (ret) |
| 1975 | goto link_cfg_out; |
| 1976 | |
| 1977 | if (hw->mac.ops.setup_link_speed) |
| 1978 | ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up); |
| 1979 | |
| 1980 | link_cfg_out: |
| 1981 | return ret; |
| 1982 | } |
| 1983 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1984 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 1985 | { |
| 1986 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1987 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1988 | int i, j = 0; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 1989 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1990 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1991 | u32 txdctl, rxdctl, mhadd; |
| 1992 | u32 gpie; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1993 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 1994 | ixgbe_get_hw_control(adapter); |
| 1995 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1996 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) || |
| 1997 | (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1998 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1999 | gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2000 | IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2001 | } else { |
| 2002 | /* MSI only */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2003 | gpie = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2004 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2005 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 2006 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 2007 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2008 | } |
| 2009 | |
| 2010 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 2011 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 2012 | * specifically only auto mask tx and rx interrupts */ |
| 2013 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2016 | /* Enable fan failure interrupt if media type is copper */ |
| 2017 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2018 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2019 | gpie |= IXGBE_SDP1_GPIEN; |
| 2020 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2021 | } |
| 2022 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2023 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2024 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 2025 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 2026 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 2027 | |
| 2028 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
| 2029 | } |
| 2030 | |
| 2031 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2032 | j = adapter->tx_ring[i].reg_idx; |
| 2033 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2034 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2035 | txdctl |= (8 << 16); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2036 | txdctl |= IXGBE_TXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2037 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2041 | j = adapter->rx_ring[i].reg_idx; |
| 2042 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2043 | /* enable PTHRESH=32 descriptors (half the internal cache) |
| 2044 | * and HTHRESH=0 descriptors (to minimize latency on fetch), |
| 2045 | * this also removes a pesky rx_no_buffer_count increment */ |
| 2046 | rxdctl |= 0x0020; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2047 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2048 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2049 | } |
| 2050 | /* enable all receives */ |
| 2051 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2052 | rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN); |
| 2053 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxdctl); |
| 2054 | |
| 2055 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 2056 | ixgbe_configure_msix(adapter); |
| 2057 | else |
| 2058 | ixgbe_configure_msi_and_legacy(adapter); |
| 2059 | |
Peter P Waskiewicz Jr | 7adf152 | 2008-12-26 01:36:05 -0800 | [diff] [blame] | 2060 | ixgbe_napi_add_all(adapter); |
| 2061 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2062 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2063 | ixgbe_napi_enable_all(adapter); |
| 2064 | |
| 2065 | /* clear any pending interrupts, may auto mask */ |
| 2066 | IXGBE_READ_REG(hw, IXGBE_EICR); |
| 2067 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2068 | ixgbe_irq_enable(adapter); |
| 2069 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2070 | err = ixgbe_link_config(hw); |
| 2071 | if (err) |
| 2072 | dev_err(&adapter->pdev->dev, "link_config FAILED %d\n", err); |
| 2073 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 2074 | /* enable transmits */ |
| 2075 | netif_tx_start_all_queues(netdev); |
| 2076 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2077 | /* bring the link up in the watchdog, this could race with our first |
| 2078 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2079 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2080 | adapter->link_check_timeout = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2081 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 2082 | return 0; |
| 2083 | } |
| 2084 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2085 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 2086 | { |
| 2087 | WARN_ON(in_interrupt()); |
| 2088 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
| 2089 | msleep(1); |
| 2090 | ixgbe_down(adapter); |
| 2091 | ixgbe_up(adapter); |
| 2092 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 2093 | } |
| 2094 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2095 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 2096 | { |
| 2097 | /* hardware has been reset, we need to reload some things */ |
| 2098 | ixgbe_configure(adapter); |
| 2099 | |
| 2100 | return ixgbe_up_complete(adapter); |
| 2101 | } |
| 2102 | |
| 2103 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 2104 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2105 | struct ixgbe_hw *hw = &adapter->hw; |
| 2106 | if (hw->mac.ops.init_hw(hw)) |
| 2107 | dev_err(&adapter->pdev->dev, "Hardware Error\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2108 | |
| 2109 | /* reprogram the RAR[0] in case user changed it. */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2110 | 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] | 2111 | |
| 2112 | } |
| 2113 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2114 | /** |
| 2115 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 2116 | * @adapter: board private structure |
| 2117 | * @rx_ring: ring to free buffers from |
| 2118 | **/ |
| 2119 | static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2120 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2121 | { |
| 2122 | struct pci_dev *pdev = adapter->pdev; |
| 2123 | unsigned long size; |
| 2124 | unsigned int i; |
| 2125 | |
| 2126 | /* Free all the Rx ring sk_buffs */ |
| 2127 | |
| 2128 | for (i = 0; i < rx_ring->count; i++) { |
| 2129 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 2130 | |
| 2131 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 2132 | if (rx_buffer_info->dma) { |
| 2133 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2134 | rx_ring->rx_buf_len, |
| 2135 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2136 | rx_buffer_info->dma = 0; |
| 2137 | } |
| 2138 | if (rx_buffer_info->skb) { |
| 2139 | dev_kfree_skb(rx_buffer_info->skb); |
| 2140 | rx_buffer_info->skb = NULL; |
| 2141 | } |
| 2142 | if (!rx_buffer_info->page) |
| 2143 | continue; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2144 | pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2, |
| 2145 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2146 | rx_buffer_info->page_dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2147 | put_page(rx_buffer_info->page); |
| 2148 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2149 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 2153 | memset(rx_ring->rx_buffer_info, 0, size); |
| 2154 | |
| 2155 | /* Zero out the descriptor ring */ |
| 2156 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2157 | |
| 2158 | rx_ring->next_to_clean = 0; |
| 2159 | rx_ring->next_to_use = 0; |
| 2160 | |
| 2161 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 2162 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
| 2163 | } |
| 2164 | |
| 2165 | /** |
| 2166 | * ixgbe_clean_tx_ring - Free Tx Buffers |
| 2167 | * @adapter: board private structure |
| 2168 | * @tx_ring: ring to be cleaned |
| 2169 | **/ |
| 2170 | static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2171 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2172 | { |
| 2173 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 2174 | unsigned long size; |
| 2175 | unsigned int i; |
| 2176 | |
| 2177 | /* Free all the Tx ring sk_buffs */ |
| 2178 | |
| 2179 | for (i = 0; i < tx_ring->count; i++) { |
| 2180 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 2181 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 2182 | } |
| 2183 | |
| 2184 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 2185 | memset(tx_ring->tx_buffer_info, 0, size); |
| 2186 | |
| 2187 | /* Zero out the descriptor ring */ |
| 2188 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2189 | |
| 2190 | tx_ring->next_to_use = 0; |
| 2191 | tx_ring->next_to_clean = 0; |
| 2192 | |
| 2193 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 2194 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
| 2195 | } |
| 2196 | |
| 2197 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2198 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2199 | * @adapter: board private structure |
| 2200 | **/ |
| 2201 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 2202 | { |
| 2203 | int i; |
| 2204 | |
| 2205 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2206 | ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
| 2207 | } |
| 2208 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2209 | /** |
| 2210 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2211 | * @adapter: board private structure |
| 2212 | **/ |
| 2213 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 2214 | { |
| 2215 | int i; |
| 2216 | |
| 2217 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2218 | ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
| 2219 | } |
| 2220 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2221 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 2222 | { |
| 2223 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2224 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2225 | u32 rxctrl; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2226 | u32 txdctl; |
| 2227 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2228 | |
| 2229 | /* signal that we are down to the interrupt handler */ |
| 2230 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 2231 | |
| 2232 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2233 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2234 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2235 | |
| 2236 | netif_tx_disable(netdev); |
| 2237 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2238 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2239 | msleep(10); |
| 2240 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2241 | netif_tx_stop_all_queues(netdev); |
| 2242 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2243 | ixgbe_irq_disable(adapter); |
| 2244 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2245 | ixgbe_napi_disable_all(adapter); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2246 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2247 | del_timer_sync(&adapter->watchdog_timer); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2248 | cancel_work_sync(&adapter->watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2249 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2250 | /* disable transmits in the hardware now that interrupts are off */ |
| 2251 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2252 | j = adapter->tx_ring[i].reg_idx; |
| 2253 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2254 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), |
| 2255 | (txdctl & ~IXGBE_TXDCTL_ENABLE)); |
| 2256 | } |
| 2257 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2258 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2259 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2260 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 2261 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 2262 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 2263 | dca_remove_requester(&adapter->pdev->dev); |
| 2264 | } |
| 2265 | |
| 2266 | #endif |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 2267 | if (!pci_channel_offline(adapter->pdev)) |
| 2268 | ixgbe_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2269 | ixgbe_clean_all_tx_rings(adapter); |
| 2270 | ixgbe_clean_all_rx_rings(adapter); |
| 2271 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2272 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 2273 | /* since we reset the hardware DCA settings were cleared */ |
| 2274 | if (dca_add_requester(&adapter->pdev->dev) == 0) { |
| 2275 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
| 2276 | /* always use CB2 mode, difference is masked |
| 2277 | * in the CB driver */ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2278 | IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 2279 | ixgbe_setup_dca(adapter); |
| 2280 | } |
| 2281 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2284 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2285 | * ixgbe_poll - NAPI Rx polling callback |
| 2286 | * @napi: structure for representing this polling device |
| 2287 | * @budget: how many packets driver is allowed to clean |
| 2288 | * |
| 2289 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2290 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2291 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2292 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2293 | struct ixgbe_q_vector *q_vector = container_of(napi, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2294 | struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2295 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 74ce8dd | 2008-09-11 20:03:23 -0700 | [diff] [blame] | 2296 | int tx_cleaned, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2297 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2298 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 2299 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 2300 | ixgbe_update_tx_dca(adapter, adapter->tx_ring); |
| 2301 | ixgbe_update_rx_dca(adapter, adapter->rx_ring); |
| 2302 | } |
| 2303 | #endif |
| 2304 | |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2305 | tx_cleaned = ixgbe_clean_tx_irq(adapter, adapter->tx_ring); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 2306 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2307 | |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2308 | if (tx_cleaned) |
| 2309 | work_done = budget; |
| 2310 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 2311 | /* If budget not fully consumed, exit the polling mode */ |
| 2312 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2313 | napi_complete(napi); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2314 | if (adapter->itr_setting & 3) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2315 | ixgbe_set_itr(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2316 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2317 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2318 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2319 | return work_done; |
| 2320 | } |
| 2321 | |
| 2322 | /** |
| 2323 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 2324 | * @netdev: network interface device structure |
| 2325 | **/ |
| 2326 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 2327 | { |
| 2328 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2329 | |
| 2330 | /* Do the reset outside of interrupt context */ |
| 2331 | schedule_work(&adapter->reset_task); |
| 2332 | } |
| 2333 | |
| 2334 | static void ixgbe_reset_task(struct work_struct *work) |
| 2335 | { |
| 2336 | struct ixgbe_adapter *adapter; |
| 2337 | adapter = container_of(work, struct ixgbe_adapter, reset_task); |
| 2338 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2339 | /* If we're already down or resetting, just bail */ |
| 2340 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 2341 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 2342 | return; |
| 2343 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2344 | adapter->tx_timeout_count++; |
| 2345 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2346 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2349 | #ifdef CONFIG_IXGBE_DCB |
| 2350 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2351 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2352 | bool ret = false; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2353 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2354 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 2355 | adapter->ring_feature[RING_F_DCB].mask = 0x7 << 3; |
| 2356 | adapter->num_rx_queues = |
| 2357 | adapter->ring_feature[RING_F_DCB].indices; |
| 2358 | adapter->num_tx_queues = |
| 2359 | adapter->ring_feature[RING_F_DCB].indices; |
| 2360 | ret = true; |
| 2361 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2362 | ret = false; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2363 | } |
| 2364 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2365 | return ret; |
| 2366 | } |
| 2367 | #endif |
| 2368 | |
| 2369 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 2370 | { |
| 2371 | bool ret = false; |
| 2372 | |
| 2373 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 2374 | adapter->ring_feature[RING_F_RSS].mask = 0xF; |
| 2375 | adapter->num_rx_queues = |
| 2376 | adapter->ring_feature[RING_F_RSS].indices; |
| 2377 | adapter->num_tx_queues = |
| 2378 | adapter->ring_feature[RING_F_RSS].indices; |
| 2379 | ret = true; |
| 2380 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2381 | ret = false; |
| 2382 | } |
| 2383 | |
| 2384 | return ret; |
| 2385 | } |
| 2386 | |
| 2387 | static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
| 2388 | { |
| 2389 | /* Start with base case */ |
| 2390 | adapter->num_rx_queues = 1; |
| 2391 | adapter->num_tx_queues = 1; |
| 2392 | |
| 2393 | #ifdef CONFIG_IXGBE_DCB |
| 2394 | if (ixgbe_set_dcb_queues(adapter)) |
| 2395 | return; |
| 2396 | |
| 2397 | #endif |
| 2398 | if (ixgbe_set_rss_queues(adapter)) |
| 2399 | return; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2400 | } |
| 2401 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2402 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2403 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2404 | { |
| 2405 | int err, vector_threshold; |
| 2406 | |
| 2407 | /* We'll want at least 3 (vector_threshold): |
| 2408 | * 1) TxQ[0] Cleanup |
| 2409 | * 2) RxQ[0] Cleanup |
| 2410 | * 3) Other (Link Status Change, etc.) |
| 2411 | * 4) TCP Timer (optional) |
| 2412 | */ |
| 2413 | vector_threshold = MIN_MSIX_COUNT; |
| 2414 | |
| 2415 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 2416 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 2417 | * Right now, we simply care about how many we'll get; we'll |
| 2418 | * set them up later while requesting irq's. |
| 2419 | */ |
| 2420 | while (vectors >= vector_threshold) { |
| 2421 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2422 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2423 | if (!err) /* Success in acquiring all requested vectors. */ |
| 2424 | break; |
| 2425 | else if (err < 0) |
| 2426 | vectors = 0; /* Nasty failure, quit now */ |
| 2427 | else /* err == number of vectors we should try again with */ |
| 2428 | vectors = err; |
| 2429 | } |
| 2430 | |
| 2431 | if (vectors < vector_threshold) { |
| 2432 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 2433 | * This just means we'll go with either a single MSI |
| 2434 | * vector or fall back to legacy interrupts. |
| 2435 | */ |
| 2436 | DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n"); |
| 2437 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2438 | kfree(adapter->msix_entries); |
| 2439 | adapter->msix_entries = NULL; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2440 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2441 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2442 | ixgbe_set_num_queues(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2443 | } else { |
| 2444 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 2445 | /* |
| 2446 | * Adjust for only the vectors we'll use, which is minimum |
| 2447 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 2448 | * vectors we were allocated. |
| 2449 | */ |
| 2450 | adapter->num_msix_vectors = min(vectors, |
| 2451 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2452 | } |
| 2453 | } |
| 2454 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2455 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2456 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2457 | * @adapter: board private structure to initialize |
| 2458 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2459 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 2460 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2461 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2462 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2463 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2464 | int i; |
| 2465 | bool ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2466 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2467 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 2468 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2469 | adapter->rx_ring[i].reg_idx = i; |
| 2470 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2471 | adapter->tx_ring[i].reg_idx = i; |
| 2472 | ret = true; |
| 2473 | } else { |
| 2474 | ret = false; |
| 2475 | } |
| 2476 | |
| 2477 | return ret; |
| 2478 | } |
| 2479 | |
| 2480 | #ifdef CONFIG_IXGBE_DCB |
| 2481 | /** |
| 2482 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 2483 | * @adapter: board private structure to initialize |
| 2484 | * |
| 2485 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 2486 | * |
| 2487 | **/ |
| 2488 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 2489 | { |
| 2490 | int i; |
| 2491 | bool ret = false; |
| 2492 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 2493 | |
| 2494 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 2495 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2496 | /* the number of queues is assumed to be symmetric */ |
| 2497 | for (i = 0; i < dcb_i; i++) { |
| 2498 | adapter->rx_ring[i].reg_idx = i << 3; |
| 2499 | adapter->tx_ring[i].reg_idx = i << 2; |
| 2500 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2501 | ret = true; |
| 2502 | } else { |
| 2503 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2504 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2505 | } else { |
| 2506 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2507 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2508 | |
| 2509 | return ret; |
| 2510 | } |
| 2511 | #endif |
| 2512 | |
| 2513 | /** |
| 2514 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 2515 | * @adapter: board private structure to initialize |
| 2516 | * |
| 2517 | * Once we know the feature-set enabled for the device, we'll cache |
| 2518 | * the register offset the descriptor ring is assigned to. |
| 2519 | * |
| 2520 | * Note, the order the various feature calls is important. It must start with |
| 2521 | * the "most" features enabled at the same time, then trickle down to the |
| 2522 | * least amount of features turned on at once. |
| 2523 | **/ |
| 2524 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 2525 | { |
| 2526 | /* start with default case */ |
| 2527 | adapter->rx_ring[0].reg_idx = 0; |
| 2528 | adapter->tx_ring[0].reg_idx = 0; |
| 2529 | |
| 2530 | #ifdef CONFIG_IXGBE_DCB |
| 2531 | if (ixgbe_cache_ring_dcb(adapter)) |
| 2532 | return; |
| 2533 | |
| 2534 | #endif |
| 2535 | if (ixgbe_cache_ring_rss(adapter)) |
| 2536 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2537 | } |
| 2538 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2539 | /** |
| 2540 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 2541 | * @adapter: board private structure to initialize |
| 2542 | * |
| 2543 | * We allocate one ring per queue at run-time since we don't know the |
Wang Chen | a4d2f34 | 2008-12-03 22:05:58 -0800 | [diff] [blame] | 2544 | * number of queues at compile-time. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2545 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2546 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2547 | { |
| 2548 | int i; |
| 2549 | |
| 2550 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2551 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2552 | if (!adapter->tx_ring) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2553 | goto err_tx_ring_allocation; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2554 | |
| 2555 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2556 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2557 | if (!adapter->rx_ring) |
| 2558 | goto err_rx_ring_allocation; |
| 2559 | |
| 2560 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2561 | adapter->tx_ring[i].count = adapter->tx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2562 | adapter->tx_ring[i].queue_index = i; |
| 2563 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2564 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2565 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2566 | adapter->rx_ring[i].count = adapter->rx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2567 | adapter->rx_ring[i].queue_index = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2570 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2571 | |
| 2572 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2573 | |
| 2574 | err_rx_ring_allocation: |
| 2575 | kfree(adapter->tx_ring); |
| 2576 | err_tx_ring_allocation: |
| 2577 | return -ENOMEM; |
| 2578 | } |
| 2579 | |
| 2580 | /** |
| 2581 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 2582 | * @adapter: board private structure to initialize |
| 2583 | * |
| 2584 | * Attempt to configure the interrupts using the best available |
| 2585 | * capabilities of the hardware and the kernel. |
| 2586 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 2587 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2588 | { |
| 2589 | int err = 0; |
| 2590 | int vector, v_budget; |
| 2591 | |
| 2592 | /* |
| 2593 | * It's easy to be greedy for MSI-X vectors, but it really |
| 2594 | * doesn't do us much good if we have a lot more vectors |
| 2595 | * than CPU's. So let's be conservative and only ask for |
| 2596 | * (roughly) twice the number of vectors as there are CPU's. |
| 2597 | */ |
| 2598 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2599 | (int)(num_online_cpus() * 2)) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2600 | |
| 2601 | /* |
| 2602 | * At the same time, hardware can only support a maximum of |
| 2603 | * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq, |
| 2604 | * we can easily reach upwards of 64 Rx descriptor queues and |
| 2605 | * 32 Tx queues. Thus, we cap it off in those rare cases where |
| 2606 | * the cpu count also exceeds our vector limit. |
| 2607 | */ |
| 2608 | v_budget = min(v_budget, MAX_MSIX_COUNT); |
| 2609 | |
| 2610 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 2611 | * mean we disable MSI-X capabilities of the adapter. */ |
| 2612 | adapter->msix_entries = kcalloc(v_budget, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2613 | sizeof(struct msix_entry), GFP_KERNEL); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2614 | if (!adapter->msix_entries) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2615 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2616 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
| 2617 | ixgbe_set_num_queues(adapter); |
| 2618 | kfree(adapter->tx_ring); |
| 2619 | kfree(adapter->rx_ring); |
| 2620 | err = ixgbe_alloc_queues(adapter); |
| 2621 | if (err) { |
| 2622 | DPRINTK(PROBE, ERR, "Unable to allocate memory " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2623 | "for queues\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2624 | goto out; |
| 2625 | } |
| 2626 | |
| 2627 | goto try_msi; |
| 2628 | } |
| 2629 | |
| 2630 | for (vector = 0; vector < v_budget; vector++) |
| 2631 | adapter->msix_entries[vector].entry = vector; |
| 2632 | |
| 2633 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 2634 | |
| 2635 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 2636 | goto out; |
| 2637 | |
| 2638 | try_msi: |
| 2639 | err = pci_enable_msi(adapter->pdev); |
| 2640 | if (!err) { |
| 2641 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 2642 | } else { |
| 2643 | DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2644 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2645 | /* reset err */ |
| 2646 | err = 0; |
| 2647 | } |
| 2648 | |
| 2649 | out: |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 2650 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 2651 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2652 | |
| 2653 | return err; |
| 2654 | } |
| 2655 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2656 | void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2657 | { |
| 2658 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2659 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2660 | pci_disable_msix(adapter->pdev); |
| 2661 | kfree(adapter->msix_entries); |
| 2662 | adapter->msix_entries = NULL; |
| 2663 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 2664 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 2665 | pci_disable_msi(adapter->pdev); |
| 2666 | } |
| 2667 | return; |
| 2668 | } |
| 2669 | |
| 2670 | /** |
| 2671 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 2672 | * @adapter: board private structure to initialize |
| 2673 | * |
| 2674 | * We determine which interrupt scheme to use based on... |
| 2675 | * - Kernel support (MSI, MSI-X) |
| 2676 | * - which can be user-defined (via MODULE_PARAM) |
| 2677 | * - Hardware queue count (num_*_queues) |
| 2678 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 2679 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2680 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2681 | { |
| 2682 | int err; |
| 2683 | |
| 2684 | /* Number of supported queues */ |
| 2685 | ixgbe_set_num_queues(adapter); |
| 2686 | |
| 2687 | err = ixgbe_alloc_queues(adapter); |
| 2688 | if (err) { |
| 2689 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 2690 | goto err_alloc_queues; |
| 2691 | } |
| 2692 | |
| 2693 | err = ixgbe_set_interrupt_capability(adapter); |
| 2694 | if (err) { |
| 2695 | DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n"); |
| 2696 | goto err_set_interrupt; |
| 2697 | } |
| 2698 | |
| 2699 | DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2700 | "Tx Queue count = %u\n", |
| 2701 | (adapter->num_rx_queues > 1) ? "Enabled" : |
| 2702 | "Disabled", adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2703 | |
| 2704 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 2705 | |
| 2706 | return 0; |
| 2707 | |
| 2708 | err_set_interrupt: |
| 2709 | kfree(adapter->tx_ring); |
| 2710 | kfree(adapter->rx_ring); |
| 2711 | err_alloc_queues: |
| 2712 | return err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | /** |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 2716 | * ixgbe_sfp_timer - worker thread to find a missing module |
| 2717 | * @data: pointer to our adapter struct |
| 2718 | **/ |
| 2719 | static void ixgbe_sfp_timer(unsigned long data) |
| 2720 | { |
| 2721 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 2722 | |
| 2723 | /* Do the sfp_timer outside of interrupt context due to the |
| 2724 | * delays that sfp+ detection requires |
| 2725 | */ |
| 2726 | schedule_work(&adapter->sfp_task); |
| 2727 | } |
| 2728 | |
| 2729 | /** |
| 2730 | * ixgbe_sfp_task - worker thread to find a missing module |
| 2731 | * @work: pointer to work_struct containing our data |
| 2732 | **/ |
| 2733 | static void ixgbe_sfp_task(struct work_struct *work) |
| 2734 | { |
| 2735 | struct ixgbe_adapter *adapter = container_of(work, |
| 2736 | struct ixgbe_adapter, |
| 2737 | sfp_task); |
| 2738 | struct ixgbe_hw *hw = &adapter->hw; |
| 2739 | |
| 2740 | if ((hw->phy.type == ixgbe_phy_nl) && |
| 2741 | (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) { |
| 2742 | s32 ret = hw->phy.ops.identify_sfp(hw); |
| 2743 | if (ret) |
| 2744 | goto reschedule; |
| 2745 | ret = hw->phy.ops.reset(hw); |
| 2746 | if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
| 2747 | DPRINTK(PROBE, ERR, "failed to initialize because an " |
| 2748 | "unsupported SFP+ module type was detected.\n" |
| 2749 | "Reload the driver after installing a " |
| 2750 | "supported module.\n"); |
| 2751 | unregister_netdev(adapter->netdev); |
| 2752 | } else { |
| 2753 | DPRINTK(PROBE, INFO, "detected SFP+: %d\n", |
| 2754 | hw->phy.sfp_type); |
| 2755 | } |
| 2756 | /* don't need this routine any more */ |
| 2757 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 2758 | } |
| 2759 | return; |
| 2760 | reschedule: |
| 2761 | if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state)) |
| 2762 | mod_timer(&adapter->sfp_timer, |
| 2763 | round_jiffies(jiffies + (2 * HZ))); |
| 2764 | } |
| 2765 | |
| 2766 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2767 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 2768 | * @adapter: board private structure to initialize |
| 2769 | * |
| 2770 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 2771 | * Fields are initialized based on PCI device information and |
| 2772 | * OS network device settings (MTU size). |
| 2773 | **/ |
| 2774 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 2775 | { |
| 2776 | struct ixgbe_hw *hw = &adapter->hw; |
| 2777 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2778 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2779 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2780 | int j; |
| 2781 | struct tc_configuration *tc; |
| 2782 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2783 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2784 | /* PCI config space info */ |
| 2785 | |
| 2786 | hw->vendor_id = pdev->vendor; |
| 2787 | hw->device_id = pdev->device; |
| 2788 | hw->revision_id = pdev->revision; |
| 2789 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 2790 | hw->subsystem_device_id = pdev->subsystem_device; |
| 2791 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2792 | /* Set capability flags */ |
| 2793 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 2794 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 2795 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2796 | adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES; |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 2797 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2798 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2799 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2800 | /* Configure DCB traffic classes */ |
| 2801 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 2802 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 2803 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 2804 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 2805 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 2806 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 2807 | tc->dcb_pfc = pfc_disabled; |
| 2808 | } |
| 2809 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 2810 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 2811 | adapter->dcb_cfg.rx_pba_cfg = pba_equal; |
| 2812 | adapter->dcb_cfg.round_robin_enable = false; |
| 2813 | adapter->dcb_set_bitmap = 0x00; |
| 2814 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
| 2815 | adapter->ring_feature[RING_F_DCB].indices); |
| 2816 | |
| 2817 | #endif |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2818 | if (hw->mac.ops.get_media_type && |
| 2819 | (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper)) |
| 2820 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2821 | |
| 2822 | /* default flow control settings */ |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2823 | hw->fc.requested_mode = ixgbe_fc_none; |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 2824 | hw->fc.high_water = IXGBE_DEFAULT_FCRTH; |
| 2825 | hw->fc.low_water = IXGBE_DEFAULT_FCRTL; |
| 2826 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 2827 | hw->fc.send_xon = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2828 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2829 | /* enable itr by default in dynamic mode */ |
| 2830 | adapter->itr_setting = 1; |
| 2831 | adapter->eitr_param = 20000; |
| 2832 | |
| 2833 | /* set defaults for eitr in MegaBytes */ |
| 2834 | adapter->eitr_low = 10; |
| 2835 | adapter->eitr_high = 20; |
| 2836 | |
| 2837 | /* set default ring sizes */ |
| 2838 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 2839 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 2840 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2841 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2842 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2843 | dev_err(&pdev->dev, "EEPROM initialization failed\n"); |
| 2844 | return -EIO; |
| 2845 | } |
| 2846 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2847 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2848 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 2849 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2850 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 2851 | |
| 2852 | return 0; |
| 2853 | } |
| 2854 | |
| 2855 | /** |
| 2856 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
| 2857 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2858 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2859 | * |
| 2860 | * Return 0 on success, negative on failure |
| 2861 | **/ |
| 2862 | int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2863 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2864 | { |
| 2865 | struct pci_dev *pdev = adapter->pdev; |
| 2866 | int size; |
| 2867 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2868 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 2869 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2870 | if (!tx_ring->tx_buffer_info) |
| 2871 | goto err; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2872 | memset(tx_ring->tx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2873 | |
| 2874 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 2875 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2876 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2877 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2878 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, |
| 2879 | &tx_ring->dma); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2880 | if (!tx_ring->desc) |
| 2881 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2882 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2883 | tx_ring->next_to_use = 0; |
| 2884 | tx_ring->next_to_clean = 0; |
| 2885 | tx_ring->work_limit = tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2886 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2887 | |
| 2888 | err: |
| 2889 | vfree(tx_ring->tx_buffer_info); |
| 2890 | tx_ring->tx_buffer_info = NULL; |
| 2891 | DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit " |
| 2892 | "descriptor ring\n"); |
| 2893 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 2897 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 2898 | * @adapter: board private structure |
| 2899 | * |
| 2900 | * If this function returns with an error, then it's possible one or |
| 2901 | * more of the rings is populated (while the rest are not). It is the |
| 2902 | * callers duty to clean those orphaned rings. |
| 2903 | * |
| 2904 | * Return 0 on success, negative on failure |
| 2905 | **/ |
| 2906 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 2907 | { |
| 2908 | int i, err = 0; |
| 2909 | |
| 2910 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2911 | err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 2912 | if (!err) |
| 2913 | continue; |
| 2914 | DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i); |
| 2915 | break; |
| 2916 | } |
| 2917 | |
| 2918 | return err; |
| 2919 | } |
| 2920 | |
| 2921 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2922 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
| 2923 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2924 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2925 | * |
| 2926 | * Returns 0 on success, negative on failure |
| 2927 | **/ |
| 2928 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2929 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2930 | { |
| 2931 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2932 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2933 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2934 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 2935 | rx_ring->rx_buffer_info = vmalloc(size); |
| 2936 | if (!rx_ring->rx_buffer_info) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2937 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2938 | "vmalloc allocation failed for the rx desc ring\n"); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2939 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2940 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2941 | memset(rx_ring->rx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2942 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2943 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2944 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 2945 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2946 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2947 | 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] | 2948 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2949 | if (!rx_ring->desc) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2950 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2951 | "Memory allocation failed for the rx desc ring\n"); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2952 | vfree(rx_ring->rx_buffer_info); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2953 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2956 | rx_ring->next_to_clean = 0; |
| 2957 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2958 | |
| 2959 | return 0; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2960 | |
| 2961 | alloc_failed: |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2962 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 2966 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 2967 | * @adapter: board private structure |
| 2968 | * |
| 2969 | * If this function returns with an error, then it's possible one or |
| 2970 | * more of the rings is populated (while the rest are not). It is the |
| 2971 | * callers duty to clean those orphaned rings. |
| 2972 | * |
| 2973 | * Return 0 on success, negative on failure |
| 2974 | **/ |
| 2975 | |
| 2976 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 2977 | { |
| 2978 | int i, err = 0; |
| 2979 | |
| 2980 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2981 | err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 2982 | if (!err) |
| 2983 | continue; |
| 2984 | DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i); |
| 2985 | break; |
| 2986 | } |
| 2987 | |
| 2988 | return err; |
| 2989 | } |
| 2990 | |
| 2991 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2992 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
| 2993 | * @adapter: board private structure |
| 2994 | * @tx_ring: Tx descriptor ring for a specific queue |
| 2995 | * |
| 2996 | * Free all transmit software resources |
| 2997 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 2998 | void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter, |
| 2999 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3000 | { |
| 3001 | struct pci_dev *pdev = adapter->pdev; |
| 3002 | |
| 3003 | ixgbe_clean_tx_ring(adapter, tx_ring); |
| 3004 | |
| 3005 | vfree(tx_ring->tx_buffer_info); |
| 3006 | tx_ring->tx_buffer_info = NULL; |
| 3007 | |
| 3008 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 3009 | |
| 3010 | tx_ring->desc = NULL; |
| 3011 | } |
| 3012 | |
| 3013 | /** |
| 3014 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 3015 | * @adapter: board private structure |
| 3016 | * |
| 3017 | * Free all transmit software resources |
| 3018 | **/ |
| 3019 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 3020 | { |
| 3021 | int i; |
| 3022 | |
| 3023 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3024 | ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]); |
| 3025 | } |
| 3026 | |
| 3027 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3028 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3029 | * @adapter: board private structure |
| 3030 | * @rx_ring: ring to clean the resources from |
| 3031 | * |
| 3032 | * Free all receive software resources |
| 3033 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 3034 | void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter, |
| 3035 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3036 | { |
| 3037 | struct pci_dev *pdev = adapter->pdev; |
| 3038 | |
| 3039 | ixgbe_clean_rx_ring(adapter, rx_ring); |
| 3040 | |
| 3041 | vfree(rx_ring->rx_buffer_info); |
| 3042 | rx_ring->rx_buffer_info = NULL; |
| 3043 | |
| 3044 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 3045 | |
| 3046 | rx_ring->desc = NULL; |
| 3047 | } |
| 3048 | |
| 3049 | /** |
| 3050 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 3051 | * @adapter: board private structure |
| 3052 | * |
| 3053 | * Free all receive software resources |
| 3054 | **/ |
| 3055 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 3056 | { |
| 3057 | int i; |
| 3058 | |
| 3059 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3060 | ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]); |
| 3061 | } |
| 3062 | |
| 3063 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3064 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 3065 | * @netdev: network interface device structure |
| 3066 | * @new_mtu: new value for maximum frame size |
| 3067 | * |
| 3068 | * Returns 0 on success, negative on failure |
| 3069 | **/ |
| 3070 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 3071 | { |
| 3072 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3073 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3074 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 3075 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 3076 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3077 | return -EINVAL; |
| 3078 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3079 | DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n", |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3080 | netdev->mtu, new_mtu); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3081 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3082 | netdev->mtu = new_mtu; |
| 3083 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3084 | if (netif_running(netdev)) |
| 3085 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3086 | |
| 3087 | return 0; |
| 3088 | } |
| 3089 | |
| 3090 | /** |
| 3091 | * ixgbe_open - Called when a network interface is made active |
| 3092 | * @netdev: network interface device structure |
| 3093 | * |
| 3094 | * Returns 0 on success, negative value on failure |
| 3095 | * |
| 3096 | * The open entry point is called when a network interface is made |
| 3097 | * active by the system (IFF_UP). At this point all resources needed |
| 3098 | * for transmit and receive operations are allocated, the interrupt |
| 3099 | * handler is registered with the OS, the watchdog timer is started, |
| 3100 | * and the stack is notified that the interface is ready. |
| 3101 | **/ |
| 3102 | static int ixgbe_open(struct net_device *netdev) |
| 3103 | { |
| 3104 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3105 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3106 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 3107 | /* disallow open during test */ |
| 3108 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 3109 | return -EBUSY; |
| 3110 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3111 | /* allocate transmit descriptors */ |
| 3112 | err = ixgbe_setup_all_tx_resources(adapter); |
| 3113 | if (err) |
| 3114 | goto err_setup_tx; |
| 3115 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3116 | /* allocate receive descriptors */ |
| 3117 | err = ixgbe_setup_all_rx_resources(adapter); |
| 3118 | if (err) |
| 3119 | goto err_setup_rx; |
| 3120 | |
| 3121 | ixgbe_configure(adapter); |
| 3122 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3123 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3124 | if (err) |
| 3125 | goto err_req_irq; |
| 3126 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3127 | err = ixgbe_up_complete(adapter); |
| 3128 | if (err) |
| 3129 | goto err_up; |
| 3130 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 3131 | netif_tx_start_all_queues(netdev); |
| 3132 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3133 | return 0; |
| 3134 | |
| 3135 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 3136 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3137 | ixgbe_free_irq(adapter); |
| 3138 | err_req_irq: |
| 3139 | ixgbe_free_all_rx_resources(adapter); |
| 3140 | err_setup_rx: |
| 3141 | ixgbe_free_all_tx_resources(adapter); |
| 3142 | err_setup_tx: |
| 3143 | ixgbe_reset(adapter); |
| 3144 | |
| 3145 | return err; |
| 3146 | } |
| 3147 | |
| 3148 | /** |
| 3149 | * ixgbe_close - Disables a network interface |
| 3150 | * @netdev: network interface device structure |
| 3151 | * |
| 3152 | * Returns 0, this is not allowed to fail |
| 3153 | * |
| 3154 | * The close entry point is called when an interface is de-activated |
| 3155 | * by the OS. The hardware is still under the drivers control, but |
| 3156 | * needs to be disabled. A global MAC reset is issued to stop the |
| 3157 | * hardware, and all transmit and receive resources are freed. |
| 3158 | **/ |
| 3159 | static int ixgbe_close(struct net_device *netdev) |
| 3160 | { |
| 3161 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3162 | |
| 3163 | ixgbe_down(adapter); |
| 3164 | ixgbe_free_irq(adapter); |
| 3165 | |
| 3166 | ixgbe_free_all_tx_resources(adapter); |
| 3167 | ixgbe_free_all_rx_resources(adapter); |
| 3168 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 3169 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3170 | |
| 3171 | return 0; |
| 3172 | } |
| 3173 | |
| 3174 | /** |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3175 | * ixgbe_napi_add_all - prep napi structs for use |
| 3176 | * @adapter: private struct |
| 3177 | * helper function to napi_add each possible q_vector->napi |
| 3178 | */ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3179 | void ixgbe_napi_add_all(struct ixgbe_adapter *adapter) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3180 | { |
| 3181 | int q_idx, q_vectors; |
Peter P Waskiewicz Jr | 7adf152 | 2008-12-26 01:36:05 -0800 | [diff] [blame] | 3182 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3183 | int (*poll)(struct napi_struct *, int); |
| 3184 | |
Peter P Waskiewicz Jr | 7adf152 | 2008-12-26 01:36:05 -0800 | [diff] [blame] | 3185 | /* check if we already have our netdev->napi_list populated */ |
| 3186 | if (&netdev->napi_list != netdev->napi_list.next) |
| 3187 | return; |
| 3188 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3189 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3190 | poll = &ixgbe_clean_rxonly; |
| 3191 | /* Only enable as many vectors as we have rx queues. */ |
| 3192 | q_vectors = adapter->num_rx_queues; |
| 3193 | } else { |
| 3194 | poll = &ixgbe_poll; |
| 3195 | /* only one q_vector for legacy modes */ |
| 3196 | q_vectors = 1; |
| 3197 | } |
| 3198 | |
| 3199 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 3200 | struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx]; |
| 3201 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
| 3202 | } |
| 3203 | } |
| 3204 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3205 | void ixgbe_napi_del_all(struct ixgbe_adapter *adapter) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3206 | { |
| 3207 | int q_idx; |
| 3208 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3209 | |
| 3210 | /* legacy and MSI only use one vector */ |
| 3211 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3212 | q_vectors = 1; |
| 3213 | |
| 3214 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 3215 | struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx]; |
| 3216 | if (!q_vector->rxr_count) |
| 3217 | continue; |
| 3218 | netif_napi_del(&q_vector->napi); |
| 3219 | } |
| 3220 | } |
| 3221 | |
| 3222 | #ifdef CONFIG_PM |
| 3223 | static int ixgbe_resume(struct pci_dev *pdev) |
| 3224 | { |
| 3225 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3226 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3227 | u32 err; |
| 3228 | |
| 3229 | pci_set_power_state(pdev, PCI_D0); |
| 3230 | pci_restore_state(pdev); |
| 3231 | err = pci_enable_device(pdev); |
| 3232 | if (err) { |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 3233 | printk(KERN_ERR "ixgbe: Cannot enable PCI device from " |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3234 | "suspend\n"); |
| 3235 | return err; |
| 3236 | } |
| 3237 | pci_set_master(pdev); |
| 3238 | |
| 3239 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 3240 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 3241 | |
| 3242 | err = ixgbe_init_interrupt_scheme(adapter); |
| 3243 | if (err) { |
| 3244 | printk(KERN_ERR "ixgbe: Cannot initialize interrupts for " |
| 3245 | "device\n"); |
| 3246 | return err; |
| 3247 | } |
| 3248 | |
| 3249 | ixgbe_napi_add_all(adapter); |
| 3250 | ixgbe_reset(adapter); |
| 3251 | |
| 3252 | if (netif_running(netdev)) { |
| 3253 | err = ixgbe_open(adapter->netdev); |
| 3254 | if (err) |
| 3255 | return err; |
| 3256 | } |
| 3257 | |
| 3258 | netif_device_attach(netdev); |
| 3259 | |
| 3260 | return 0; |
| 3261 | } |
| 3262 | |
| 3263 | #endif /* CONFIG_PM */ |
| 3264 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 3265 | { |
| 3266 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3267 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3268 | #ifdef CONFIG_PM |
| 3269 | int retval = 0; |
| 3270 | #endif |
| 3271 | |
| 3272 | netif_device_detach(netdev); |
| 3273 | |
| 3274 | if (netif_running(netdev)) { |
| 3275 | ixgbe_down(adapter); |
| 3276 | ixgbe_free_irq(adapter); |
| 3277 | ixgbe_free_all_tx_resources(adapter); |
| 3278 | ixgbe_free_all_rx_resources(adapter); |
| 3279 | } |
| 3280 | ixgbe_reset_interrupt_capability(adapter); |
| 3281 | ixgbe_napi_del_all(adapter); |
Peter P Waskiewicz Jr | 7adf152 | 2008-12-26 01:36:05 -0800 | [diff] [blame] | 3282 | INIT_LIST_HEAD(&netdev->napi_list); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3283 | kfree(adapter->tx_ring); |
| 3284 | kfree(adapter->rx_ring); |
| 3285 | |
| 3286 | #ifdef CONFIG_PM |
| 3287 | retval = pci_save_state(pdev); |
| 3288 | if (retval) |
| 3289 | return retval; |
| 3290 | #endif |
| 3291 | |
| 3292 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 3293 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 3294 | |
| 3295 | ixgbe_release_hw_control(adapter); |
| 3296 | |
| 3297 | pci_disable_device(pdev); |
| 3298 | |
| 3299 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 3300 | |
| 3301 | return 0; |
| 3302 | } |
| 3303 | |
| 3304 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 3305 | { |
| 3306 | ixgbe_suspend(pdev, PMSG_SUSPEND); |
| 3307 | } |
| 3308 | |
| 3309 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3310 | * ixgbe_update_stats - Update the board statistics counters. |
| 3311 | * @adapter: board private structure |
| 3312 | **/ |
| 3313 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 3314 | { |
| 3315 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3316 | u64 total_mpc = 0; |
| 3317 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3318 | |
| 3319 | adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3320 | for (i = 0; i < 8; i++) { |
| 3321 | /* for packet buffers not used, the register should read 0 */ |
| 3322 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 3323 | missed_rx += mpc; |
| 3324 | adapter->stats.mpc[i] += mpc; |
| 3325 | total_mpc += adapter->stats.mpc[i]; |
| 3326 | adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3327 | adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 3328 | adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 3329 | adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 3330 | adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
| 3331 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 3332 | IXGBE_PXONRXC(i)); |
| 3333 | adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw, |
| 3334 | IXGBE_PXONTXC(i)); |
| 3335 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 3336 | IXGBE_PXOFFRXC(i)); |
| 3337 | adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw, |
| 3338 | IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3339 | } |
| 3340 | adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
| 3341 | /* work around hardware counting issue */ |
| 3342 | adapter->stats.gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3343 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3344 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3345 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3346 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 3347 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3348 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
| 3349 | adapter->stats.bprc += bprc; |
| 3350 | adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
| 3351 | adapter->stats.mprc -= bprc; |
| 3352 | adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 3353 | adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 3354 | adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 3355 | adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 3356 | adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 3357 | adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 3358 | adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3359 | adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
| 3360 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3361 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3362 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
| 3363 | adapter->stats.lxontxc += lxon; |
| 3364 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
| 3365 | adapter->stats.lxofftxc += lxoff; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3366 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 3367 | adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3368 | adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
| 3369 | /* |
| 3370 | * 82598 errata - tx of flow control packets is included in tx counters |
| 3371 | */ |
| 3372 | xon_off_tot = lxon + lxoff; |
| 3373 | adapter->stats.gptc -= xon_off_tot; |
| 3374 | adapter->stats.mptc -= xon_off_tot; |
| 3375 | adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3376 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 3377 | adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 3378 | adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3379 | adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 3380 | adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3381 | adapter->stats.ptc64 -= xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3382 | adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 3383 | adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 3384 | adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 3385 | adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 3386 | adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3387 | adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
| 3388 | |
| 3389 | /* Fill out the OS statistics structure */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3390 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 3391 | |
| 3392 | /* Rx Errors */ |
| 3393 | adapter->net_stats.rx_errors = adapter->stats.crcerrs + |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3394 | adapter->stats.rlec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3395 | adapter->net_stats.rx_dropped = 0; |
| 3396 | adapter->net_stats.rx_length_errors = adapter->stats.rlec; |
| 3397 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3398 | adapter->net_stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | /** |
| 3402 | * ixgbe_watchdog - Timer Call-back |
| 3403 | * @data: pointer to adapter cast into an unsigned long |
| 3404 | **/ |
| 3405 | static void ixgbe_watchdog(unsigned long data) |
| 3406 | { |
| 3407 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3408 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3409 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3410 | /* Do the watchdog outside of interrupt context due to the lovely |
| 3411 | * delays that some of the newer hardware requires */ |
| 3412 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 3413 | /* Cause software interrupt to ensure rx rings are cleaned */ |
| 3414 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3415 | u32 eics = |
| 3416 | (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1; |
| 3417 | IXGBE_WRITE_REG(hw, IXGBE_EICS, eics); |
| 3418 | } else { |
| 3419 | /* For legacy and MSI interrupts don't set any bits that |
| 3420 | * are enabled for EIAM, because this operation would |
| 3421 | * set *both* EIMS and EICS for any bit in EIAM */ |
| 3422 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 3423 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
| 3424 | } |
| 3425 | /* Reset the timer */ |
| 3426 | mod_timer(&adapter->watchdog_timer, |
| 3427 | round_jiffies(jiffies + 2 * HZ)); |
| 3428 | } |
| 3429 | |
| 3430 | schedule_work(&adapter->watchdog_task); |
| 3431 | } |
| 3432 | |
| 3433 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 3434 | * ixgbe_watchdog_task - worker thread to bring link up |
| 3435 | * @work: pointer to work_struct containing our data |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3436 | **/ |
| 3437 | static void ixgbe_watchdog_task(struct work_struct *work) |
| 3438 | { |
| 3439 | struct ixgbe_adapter *adapter = container_of(work, |
| 3440 | struct ixgbe_adapter, |
| 3441 | watchdog_task); |
| 3442 | struct net_device *netdev = adapter->netdev; |
| 3443 | struct ixgbe_hw *hw = &adapter->hw; |
| 3444 | u32 link_speed = adapter->link_speed; |
| 3445 | bool link_up = adapter->link_up; |
| 3446 | |
| 3447 | adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK; |
| 3448 | |
| 3449 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) { |
| 3450 | hw->mac.ops.check_link(hw, &link_speed, &link_up, false); |
| 3451 | if (link_up || |
| 3452 | time_after(jiffies, (adapter->link_check_timeout + |
| 3453 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 3454 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 3455 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 3456 | } |
| 3457 | adapter->link_up = link_up; |
| 3458 | adapter->link_speed = link_speed; |
| 3459 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3460 | |
| 3461 | if (link_up) { |
| 3462 | if (!netif_carrier_ok(netdev)) { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3463 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3464 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3465 | #define FLOW_RX (frctl & IXGBE_FCTRL_RFCE) |
| 3466 | #define FLOW_TX (rmcs & IXGBE_RMCS_TFCE_802_3X) |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 3467 | printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, " |
| 3468 | "Flow Control: %s\n", |
| 3469 | netdev->name, |
| 3470 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 3471 | "10 Gbps" : |
| 3472 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 3473 | "1 Gbps" : "unknown speed")), |
| 3474 | ((FLOW_RX && FLOW_TX) ? "RX/TX" : |
| 3475 | (FLOW_RX ? "RX" : |
| 3476 | (FLOW_TX ? "TX" : "None")))); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3477 | |
| 3478 | netif_carrier_on(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3479 | } else { |
| 3480 | /* Force detection of hung controller */ |
| 3481 | adapter->detect_tx_hung = true; |
| 3482 | } |
| 3483 | } else { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3484 | adapter->link_up = false; |
| 3485 | adapter->link_speed = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3486 | if (netif_carrier_ok(netdev)) { |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 3487 | printk(KERN_INFO "ixgbe: %s NIC Link is Down\n", |
| 3488 | netdev->name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3489 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3490 | } |
| 3491 | } |
| 3492 | |
| 3493 | ixgbe_update_stats(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3494 | adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3495 | } |
| 3496 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3497 | static int ixgbe_tso(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3498 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 3499 | u32 tx_flags, u8 *hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3500 | { |
| 3501 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 3502 | unsigned int i; |
| 3503 | int err; |
| 3504 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3505 | u32 vlan_macip_lens = 0, type_tucmd_mlhl; |
| 3506 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3507 | |
| 3508 | if (skb_is_gso(skb)) { |
| 3509 | if (skb_header_cloned(skb)) { |
| 3510 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 3511 | if (err) |
| 3512 | return err; |
| 3513 | } |
| 3514 | l4len = tcp_hdrlen(skb); |
| 3515 | *hdr_len += l4len; |
| 3516 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 3517 | if (skb->protocol == htons(ETH_P_IP)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3518 | struct iphdr *iph = ip_hdr(skb); |
| 3519 | iph->tot_len = 0; |
| 3520 | iph->check = 0; |
| 3521 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3522 | iph->daddr, 0, |
| 3523 | IPPROTO_TCP, |
| 3524 | 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3525 | adapter->hw_tso_ctxt++; |
| 3526 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { |
| 3527 | ipv6_hdr(skb)->payload_len = 0; |
| 3528 | tcp_hdr(skb)->check = |
| 3529 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3530 | &ipv6_hdr(skb)->daddr, |
| 3531 | 0, IPPROTO_TCP, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3532 | adapter->hw_tso6_ctxt++; |
| 3533 | } |
| 3534 | |
| 3535 | i = tx_ring->next_to_use; |
| 3536 | |
| 3537 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 3538 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 3539 | |
| 3540 | /* VLAN MACLEN IPLEN */ |
| 3541 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 3542 | vlan_macip_lens |= |
| 3543 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 3544 | vlan_macip_lens |= ((skb_network_offset(skb)) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3545 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3546 | *hdr_len += skb_network_offset(skb); |
| 3547 | vlan_macip_lens |= |
| 3548 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 3549 | *hdr_len += |
| 3550 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 3551 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 3552 | context_desc->seqnum_seed = 0; |
| 3553 | |
| 3554 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3555 | type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3556 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3557 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 3558 | if (skb->protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3559 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 3560 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 3561 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
| 3562 | |
| 3563 | /* MSS L4LEN IDX */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3564 | mss_l4len_idx = |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3565 | (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT); |
| 3566 | mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 3567 | /* use index 1 for TSO */ |
| 3568 | mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3569 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 3570 | |
| 3571 | tx_buffer_info->time_stamp = jiffies; |
| 3572 | tx_buffer_info->next_to_watch = i; |
| 3573 | |
| 3574 | i++; |
| 3575 | if (i == tx_ring->count) |
| 3576 | i = 0; |
| 3577 | tx_ring->next_to_use = i; |
| 3578 | |
| 3579 | return true; |
| 3580 | } |
| 3581 | return false; |
| 3582 | } |
| 3583 | |
| 3584 | static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3585 | struct ixgbe_ring *tx_ring, |
| 3586 | struct sk_buff *skb, u32 tx_flags) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3587 | { |
| 3588 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 3589 | unsigned int i; |
| 3590 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 3591 | u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0; |
| 3592 | |
| 3593 | if (skb->ip_summed == CHECKSUM_PARTIAL || |
| 3594 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) { |
| 3595 | i = tx_ring->next_to_use; |
| 3596 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 3597 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 3598 | |
| 3599 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 3600 | vlan_macip_lens |= |
| 3601 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 3602 | vlan_macip_lens |= (skb_network_offset(skb) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3603 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3604 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 3605 | vlan_macip_lens |= (skb_transport_header(skb) - |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3606 | skb_network_header(skb)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3607 | |
| 3608 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 3609 | context_desc->seqnum_seed = 0; |
| 3610 | |
| 3611 | type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3612 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3613 | |
| 3614 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 3615 | switch (skb->protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 3616 | case cpu_to_be16(ETH_P_IP): |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3617 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 3618 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 3619 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3620 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 3621 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 3622 | case cpu_to_be16(ETH_P_IPV6): |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 3623 | /* XXX what about other V6 headers?? */ |
| 3624 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 3625 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3626 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 3627 | break; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 3628 | default: |
| 3629 | if (unlikely(net_ratelimit())) { |
| 3630 | DPRINTK(PROBE, WARNING, |
| 3631 | "partial checksum but proto=%x!\n", |
| 3632 | skb->protocol); |
| 3633 | } |
| 3634 | break; |
| 3635 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3636 | } |
| 3637 | |
| 3638 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 3639 | /* use index zero for tx checksum offload */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3640 | context_desc->mss_l4len_idx = 0; |
| 3641 | |
| 3642 | tx_buffer_info->time_stamp = jiffies; |
| 3643 | tx_buffer_info->next_to_watch = i; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3644 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3645 | adapter->hw_csum_tx_good++; |
| 3646 | i++; |
| 3647 | if (i == tx_ring->count) |
| 3648 | i = 0; |
| 3649 | tx_ring->next_to_use = i; |
| 3650 | |
| 3651 | return true; |
| 3652 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3653 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3654 | return false; |
| 3655 | } |
| 3656 | |
| 3657 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3658 | struct ixgbe_ring *tx_ring, |
| 3659 | struct sk_buff *skb, unsigned int first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3660 | { |
| 3661 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 3662 | unsigned int len = skb->len; |
| 3663 | unsigned int offset = 0, size, count = 0, i; |
| 3664 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 3665 | unsigned int f; |
| 3666 | |
| 3667 | len -= skb->data_len; |
| 3668 | |
| 3669 | i = tx_ring->next_to_use; |
| 3670 | |
| 3671 | while (len) { |
| 3672 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 3673 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 3674 | |
| 3675 | tx_buffer_info->length = size; |
| 3676 | tx_buffer_info->dma = pci_map_single(adapter->pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3677 | skb->data + offset, |
| 3678 | size, PCI_DMA_TODEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3679 | tx_buffer_info->time_stamp = jiffies; |
| 3680 | tx_buffer_info->next_to_watch = i; |
| 3681 | |
| 3682 | len -= size; |
| 3683 | offset += size; |
| 3684 | count++; |
| 3685 | i++; |
| 3686 | if (i == tx_ring->count) |
| 3687 | i = 0; |
| 3688 | } |
| 3689 | |
| 3690 | for (f = 0; f < nr_frags; f++) { |
| 3691 | struct skb_frag_struct *frag; |
| 3692 | |
| 3693 | frag = &skb_shinfo(skb)->frags[f]; |
| 3694 | len = frag->size; |
| 3695 | offset = frag->page_offset; |
| 3696 | |
| 3697 | while (len) { |
| 3698 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 3699 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 3700 | |
| 3701 | tx_buffer_info->length = size; |
| 3702 | tx_buffer_info->dma = pci_map_page(adapter->pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3703 | frag->page, |
| 3704 | offset, |
| 3705 | size, |
| 3706 | PCI_DMA_TODEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3707 | tx_buffer_info->time_stamp = jiffies; |
| 3708 | tx_buffer_info->next_to_watch = i; |
| 3709 | |
| 3710 | len -= size; |
| 3711 | offset += size; |
| 3712 | count++; |
| 3713 | i++; |
| 3714 | if (i == tx_ring->count) |
| 3715 | i = 0; |
| 3716 | } |
| 3717 | } |
| 3718 | if (i == 0) |
| 3719 | i = tx_ring->count - 1; |
| 3720 | else |
| 3721 | i = i - 1; |
| 3722 | tx_ring->tx_buffer_info[i].skb = skb; |
| 3723 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 3724 | |
| 3725 | return count; |
| 3726 | } |
| 3727 | |
| 3728 | static void ixgbe_tx_queue(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3729 | struct ixgbe_ring *tx_ring, |
| 3730 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3731 | { |
| 3732 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 3733 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 3734 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 3735 | unsigned int i; |
| 3736 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 3737 | |
| 3738 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 3739 | |
| 3740 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 3741 | |
| 3742 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 3743 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 3744 | |
| 3745 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 3746 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 3747 | |
| 3748 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3749 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3750 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 3751 | /* use index 1 context for tso */ |
| 3752 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3753 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 3754 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3755 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3756 | |
| 3757 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 3758 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3759 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3760 | |
| 3761 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 3762 | |
| 3763 | i = tx_ring->next_to_use; |
| 3764 | while (count--) { |
| 3765 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 3766 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 3767 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 3768 | tx_desc->read.cmd_type_len = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3769 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3770 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3771 | i++; |
| 3772 | if (i == tx_ring->count) |
| 3773 | i = 0; |
| 3774 | } |
| 3775 | |
| 3776 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 3777 | |
| 3778 | /* |
| 3779 | * Force memory writes to complete before letting h/w |
| 3780 | * know there are new descriptors to fetch. (Only |
| 3781 | * applicable for weak-ordered memory model archs, |
| 3782 | * such as IA-64). |
| 3783 | */ |
| 3784 | wmb(); |
| 3785 | |
| 3786 | tx_ring->next_to_use = i; |
| 3787 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
| 3788 | } |
| 3789 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 3790 | static int __ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3791 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 3792 | { |
| 3793 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3794 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 3795 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 3796 | /* Herbert's original patch had: |
| 3797 | * smp_mb__after_netif_stop_queue(); |
| 3798 | * but since that doesn't exist yet, just open code it. */ |
| 3799 | smp_mb(); |
| 3800 | |
| 3801 | /* We need to check again in a case another CPU has just |
| 3802 | * made room available. */ |
| 3803 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) |
| 3804 | return -EBUSY; |
| 3805 | |
| 3806 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Jesse Brandeburg | af72166 | 2008-09-11 19:54:23 -0700 | [diff] [blame] | 3807 | netif_start_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 3808 | ++adapter->restart_queue; |
| 3809 | return 0; |
| 3810 | } |
| 3811 | |
| 3812 | static int ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3813 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 3814 | { |
| 3815 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) |
| 3816 | return 0; |
| 3817 | return __ixgbe_maybe_stop_tx(netdev, tx_ring, size); |
| 3818 | } |
| 3819 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3820 | static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 3821 | { |
| 3822 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3823 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3824 | unsigned int first; |
| 3825 | unsigned int tx_flags = 0; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 3826 | u8 hdr_len = 0; |
| 3827 | int r_idx = 0, tso; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3828 | int count = 0; |
| 3829 | unsigned int f; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3830 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 3831 | r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 3832 | tx_ring = &adapter->tx_ring[r_idx]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3833 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3834 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 3835 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3836 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3837 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
| 3838 | tx_flags |= (skb->queue_mapping << 13); |
| 3839 | } |
| 3840 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 3841 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 3842 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3843 | tx_flags |= (skb->queue_mapping << 13); |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3844 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 3845 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3846 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3847 | /* three things can cause us to need a context descriptor */ |
| 3848 | if (skb_is_gso(skb) || |
| 3849 | (skb->ip_summed == CHECKSUM_PARTIAL) || |
| 3850 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3851 | count++; |
| 3852 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3853 | count += TXD_USE_COUNT(skb_headlen(skb)); |
| 3854 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3855 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 3856 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 3857 | if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3858 | adapter->tx_busy++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3859 | return NETDEV_TX_BUSY; |
| 3860 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3861 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 3862 | if (skb->protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3863 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
| 3864 | first = tx_ring->next_to_use; |
| 3865 | tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 3866 | if (tso < 0) { |
| 3867 | dev_kfree_skb_any(skb); |
| 3868 | return NETDEV_TX_OK; |
| 3869 | } |
| 3870 | |
| 3871 | if (tso) |
| 3872 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
| 3873 | else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) && |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3874 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3875 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 3876 | |
| 3877 | ixgbe_tx_queue(adapter, tx_ring, tx_flags, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3878 | ixgbe_tx_map(adapter, tx_ring, skb, first), |
| 3879 | skb->len, hdr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3880 | |
| 3881 | netdev->trans_start = jiffies; |
| 3882 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 3883 | ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3884 | |
| 3885 | return NETDEV_TX_OK; |
| 3886 | } |
| 3887 | |
| 3888 | /** |
| 3889 | * ixgbe_get_stats - Get System Network Statistics |
| 3890 | * @netdev: network interface device structure |
| 3891 | * |
| 3892 | * Returns the address of the device statistics structure. |
| 3893 | * The statistics are actually updated from the timer callback. |
| 3894 | **/ |
| 3895 | static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev) |
| 3896 | { |
| 3897 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3898 | |
| 3899 | /* only return the current stats */ |
| 3900 | return &adapter->net_stats; |
| 3901 | } |
| 3902 | |
| 3903 | /** |
| 3904 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 3905 | * @netdev: network interface device structure |
| 3906 | * @p: pointer to an address structure |
| 3907 | * |
| 3908 | * Returns 0 on success, negative on failure |
| 3909 | **/ |
| 3910 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 3911 | { |
| 3912 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3913 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3914 | struct sockaddr *addr = p; |
| 3915 | |
| 3916 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3917 | return -EADDRNOTAVAIL; |
| 3918 | |
| 3919 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3920 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3921 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3922 | 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] | 3923 | |
| 3924 | return 0; |
| 3925 | } |
| 3926 | |
| 3927 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3928 | /* |
| 3929 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 3930 | * without having to re-enable interrupts. It's not called while |
| 3931 | * the interrupt routine is executing. |
| 3932 | */ |
| 3933 | static void ixgbe_netpoll(struct net_device *netdev) |
| 3934 | { |
| 3935 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3936 | |
| 3937 | disable_irq(adapter->pdev->irq); |
| 3938 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
| 3939 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 3940 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
| 3941 | enable_irq(adapter->pdev->irq); |
| 3942 | } |
| 3943 | #endif |
| 3944 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 3945 | static const struct net_device_ops ixgbe_netdev_ops = { |
| 3946 | .ndo_open = ixgbe_open, |
| 3947 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 3948 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 3949 | .ndo_get_stats = ixgbe_get_stats, |
| 3950 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 3951 | .ndo_validate_addr = eth_validate_addr, |
| 3952 | .ndo_set_mac_address = ixgbe_set_mac, |
| 3953 | .ndo_change_mtu = ixgbe_change_mtu, |
| 3954 | .ndo_tx_timeout = ixgbe_tx_timeout, |
| 3955 | .ndo_vlan_rx_register = ixgbe_vlan_rx_register, |
| 3956 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 3957 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
| 3958 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3959 | .ndo_poll_controller = ixgbe_netpoll, |
| 3960 | #endif |
| 3961 | }; |
| 3962 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3963 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3964 | * ixgbe_probe - Device Initialization Routine |
| 3965 | * @pdev: PCI device information struct |
| 3966 | * @ent: entry in ixgbe_pci_tbl |
| 3967 | * |
| 3968 | * Returns 0 on success, negative on failure |
| 3969 | * |
| 3970 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 3971 | * The OS initialization, configuring of the adapter private structure, |
| 3972 | * and a hardware reset occur. |
| 3973 | **/ |
| 3974 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3975 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3976 | { |
| 3977 | struct net_device *netdev; |
| 3978 | struct ixgbe_adapter *adapter = NULL; |
| 3979 | struct ixgbe_hw *hw; |
| 3980 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3981 | static int cards_found; |
| 3982 | int i, err, pci_using_dac; |
| 3983 | u16 link_status, link_speed, link_width; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3984 | u32 part_num, eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3985 | |
| 3986 | err = pci_enable_device(pdev); |
| 3987 | if (err) |
| 3988 | return err; |
| 3989 | |
| 3990 | if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) && |
| 3991 | !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) { |
| 3992 | pci_using_dac = 1; |
| 3993 | } else { |
| 3994 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 3995 | if (err) { |
| 3996 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 3997 | if (err) { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3998 | dev_err(&pdev->dev, "No usable DMA " |
| 3999 | "configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4000 | goto err_dma; |
| 4001 | } |
| 4002 | } |
| 4003 | pci_using_dac = 0; |
| 4004 | } |
| 4005 | |
| 4006 | err = pci_request_regions(pdev, ixgbe_driver_name); |
| 4007 | if (err) { |
| 4008 | dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err); |
| 4009 | goto err_pci_reg; |
| 4010 | } |
| 4011 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4012 | err = pci_enable_pcie_error_reporting(pdev); |
| 4013 | if (err) { |
| 4014 | dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed " |
| 4015 | "0x%x\n", err); |
| 4016 | /* non-fatal, continue */ |
| 4017 | } |
| 4018 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4019 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 4020 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4021 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 4022 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4023 | if (!netdev) { |
| 4024 | err = -ENOMEM; |
| 4025 | goto err_alloc_etherdev; |
| 4026 | } |
| 4027 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4028 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 4029 | |
| 4030 | pci_set_drvdata(pdev, netdev); |
| 4031 | adapter = netdev_priv(netdev); |
| 4032 | |
| 4033 | adapter->netdev = netdev; |
| 4034 | adapter->pdev = pdev; |
| 4035 | hw = &adapter->hw; |
| 4036 | hw->back = adapter; |
| 4037 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 4038 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 4039 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 4040 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4041 | if (!hw->hw_addr) { |
| 4042 | err = -EIO; |
| 4043 | goto err_ioremap; |
| 4044 | } |
| 4045 | |
| 4046 | for (i = 1; i <= 5; i++) { |
| 4047 | if (pci_resource_len(pdev, i) == 0) |
| 4048 | continue; |
| 4049 | } |
| 4050 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 4051 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4052 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4053 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4054 | strcpy(netdev->name, pci_name(pdev)); |
| 4055 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4056 | adapter->bd_number = cards_found; |
| 4057 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4058 | /* Setup hw api */ |
| 4059 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4060 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4061 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4062 | /* EEPROM */ |
| 4063 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 4064 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 4065 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 4066 | if (!(eec & (1 << 8))) |
| 4067 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 4068 | |
| 4069 | /* PHY */ |
| 4070 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4071 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
| 4072 | |
| 4073 | /* set up this timer and work struct before calling get_invariants |
| 4074 | * which might start the timer |
| 4075 | */ |
| 4076 | init_timer(&adapter->sfp_timer); |
| 4077 | adapter->sfp_timer.function = &ixgbe_sfp_timer; |
| 4078 | adapter->sfp_timer.data = (unsigned long) adapter; |
| 4079 | |
| 4080 | INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4081 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4082 | err = ii->get_invariants(hw); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4083 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 4084 | /* start a kernel thread to watch for a module to arrive */ |
| 4085 | set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 4086 | mod_timer(&adapter->sfp_timer, |
| 4087 | round_jiffies(jiffies + (2 * HZ))); |
| 4088 | err = 0; |
| 4089 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
| 4090 | DPRINTK(PROBE, ERR, "failed to load because an " |
| 4091 | "unsupported SFP+ module type was detected.\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4092 | goto err_hw_init; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4093 | } else if (err) { |
| 4094 | goto err_hw_init; |
| 4095 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4096 | |
| 4097 | /* setup the private structure */ |
| 4098 | err = ixgbe_sw_init(adapter); |
| 4099 | if (err) |
| 4100 | goto err_sw_init; |
| 4101 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4102 | /* reset_hw fills in the perm_addr as well */ |
| 4103 | err = hw->mac.ops.reset_hw(hw); |
| 4104 | if (err) { |
| 4105 | dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err); |
| 4106 | goto err_sw_init; |
| 4107 | } |
| 4108 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4109 | netdev->features = NETIF_F_SG | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4110 | NETIF_F_IP_CSUM | |
| 4111 | NETIF_F_HW_VLAN_TX | |
| 4112 | NETIF_F_HW_VLAN_RX | |
| 4113 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4114 | |
Jesse Brandeburg | e9990a9 | 2008-08-26 04:27:24 -0700 | [diff] [blame] | 4115 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4116 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4117 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 4118 | netdev->features |= NETIF_F_GRO; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 4119 | |
| 4120 | netdev->vlan_features |= NETIF_F_TSO; |
| 4121 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 4122 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 4123 | netdev->vlan_features |= NETIF_F_SG; |
| 4124 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4125 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 4126 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
| 4127 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4128 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4129 | netdev->dcbnl_ops = &dcbnl_ops; |
| 4130 | #endif |
| 4131 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4132 | if (pci_using_dac) |
| 4133 | netdev->features |= NETIF_F_HIGHDMA; |
| 4134 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4135 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4136 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4137 | dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); |
| 4138 | err = -EIO; |
| 4139 | goto err_eeprom; |
| 4140 | } |
| 4141 | |
| 4142 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 4143 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 4144 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4145 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
| 4146 | dev_err(&pdev->dev, "invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4147 | err = -EIO; |
| 4148 | goto err_eeprom; |
| 4149 | } |
| 4150 | |
| 4151 | init_timer(&adapter->watchdog_timer); |
| 4152 | adapter->watchdog_timer.function = &ixgbe_watchdog; |
| 4153 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 4154 | |
| 4155 | INIT_WORK(&adapter->reset_task, ixgbe_reset_task); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4156 | INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4157 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4158 | err = ixgbe_init_interrupt_scheme(adapter); |
| 4159 | if (err) |
| 4160 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4161 | |
| 4162 | /* print bus type/speed/width info */ |
| 4163 | pci_read_config_word(pdev, IXGBE_PCI_LINK_STATUS, &link_status); |
| 4164 | link_speed = link_status & IXGBE_PCI_LINK_SPEED; |
| 4165 | link_width = link_status & IXGBE_PCI_LINK_WIDTH; |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 4166 | dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n", |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4167 | ((link_speed == IXGBE_PCI_LINK_SPEED_5000) ? "5.0Gb/s" : |
| 4168 | (link_speed == IXGBE_PCI_LINK_SPEED_2500) ? "2.5Gb/s" : |
| 4169 | "Unknown"), |
| 4170 | ((link_width == IXGBE_PCI_LINK_WIDTH_8) ? "Width x8" : |
| 4171 | (link_width == IXGBE_PCI_LINK_WIDTH_4) ? "Width x4" : |
| 4172 | (link_width == IXGBE_PCI_LINK_WIDTH_2) ? "Width x2" : |
| 4173 | (link_width == IXGBE_PCI_LINK_WIDTH_1) ? "Width x1" : |
| 4174 | "Unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 4175 | netdev->dev_addr); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4176 | ixgbe_read_pba_num_generic(hw, &part_num); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4177 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4178 | hw->mac.type, hw->phy.type, |
| 4179 | (part_num >> 8), (part_num & 0xff)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4180 | |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 4181 | if (link_width <= IXGBE_PCI_LINK_WIDTH_4) { |
| 4182 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4183 | "this card is not sufficient for optimal " |
| 4184 | "performance.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 4185 | dev_warn(&pdev->dev, "For optimal performance a x8 " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4186 | "PCI-Express slot is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 4187 | } |
| 4188 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 4189 | /* save off EEPROM version number */ |
| 4190 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 4191 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4192 | /* reset the hardware with the new settings */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4193 | hw->mac.ops.start_hw(hw); |
| 4194 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4195 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4196 | |
| 4197 | strcpy(netdev->name, "eth%d"); |
| 4198 | err = register_netdev(netdev); |
| 4199 | if (err) |
| 4200 | goto err_register; |
| 4201 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4202 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 4203 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4204 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
| 4205 | /* always use CB2 mode, difference is masked |
| 4206 | * in the CB driver */ |
| 4207 | IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2); |
| 4208 | ixgbe_setup_dca(adapter); |
| 4209 | } |
| 4210 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4211 | |
| 4212 | dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n"); |
| 4213 | cards_found++; |
| 4214 | return 0; |
| 4215 | |
| 4216 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4217 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4218 | err_hw_init: |
| 4219 | err_sw_init: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4220 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4221 | err_eeprom: |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4222 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 4223 | del_timer_sync(&adapter->sfp_timer); |
| 4224 | cancel_work_sync(&adapter->sfp_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4225 | iounmap(hw->hw_addr); |
| 4226 | err_ioremap: |
| 4227 | free_netdev(netdev); |
| 4228 | err_alloc_etherdev: |
| 4229 | pci_release_regions(pdev); |
| 4230 | err_pci_reg: |
| 4231 | err_dma: |
| 4232 | pci_disable_device(pdev); |
| 4233 | return err; |
| 4234 | } |
| 4235 | |
| 4236 | /** |
| 4237 | * ixgbe_remove - Device Removal Routine |
| 4238 | * @pdev: PCI device information struct |
| 4239 | * |
| 4240 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 4241 | * that it should release a PCI device. The could be caused by a |
| 4242 | * Hot-Plug event, or because the driver is going to be removed from |
| 4243 | * memory. |
| 4244 | **/ |
| 4245 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 4246 | { |
| 4247 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4248 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4249 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4250 | |
| 4251 | set_bit(__IXGBE_DOWN, &adapter->state); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4252 | /* clear the module not found bit to make sure the worker won't |
| 4253 | * reschedule |
| 4254 | */ |
| 4255 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4256 | del_timer_sync(&adapter->watchdog_timer); |
| 4257 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4258 | del_timer_sync(&adapter->sfp_timer); |
| 4259 | cancel_work_sync(&adapter->watchdog_task); |
| 4260 | cancel_work_sync(&adapter->sfp_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4261 | flush_scheduled_work(); |
| 4262 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4263 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4264 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 4265 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 4266 | dca_remove_requester(&pdev->dev); |
| 4267 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 4268 | } |
| 4269 | |
| 4270 | #endif |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4271 | if (netdev->reg_state == NETREG_REGISTERED) |
| 4272 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4273 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4274 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4275 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4276 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4277 | |
| 4278 | iounmap(adapter->hw.hw_addr); |
| 4279 | pci_release_regions(pdev); |
| 4280 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4281 | DPRINTK(PROBE, INFO, "complete\n"); |
| 4282 | kfree(adapter->tx_ring); |
| 4283 | kfree(adapter->rx_ring); |
| 4284 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4285 | free_netdev(netdev); |
| 4286 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4287 | err = pci_disable_pcie_error_reporting(pdev); |
| 4288 | if (err) |
| 4289 | dev_err(&pdev->dev, |
| 4290 | "pci_disable_pcie_error_reporting failed 0x%x\n", err); |
| 4291 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4292 | pci_disable_device(pdev); |
| 4293 | } |
| 4294 | |
| 4295 | /** |
| 4296 | * ixgbe_io_error_detected - called when PCI error is detected |
| 4297 | * @pdev: Pointer to PCI device |
| 4298 | * @state: The current pci connection state |
| 4299 | * |
| 4300 | * This function is called after a PCI bus error affecting |
| 4301 | * this device has been detected. |
| 4302 | */ |
| 4303 | 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] | 4304 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4305 | { |
| 4306 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4307 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4308 | |
| 4309 | netif_device_detach(netdev); |
| 4310 | |
| 4311 | if (netif_running(netdev)) |
| 4312 | ixgbe_down(adapter); |
| 4313 | pci_disable_device(pdev); |
| 4314 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4315 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4316 | return PCI_ERS_RESULT_NEED_RESET; |
| 4317 | } |
| 4318 | |
| 4319 | /** |
| 4320 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 4321 | * @pdev: Pointer to PCI device |
| 4322 | * |
| 4323 | * Restart the card from scratch, as if from a cold-boot. |
| 4324 | */ |
| 4325 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 4326 | { |
| 4327 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4328 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4329 | pci_ers_result_t result; |
| 4330 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4331 | |
| 4332 | if (pci_enable_device(pdev)) { |
| 4333 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4334 | "Cannot re-enable PCI device after reset.\n"); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4335 | result = PCI_ERS_RESULT_DISCONNECT; |
| 4336 | } else { |
| 4337 | pci_set_master(pdev); |
| 4338 | pci_restore_state(pdev); |
| 4339 | |
| 4340 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 4341 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 4342 | |
| 4343 | ixgbe_reset(adapter); |
| 4344 | |
| 4345 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4346 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4347 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4348 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 4349 | if (err) { |
| 4350 | dev_err(&pdev->dev, |
| 4351 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err); |
| 4352 | /* non-fatal, continue */ |
| 4353 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4354 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4355 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4356 | } |
| 4357 | |
| 4358 | /** |
| 4359 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 4360 | * @pdev: Pointer to PCI device |
| 4361 | * |
| 4362 | * This callback is called when the error recovery driver tells us that |
| 4363 | * its OK to resume normal operation. |
| 4364 | */ |
| 4365 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 4366 | { |
| 4367 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4368 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4369 | |
| 4370 | if (netif_running(netdev)) { |
| 4371 | if (ixgbe_up(adapter)) { |
| 4372 | DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n"); |
| 4373 | return; |
| 4374 | } |
| 4375 | } |
| 4376 | |
| 4377 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | static struct pci_error_handlers ixgbe_err_handler = { |
| 4381 | .error_detected = ixgbe_io_error_detected, |
| 4382 | .slot_reset = ixgbe_io_slot_reset, |
| 4383 | .resume = ixgbe_io_resume, |
| 4384 | }; |
| 4385 | |
| 4386 | static struct pci_driver ixgbe_driver = { |
| 4387 | .name = ixgbe_driver_name, |
| 4388 | .id_table = ixgbe_pci_tbl, |
| 4389 | .probe = ixgbe_probe, |
| 4390 | .remove = __devexit_p(ixgbe_remove), |
| 4391 | #ifdef CONFIG_PM |
| 4392 | .suspend = ixgbe_suspend, |
| 4393 | .resume = ixgbe_resume, |
| 4394 | #endif |
| 4395 | .shutdown = ixgbe_shutdown, |
| 4396 | .err_handler = &ixgbe_err_handler |
| 4397 | }; |
| 4398 | |
| 4399 | /** |
| 4400 | * ixgbe_init_module - Driver Registration Routine |
| 4401 | * |
| 4402 | * ixgbe_init_module is the first routine called when the driver is |
| 4403 | * loaded. All it does is register with the PCI subsystem. |
| 4404 | **/ |
| 4405 | static int __init ixgbe_init_module(void) |
| 4406 | { |
| 4407 | int ret; |
| 4408 | printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name, |
| 4409 | ixgbe_driver_string, ixgbe_driver_version); |
| 4410 | |
| 4411 | printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright); |
| 4412 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4413 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4414 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4415 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4416 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4417 | ret = pci_register_driver(&ixgbe_driver); |
| 4418 | return ret; |
| 4419 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4420 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4421 | module_init(ixgbe_init_module); |
| 4422 | |
| 4423 | /** |
| 4424 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 4425 | * |
| 4426 | * ixgbe_exit_module is called just before the driver is removed |
| 4427 | * from memory. |
| 4428 | **/ |
| 4429 | static void __exit ixgbe_exit_module(void) |
| 4430 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4431 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4432 | dca_unregister_notify(&dca_notifier); |
| 4433 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4434 | pci_unregister_driver(&ixgbe_driver); |
| 4435 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4436 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4437 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4438 | 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] | 4439 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4440 | { |
| 4441 | int ret_val; |
| 4442 | |
| 4443 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4444 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4445 | |
| 4446 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 4447 | } |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4448 | #endif /* CONFIG_IXGBE_DCA */ |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4449 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4450 | module_exit(ixgbe_exit_module); |
| 4451 | |
| 4452 | /* ixgbe_main.c */ |