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