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