blob: ae2af45eb8f1a3dcff6ccd93ba58b2f6d8ceebbe [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Peter P Waskiewicz Jr3efac5a2009-02-01 01:19:20 -08004 Copyright(c) 1999 - 2009 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
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 Kok9a799d72007-09-15 14:07:45 -070023 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
46char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070047static const char ixgbe_driver_string[] =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070048 "Intel(R) 10 Gigabit PCI Express Network Driver";
Auke Kok9a799d72007-09-15 14:07:45 -070049
PJ Waskiewicze8e26352009-02-27 15:45:05 +000050#define DRV_VERSION "2.0.8-k2"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070051const char ixgbe_driver_version[] = DRV_VERSION;
Peter P Waskiewicz Jr3efac5a2009-02-01 01:19:20 -080052static char ixgbe_copyright[] = "Copyright (c) 1999-2009 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070053
54static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070055 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000056 [board_82599] = &ixgbe_82599_info,
Auke Kok9a799d72007-09-15 14:07:45 -070057};
58
59/* ixgbe_pci_tbl - PCI Device ID Table
60 *
61 * Wildcard entries (PCI_ANY_ID) should come last
62 * Last entry must be all 0s
63 *
64 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
65 * Class, Class Mask, private data (not used) }
66 */
67static struct pci_device_id ixgbe_pci_tbl[] = {
Don Skidmore1e336d02009-01-26 20:57:51 -080068 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
69 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070070 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070071 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070072 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070073 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070074 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
75 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070076 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070077 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070078 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
79 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080080 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
81 board_82598 },
82 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
83 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070084 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
85 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080086 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
87 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -080088 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
89 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +000090 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
91 board_82599 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
93 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -070094
95 /* required last entry */
96 {0, }
97};
98MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
99
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400100#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800101static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700102 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800103static struct notifier_block dca_notifier = {
104 .notifier_call = ixgbe_notify_dca,
105 .next = NULL,
106 .priority = 0
107};
108#endif
109
Auke Kok9a799d72007-09-15 14:07:45 -0700110MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
111MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
112MODULE_LICENSE("GPL");
113MODULE_VERSION(DRV_VERSION);
114
115#define DEFAULT_DEBUG_LEVEL_SHIFT 3
116
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800117static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
118{
119 u32 ctrl_ext;
120
121 /* Let firmware take over control of h/w */
122 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
123 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700124 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800125}
126
127static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
128{
129 u32 ctrl_ext;
130
131 /* Let firmware know the driver has taken over */
132 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
133 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700134 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800135}
Auke Kok9a799d72007-09-15 14:07:45 -0700136
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000137/*
138 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
139 * @adapter: pointer to adapter struct
140 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
141 * @queue: queue to map the corresponding interrupt to
142 * @msix_vector: the vector to map to the corresponding queue
143 *
144 */
145static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
146 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700147{
148 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000149 struct ixgbe_hw *hw = &adapter->hw;
150 switch (hw->mac.type) {
151 case ixgbe_mac_82598EB:
152 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
153 if (direction == -1)
154 direction = 0;
155 index = (((direction * 64) + queue) >> 2) & 0x1F;
156 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
157 ivar &= ~(0xFF << (8 * (queue & 0x3)));
158 ivar |= (msix_vector << (8 * (queue & 0x3)));
159 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
160 break;
161 case ixgbe_mac_82599EB:
162 if (direction == -1) {
163 /* other causes */
164 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
165 index = ((queue & 1) * 8);
166 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
167 ivar &= ~(0xFF << index);
168 ivar |= (msix_vector << index);
169 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
170 break;
171 } else {
172 /* tx or rx causes */
173 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
174 index = ((16 * (queue & 1)) + (8 * direction));
175 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
176 ivar &= ~(0xFF << index);
177 ivar |= (msix_vector << index);
178 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
179 break;
180 }
181 default:
182 break;
183 }
Auke Kok9a799d72007-09-15 14:07:45 -0700184}
185
186static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700187 struct ixgbe_tx_buffer
188 *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700189{
Alexander Duyck44df32c2009-03-31 21:34:23 +0000190 tx_buffer_info->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700191 if (tx_buffer_info->skb) {
Alexander Duyck44df32c2009-03-31 21:34:23 +0000192 skb_dma_unmap(&adapter->pdev->dev, tx_buffer_info->skb,
193 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700194 dev_kfree_skb_any(tx_buffer_info->skb);
195 tx_buffer_info->skb = NULL;
196 }
Alexander Duyck44df32c2009-03-31 21:34:23 +0000197 tx_buffer_info->time_stamp = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700198 /* tx_buffer_info must be completely set up in the transmit path */
199}
200
201static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700202 struct ixgbe_ring *tx_ring,
203 unsigned int eop)
Auke Kok9a799d72007-09-15 14:07:45 -0700204{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700205 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700206
Auke Kok9a799d72007-09-15 14:07:45 -0700207 /* Detect a transmit hang in hardware, this serializes the
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700208 * check with the clearing of time_stamp and movement of eop */
Auke Kok9a799d72007-09-15 14:07:45 -0700209 adapter->detect_tx_hung = false;
Alexander Duyck44df32c2009-03-31 21:34:23 +0000210 if (tx_ring->tx_buffer_info[eop].time_stamp &&
Auke Kok9a799d72007-09-15 14:07:45 -0700211 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
212 !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) {
213 /* detected Tx unit hang */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700214 union ixgbe_adv_tx_desc *tx_desc;
215 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
Auke Kok9a799d72007-09-15 14:07:45 -0700216 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700217 " Tx Queue <%d>\n"
218 " TDH, TDT <%x>, <%x>\n"
Auke Kok9a799d72007-09-15 14:07:45 -0700219 " next_to_use <%x>\n"
220 " next_to_clean <%x>\n"
221 "tx_buffer_info[next_to_clean]\n"
222 " time_stamp <%lx>\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700223 " jiffies <%lx>\n",
224 tx_ring->queue_index,
Alexander Duyck44df32c2009-03-31 21:34:23 +0000225 IXGBE_READ_REG(hw, tx_ring->head),
226 IXGBE_READ_REG(hw, tx_ring->tail),
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700227 tx_ring->next_to_use, eop,
228 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
Auke Kok9a799d72007-09-15 14:07:45 -0700229 return true;
230 }
231
232 return false;
233}
234
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700235#define IXGBE_MAX_TXD_PWR 14
236#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800237
238/* Tx Descriptors needed, worst case */
239#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
240 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
241#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700242 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800243
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700244static void ixgbe_tx_timeout(struct net_device *netdev);
245
Auke Kok9a799d72007-09-15 14:07:45 -0700246/**
247 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
248 * @adapter: board private structure
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700249 * @tx_ring: tx ring to clean
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000250 *
251 * returns true if transmit work is done
Auke Kok9a799d72007-09-15 14:07:45 -0700252 **/
253static bool ixgbe_clean_tx_irq(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700254 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700255{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700256 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800257 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
258 struct ixgbe_tx_buffer *tx_buffer_info;
259 unsigned int i, eop, count = 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700260 unsigned int total_bytes = 0, total_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700261
262 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800263 eop = tx_ring->tx_buffer_info[i].next_to_watch;
264 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
265
266 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000267 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800268 bool cleaned = false;
269 for ( ; !cleaned; count++) {
270 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700271 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
272 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800273 cleaned = (i == eop);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700274 skb = tx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700275
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800276 if (cleaned && skb) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800277 unsigned int segs, bytecount;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700278
279 /* gso_segs is currently only valid for tcp */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800280 segs = skb_shinfo(skb)->gso_segs ?: 1;
281 /* multiply data chunks by size of headers */
282 bytecount = ((segs - 1) * skb_headlen(skb)) +
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700283 skb->len;
284 total_packets += segs;
285 total_bytes += bytecount;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800286 }
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700287
Auke Kok9a799d72007-09-15 14:07:45 -0700288 ixgbe_unmap_and_free_tx_resource(adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700289 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700290
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800291 tx_desc->wb.status = 0;
292
Auke Kok9a799d72007-09-15 14:07:45 -0700293 i++;
294 if (i == tx_ring->count)
295 i = 0;
296 }
297
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800298 eop = tx_ring->tx_buffer_info[i].next_to_watch;
299 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
300 }
301
Auke Kok9a799d72007-09-15 14:07:45 -0700302 tx_ring->next_to_clean = i;
303
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800304#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700305 if (unlikely(count && netif_carrier_ok(netdev) &&
306 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800307 /* Make sure that anybody stopping the queue after this
308 * sees the new next_to_clean.
309 */
310 smp_mb();
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800311 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
312 !test_bit(__IXGBE_DOWN, &adapter->state)) {
313 netif_wake_subqueue(netdev, tx_ring->queue_index);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700314 ++adapter->restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800315 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800316 }
Auke Kok9a799d72007-09-15 14:07:45 -0700317
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700318 if (adapter->detect_tx_hung) {
319 if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
320 /* schedule immediate reset if we believe we hung */
321 DPRINTK(PROBE, INFO,
322 "tx hang %d detected, resetting adapter\n",
323 adapter->tx_timeout_count + 1);
324 ixgbe_tx_timeout(adapter->netdev);
325 }
326 }
Auke Kok9a799d72007-09-15 14:07:45 -0700327
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700328 /* re-arm the interrupt */
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000329 if (count >= tx_ring->work_limit)
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700330 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, tx_ring->v_idx);
Auke Kok9a799d72007-09-15 14:07:45 -0700331
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700332 tx_ring->total_bytes += total_bytes;
333 tx_ring->total_packets += total_packets;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700334 tx_ring->stats.packets += total_packets;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800335 tx_ring->stats.bytes += total_bytes;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700336 adapter->net_stats.tx_bytes += total_bytes;
337 adapter->net_stats.tx_packets += total_packets;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000338 return (count < tx_ring->work_limit);
Auke Kok9a799d72007-09-15 14:07:45 -0700339}
340
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400341#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800342static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700343 struct ixgbe_ring *rx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800344{
345 u32 rxctrl;
346 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700347 int q = rx_ring - adapter->rx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800348
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700349 if (rx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800350 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000351 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
352 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
353 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
354 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
355 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
356 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
357 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
358 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800359 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
360 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
Don Skidmore15005a32009-01-19 16:54:13 -0800361 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
362 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000363 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800364 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700365 rx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800366 }
367 put_cpu();
368}
369
370static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700371 struct ixgbe_ring *tx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800372{
373 u32 txctrl;
374 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700375 int q = tx_ring - adapter->tx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800376
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700377 if (tx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800378 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000379 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
380 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
381 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
382 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
383 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
384 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
385 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
386 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800387 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
388 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700389 tx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800390 }
391 put_cpu();
392}
393
394static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
395{
396 int i;
397
398 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
399 return;
400
401 for (i = 0; i < adapter->num_tx_queues; i++) {
402 adapter->tx_ring[i].cpu = -1;
403 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
404 }
405 for (i = 0; i < adapter->num_rx_queues; i++) {
406 adapter->rx_ring[i].cpu = -1;
407 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
408 }
409}
410
411static int __ixgbe_notify_dca(struct device *dev, void *data)
412{
413 struct net_device *netdev = dev_get_drvdata(dev);
414 struct ixgbe_adapter *adapter = netdev_priv(netdev);
415 unsigned long event = *(unsigned long *)data;
416
417 switch (event) {
418 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700419 /* if we're already enabled, don't do it again */
420 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
421 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800422 /* Always use CB2 mode, difference is masked
423 * in the CB driver. */
424 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
Denis V. Lunev652f0932008-03-27 14:39:17 +0300425 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700426 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800427 ixgbe_setup_dca(adapter);
428 break;
429 }
430 /* Fall Through since DCA is disabled. */
431 case DCA_PROVIDER_REMOVE:
432 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
433 dca_remove_requester(dev);
434 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
435 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
436 }
437 break;
438 }
439
Denis V. Lunev652f0932008-03-27 14:39:17 +0300440 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800441}
442
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400443#endif /* CONFIG_IXGBE_DCA */
Auke Kok9a799d72007-09-15 14:07:45 -0700444/**
445 * ixgbe_receive_skb - Send a completed packet up the stack
446 * @adapter: board private structure
447 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700448 * @status: hardware indication of status of receive
449 * @rx_ring: rx descriptor ring (for a specific queue) to setup
450 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -0700451 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800452static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700453 struct sk_buff *skb, u8 status,
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700454 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -0700455{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800456 struct ixgbe_adapter *adapter = q_vector->adapter;
457 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700458 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
459 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -0700460
David S. Miller0c8dfc82009-01-27 16:22:32 -0800461 skb_record_rx_queue(skb, q_vector - &adapter->q_vector[0]);
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800462 if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800463 if (adapter->vlgrp && is_vlan && (tag != 0))
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800464 vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700465 else
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800466 napi_gro_receive(napi, skb);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700467 } else {
468 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800469 if (adapter->vlgrp && is_vlan && (tag != 0))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700470 vlan_hwaccel_receive_skb(skb, adapter->vlgrp, tag);
471 else
472 netif_receive_skb(skb);
473 } else {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800474 if (adapter->vlgrp && is_vlan && (tag != 0))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700475 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
476 else
477 netif_rx(skb);
478 }
Auke Kok9a799d72007-09-15 14:07:45 -0700479 }
480}
481
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800482/**
483 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
484 * @adapter: address of board private structure
485 * @status_err: hardware indication of status of receive
486 * @skb: skb currently being received and modified
487 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700488static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700489 u32 status_err, struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700490{
491 skb->ip_summed = CHECKSUM_NONE;
492
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700493 /* Rx csum disabled */
494 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -0700495 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800496
497 /* if IP and error */
498 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
499 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700500 adapter->hw_csum_rx_error++;
501 return;
502 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800503
504 if (!(status_err & IXGBE_RXD_STAT_L4CS))
505 return;
506
507 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
508 adapter->hw_csum_rx_error++;
509 return;
510 }
511
Auke Kok9a799d72007-09-15 14:07:45 -0700512 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800513 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -0700514 adapter->hw_csum_rx_good++;
515}
516
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000517static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
518 struct ixgbe_ring *rx_ring, u32 val)
519{
520 /*
521 * Force memory writes to complete before letting h/w
522 * know there are new descriptors to fetch. (Only
523 * applicable for weak-ordered memory model archs,
524 * such as IA-64).
525 */
526 wmb();
527 IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
528}
529
Auke Kok9a799d72007-09-15 14:07:45 -0700530/**
531 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
532 * @adapter: address of board private structure
533 **/
534static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700535 struct ixgbe_ring *rx_ring,
536 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700537{
Auke Kok9a799d72007-09-15 14:07:45 -0700538 struct pci_dev *pdev = adapter->pdev;
539 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700540 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700541 unsigned int i;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000542 unsigned int bufsz = rx_ring->rx_buf_len + NET_IP_ALIGN;
Auke Kok9a799d72007-09-15 14:07:45 -0700543
544 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700545 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700546
547 while (cleaned_count--) {
548 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
549
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700550 if (!bi->page_dma &&
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700551 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700552 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700553 bi->page = alloc_page(GFP_ATOMIC);
554 if (!bi->page) {
555 adapter->alloc_rx_page_failed++;
556 goto no_buffers;
557 }
558 bi->page_offset = 0;
559 } else {
560 /* use a half page if we're re-using */
561 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700562 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700563
564 bi->page_dma = pci_map_page(pdev, bi->page,
565 bi->page_offset,
566 (PAGE_SIZE / 2),
567 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700568 }
569
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700570 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800571 struct sk_buff *skb;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000572 skb = netdev_alloc_skb(adapter->netdev, bufsz);
Auke Kok9a799d72007-09-15 14:07:45 -0700573
574 if (!skb) {
575 adapter->alloc_rx_buff_failed++;
576 goto no_buffers;
577 }
578
579 /*
580 * Make buffer alignment 2 beyond a 16 byte boundary
581 * this will result in a 16 byte aligned IP header after
582 * the 14 byte MAC header is removed
583 */
584 skb_reserve(skb, NET_IP_ALIGN);
585
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700586 bi->skb = skb;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000587 bi->dma = pci_map_single(pdev, skb->data, bufsz,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700588 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700589 }
590 /* Refresh the desc even if buffer_addrs didn't change because
591 * each write-back erases this info. */
592 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700593 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
594 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700595 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700596 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700597 }
598
599 i++;
600 if (i == rx_ring->count)
601 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700602 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700603 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700604
Auke Kok9a799d72007-09-15 14:07:45 -0700605no_buffers:
606 if (rx_ring->next_to_use != i) {
607 rx_ring->next_to_use = i;
608 if (i-- == 0)
609 i = (rx_ring->count - 1);
610
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000611 ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700612 }
613}
614
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700615static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
616{
617 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
618}
619
620static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
621{
622 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
623}
624
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800625static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700626 struct ixgbe_ring *rx_ring,
627 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700628{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800629 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -0700630 struct pci_dev *pdev = adapter->pdev;
631 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
632 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
633 struct sk_buff *skb;
634 unsigned int i;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700635 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700636 u16 hdr_info;
637 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700638 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800639 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700640
641 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700642 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
643 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
644 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700645
646 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700647 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700648 if (*work_done >= work_to_do)
649 break;
650 (*work_done)++;
651
652 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700653 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
654 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700655 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700656 if (hdr_info & IXGBE_RXDADV_SPH)
657 adapter->rx_hdr_split++;
658 if (len > IXGBE_RX_HDR_SIZE)
659 len = IXGBE_RX_HDR_SIZE;
660 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700661 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700662 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700663 }
Auke Kok9a799d72007-09-15 14:07:45 -0700664
665 cleaned = true;
666 skb = rx_buffer_info->skb;
667 prefetch(skb->data - NET_IP_ALIGN);
668 rx_buffer_info->skb = NULL;
669
670 if (len && !skb_shinfo(skb)->nr_frags) {
671 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800672 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700673 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700674 skb_put(skb, len);
675 }
676
677 if (upper_len) {
678 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700679 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700680 rx_buffer_info->page_dma = 0;
681 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700682 rx_buffer_info->page,
683 rx_buffer_info->page_offset,
684 upper_len);
685
686 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
687 (page_count(rx_buffer_info->page) != 1))
688 rx_buffer_info->page = NULL;
689 else
690 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700691
692 skb->len += upper_len;
693 skb->data_len += upper_len;
694 skb->truesize += upper_len;
695 }
696
697 i++;
698 if (i == rx_ring->count)
699 i = 0;
700 next_buffer = &rx_ring->rx_buffer_info[i];
701
702 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
703 prefetch(next_rxd);
704
705 cleaned_count++;
706 if (staterr & IXGBE_RXD_STAT_EOP) {
707 rx_ring->stats.packets++;
708 rx_ring->stats.bytes += skb->len;
709 } else {
710 rx_buffer_info->skb = next_buffer->skb;
711 rx_buffer_info->dma = next_buffer->dma;
712 next_buffer->skb = skb;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700713 next_buffer->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700714 adapter->non_eop_descs++;
715 goto next_desc;
716 }
717
718 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
719 dev_kfree_skb_irq(skb);
720 goto next_desc;
721 }
722
723 ixgbe_rx_checksum(adapter, staterr, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800724
725 /* probably a little skewed due to removing CRC */
726 total_rx_bytes += skb->len;
727 total_rx_packets++;
728
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700729 skb->protocol = eth_type_trans(skb, adapter->netdev);
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800730 ixgbe_receive_skb(q_vector, skb, staterr, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700731
732next_desc:
733 rx_desc->wb.upper.status_error = 0;
734
735 /* return some buffers to hardware, one at a time is too slow */
736 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
737 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
738 cleaned_count = 0;
739 }
740
741 /* use prefetched values */
742 rx_desc = next_rxd;
743 rx_buffer_info = next_buffer;
744
745 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700746 }
747
Auke Kok9a799d72007-09-15 14:07:45 -0700748 rx_ring->next_to_clean = i;
749 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
750
751 if (cleaned_count)
752 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
753
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800754 rx_ring->total_packets += total_rx_packets;
755 rx_ring->total_bytes += total_rx_bytes;
756 adapter->net_stats.rx_bytes += total_rx_bytes;
757 adapter->net_stats.rx_packets += total_rx_packets;
758
Auke Kok9a799d72007-09-15 14:07:45 -0700759 return cleaned;
760}
761
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800762static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700763/**
764 * ixgbe_configure_msix - Configure MSI-X hardware
765 * @adapter: board private structure
766 *
767 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
768 * interrupts.
769 **/
770static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
771{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800772 struct ixgbe_q_vector *q_vector;
773 int i, j, q_vectors, v_idx, r_idx;
774 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700775
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800776 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
777
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000778 /*
779 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800780 * corresponding register.
781 */
782 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
783 q_vector = &adapter->q_vector[v_idx];
784 /* XXX for_each_bit(...) */
785 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700786 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800787
788 for (i = 0; i < q_vector->rxr_count; i++) {
789 j = adapter->rx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000790 ixgbe_set_ivar(adapter, 0, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800791 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700792 adapter->num_rx_queues,
793 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800794 }
795 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700796 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800797
798 for (i = 0; i < q_vector->txr_count; i++) {
799 j = adapter->tx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000800 ixgbe_set_ivar(adapter, 1, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800801 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700802 adapter->num_tx_queues,
803 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800804 }
805
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700806 /* if this is a tx only vector halve the interrupt rate */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800807 if (q_vector->txr_count && !q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700808 q_vector->eitr = (adapter->eitr_param >> 1);
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000809 else if (q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700810 /* rx only */
811 q_vector->eitr = adapter->eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800812
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000813 /*
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000814 * since this is initial set up don't need to call
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000815 * ixgbe_write_eitr helper
816 */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800817 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx),
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700818 EITR_INTS_PER_SEC_TO_REG(q_vector->eitr));
Auke Kok9a799d72007-09-15 14:07:45 -0700819 }
820
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000821 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
822 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
823 v_idx);
824 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
825 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800826 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -0700827
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700828 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800829 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700830 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800831 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -0700832}
833
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800834enum latency_range {
835 lowest_latency = 0,
836 low_latency = 1,
837 bulk_latency = 2,
838 latency_invalid = 255
839};
840
841/**
842 * ixgbe_update_itr - update the dynamic ITR value based on statistics
843 * @adapter: pointer to adapter
844 * @eitr: eitr setting (ints per sec) to give last timeslice
845 * @itr_setting: current throttle rate in ints/second
846 * @packets: the number of packets during this measurement interval
847 * @bytes: the number of bytes during this measurement interval
848 *
849 * Stores a new ITR value based on packets and byte
850 * counts during the last interrupt. The advantage of per interrupt
851 * computation is faster updates and more accurate ITR for the current
852 * traffic pattern. Constants in this function were computed
853 * based on theoretical maximum wire speed and thresholds were set based
854 * on testing data as well as attempting to minimize response time
855 * while increasing bulk throughput.
856 * this functionality is controlled by the InterruptThrottleRate module
857 * parameter (see ixgbe_param.c)
858 **/
859static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700860 u32 eitr, u8 itr_setting,
861 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800862{
863 unsigned int retval = itr_setting;
864 u32 timepassed_us;
865 u64 bytes_perint;
866
867 if (packets == 0)
868 goto update_itr_done;
869
870
871 /* simple throttlerate management
872 * 0-20MB/s lowest (100000 ints/s)
873 * 20-100MB/s low (20000 ints/s)
874 * 100-1249MB/s bulk (8000 ints/s)
875 */
876 /* what was last interrupt timeslice? */
877 timepassed_us = 1000000/eitr;
878 bytes_perint = bytes / timepassed_us; /* bytes/usec */
879
880 switch (itr_setting) {
881 case lowest_latency:
882 if (bytes_perint > adapter->eitr_low)
883 retval = low_latency;
884 break;
885 case low_latency:
886 if (bytes_perint > adapter->eitr_high)
887 retval = bulk_latency;
888 else if (bytes_perint <= adapter->eitr_low)
889 retval = lowest_latency;
890 break;
891 case bulk_latency:
892 if (bytes_perint <= adapter->eitr_high)
893 retval = low_latency;
894 break;
895 }
896
897update_itr_done:
898 return retval;
899}
900
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000901/**
902 * ixgbe_write_eitr - write EITR register in hardware specific way
903 * @adapter: pointer to adapter struct
904 * @v_idx: vector index into q_vector array
905 * @itr_reg: new value to be written in *register* format, not ints/s
906 *
907 * This function is made to be called by ethtool and by the driver
908 * when it needs to update EITR registers at runtime. Hardware
909 * specific quirks/differences are taken care of here.
910 */
911void ixgbe_write_eitr(struct ixgbe_adapter *adapter, int v_idx, u32 itr_reg)
912{
913 struct ixgbe_hw *hw = &adapter->hw;
914 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
915 /* must write high and low 16 bits to reset counter */
916 itr_reg |= (itr_reg << 16);
917 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
918 /*
919 * set the WDIS bit to not clear the timer bits and cause an
920 * immediate assertion of the interrupt
921 */
922 itr_reg |= IXGBE_EITR_CNT_WDIS;
923 }
924 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
925}
926
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800927static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
928{
929 struct ixgbe_adapter *adapter = q_vector->adapter;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800930 u32 new_itr;
931 u8 current_itr, ret_itr;
932 int i, r_idx, v_idx = ((void *)q_vector - (void *)(adapter->q_vector)) /
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700933 sizeof(struct ixgbe_q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800934 struct ixgbe_ring *rx_ring, *tx_ring;
935
936 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
937 for (i = 0; i < q_vector->txr_count; i++) {
938 tx_ring = &(adapter->tx_ring[r_idx]);
939 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700940 q_vector->tx_itr,
941 tx_ring->total_packets,
942 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800943 /* if the result for this queue would decrease interrupt
944 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700945 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700946 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800947 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700948 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800949 }
950
951 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
952 for (i = 0; i < q_vector->rxr_count; i++) {
953 rx_ring = &(adapter->rx_ring[r_idx]);
954 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700955 q_vector->rx_itr,
956 rx_ring->total_packets,
957 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800958 /* if the result for this queue would decrease interrupt
959 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700960 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700961 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800962 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700963 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800964 }
965
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700966 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800967
968 switch (current_itr) {
969 /* counts and packets in update_itr are dependent on these numbers */
970 case lowest_latency:
971 new_itr = 100000;
972 break;
973 case low_latency:
974 new_itr = 20000; /* aka hwitr = ~200 */
975 break;
976 case bulk_latency:
977 default:
978 new_itr = 8000;
979 break;
980 }
981
982 if (new_itr != q_vector->eitr) {
983 u32 itr_reg;
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000984
985 /* save the algorithm value here, not the smoothed one */
986 q_vector->eitr = new_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800987 /* do an exponential smoothing */
988 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800989 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000990 ixgbe_write_eitr(adapter, v_idx, itr_reg);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800991 }
992
993 return;
994}
995
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700996static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
997{
998 struct ixgbe_hw *hw = &adapter->hw;
999
1000 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1001 (eicr & IXGBE_EICR_GPI_SDP1)) {
1002 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
1003 /* write to clear the interrupt */
1004 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1005 }
1006}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001007
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001008static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1009{
1010 struct ixgbe_hw *hw = &adapter->hw;
1011
1012 if (eicr & IXGBE_EICR_GPI_SDP1) {
1013 /* Clear the interrupt */
1014 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1015 schedule_work(&adapter->multispeed_fiber_task);
1016 } else if (eicr & IXGBE_EICR_GPI_SDP2) {
1017 /* Clear the interrupt */
1018 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1019 schedule_work(&adapter->sfp_config_module_task);
1020 } else {
1021 /* Interrupt isn't for us... */
1022 return;
1023 }
1024}
1025
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001026static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1027{
1028 struct ixgbe_hw *hw = &adapter->hw;
1029
1030 adapter->lsc_int++;
1031 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1032 adapter->link_check_timeout = jiffies;
1033 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1034 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1035 schedule_work(&adapter->watchdog_task);
1036 }
1037}
1038
Auke Kok9a799d72007-09-15 14:07:45 -07001039static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1040{
1041 struct net_device *netdev = data;
1042 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1043 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001044 u32 eicr;
1045
1046 /*
1047 * Workaround for Silicon errata. Use clear-by-write instead
1048 * of clear-by-read. Reading with EICS will return the
1049 * interrupt causes without clearing, which later be done
1050 * with the write to EICR.
1051 */
1052 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1053 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001054
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001055 if (eicr & IXGBE_EICR_LSC)
1056 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001057
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001058 if (hw->mac.type == ixgbe_mac_82598EB)
1059 ixgbe_check_fan_failure(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001060
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001061 if (hw->mac.type == ixgbe_mac_82599EB)
1062 ixgbe_check_sfp_event(adapter, eicr);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001063 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1064 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -07001065
1066 return IRQ_HANDLED;
1067}
1068
1069static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1070{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001071 struct ixgbe_q_vector *q_vector = data;
1072 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001073 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001074 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001075
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001076 if (!q_vector->txr_count)
1077 return IRQ_HANDLED;
1078
1079 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1080 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001081 tx_ring = &(adapter->tx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001082#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001083 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001084 ixgbe_update_tx_dca(adapter, tx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001085#endif
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001086 tx_ring->total_bytes = 0;
1087 tx_ring->total_packets = 0;
1088 ixgbe_clean_tx_irq(adapter, tx_ring);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001089 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001090 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001091 }
1092
Auke Kok9a799d72007-09-15 14:07:45 -07001093 return IRQ_HANDLED;
1094}
1095
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001096/**
1097 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1098 * @irq: unused
1099 * @data: pointer to our q_vector struct for this interrupt vector
1100 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001101static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1102{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001103 struct ixgbe_q_vector *q_vector = data;
1104 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001105 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001106 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001107 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001108
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001109 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001110 for (i = 0; i < q_vector->rxr_count; i++) {
1111 rx_ring = &(adapter->rx_ring[r_idx]);
1112 rx_ring->total_bytes = 0;
1113 rx_ring->total_packets = 0;
1114 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1115 r_idx + 1);
1116 }
1117
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001118 if (!q_vector->rxr_count)
1119 return IRQ_HANDLED;
1120
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001121 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001122 rx_ring = &(adapter->rx_ring[r_idx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001123 /* disable interrupts on this vector only */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001124 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rx_ring->v_idx);
Ben Hutchings288379f2009-01-19 16:43:59 -08001125 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001126
Auke Kok9a799d72007-09-15 14:07:45 -07001127 return IRQ_HANDLED;
1128}
1129
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001130static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1131{
1132 ixgbe_msix_clean_rx(irq, data);
1133 ixgbe_msix_clean_tx(irq, data);
1134
1135 return IRQ_HANDLED;
1136}
1137
1138/**
1139 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1140 * @napi: napi struct with our devices info in it
1141 * @budget: amount of work driver is allowed to do this pass, in packets
1142 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001143 * This function is optimized for cleaning one queue only on a single
1144 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001145 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001146static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1147{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001148 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001149 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001150 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001151 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001152 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001153 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001154
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001155 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001156 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001157#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001158 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001159 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001160#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001161
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001162 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001163
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001164 /* If all Rx work done, exit the polling mode */
1165 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001166 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001167 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001168 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001169 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001170 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rx_ring->v_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07001171 }
1172
1173 return work_done;
1174}
1175
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001176/**
1177 * ixgbe_clean_rxonly_many - msix (aka one shot) rx clean routine
1178 * @napi: napi struct with our devices info in it
1179 * @budget: amount of work driver is allowed to do this pass, in packets
1180 *
1181 * This function will clean more than one rx queue associated with a
1182 * q_vector.
1183 **/
1184static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget)
1185{
1186 struct ixgbe_q_vector *q_vector =
1187 container_of(napi, struct ixgbe_q_vector, napi);
1188 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001189 struct ixgbe_ring *rx_ring = NULL;
1190 int work_done = 0, i;
1191 long r_idx;
1192 u16 enable_mask = 0;
1193
1194 /* attempt to distribute budget to each queue fairly, but don't allow
1195 * the budget to go below 1 because we'll exit polling */
1196 budget /= (q_vector->rxr_count ?: 1);
1197 budget = max(budget, 1);
1198 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1199 for (i = 0; i < q_vector->rxr_count; i++) {
1200 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001201#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001202 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1203 ixgbe_update_rx_dca(adapter, rx_ring);
1204#endif
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001205 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001206 enable_mask |= rx_ring->v_idx;
1207 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1208 r_idx + 1);
1209 }
1210
1211 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1212 rx_ring = &(adapter->rx_ring[r_idx]);
1213 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001214 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001215 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001216 if (adapter->itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001217 ixgbe_set_itr_msix(q_vector);
1218 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1219 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, enable_mask);
1220 return 0;
1221 }
1222
1223 return work_done;
1224}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001225static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001226 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001227{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001228 a->q_vector[v_idx].adapter = a;
1229 set_bit(r_idx, a->q_vector[v_idx].rxr_idx);
1230 a->q_vector[v_idx].rxr_count++;
1231 a->rx_ring[r_idx].v_idx = 1 << v_idx;
1232}
Auke Kok9a799d72007-09-15 14:07:45 -07001233
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001234static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001235 int r_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001236{
1237 a->q_vector[v_idx].adapter = a;
1238 set_bit(r_idx, a->q_vector[v_idx].txr_idx);
1239 a->q_vector[v_idx].txr_count++;
1240 a->tx_ring[r_idx].v_idx = 1 << v_idx;
1241}
Auke Kok9a799d72007-09-15 14:07:45 -07001242
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001243/**
1244 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1245 * @adapter: board private structure to initialize
1246 * @vectors: allotted vector count for descriptor rings
1247 *
1248 * This function maps descriptor rings to the queue-specific vectors
1249 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1250 * one vector per ring/queue, but on a constrained vector budget, we
1251 * group the rings as "efficiently" as possible. You would add new
1252 * mapping configurations in here.
1253 **/
1254static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001255 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001256{
1257 int v_start = 0;
1258 int rxr_idx = 0, txr_idx = 0;
1259 int rxr_remaining = adapter->num_rx_queues;
1260 int txr_remaining = adapter->num_tx_queues;
1261 int i, j;
1262 int rqpv, tqpv;
1263 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001264
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001265 /* No mapping required if MSI-X is disabled. */
1266 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001267 goto out;
1268
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001269 /*
1270 * The ideal configuration...
1271 * We have enough vectors to map one per queue.
1272 */
1273 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1274 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1275 map_vector_to_rxq(adapter, v_start, rxr_idx);
1276
1277 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1278 map_vector_to_txq(adapter, v_start, txr_idx);
1279
1280 goto out;
1281 }
1282
1283 /*
1284 * If we don't have enough vectors for a 1-to-1
1285 * mapping, we'll have to group them so there are
1286 * multiple queues per vector.
1287 */
1288 /* Re-adjusting *qpv takes care of the remainder. */
1289 for (i = v_start; i < vectors; i++) {
1290 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1291 for (j = 0; j < rqpv; j++) {
1292 map_vector_to_rxq(adapter, i, rxr_idx);
1293 rxr_idx++;
1294 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001295 }
Auke Kok9a799d72007-09-15 14:07:45 -07001296 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001297 for (i = v_start; i < vectors; i++) {
1298 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1299 for (j = 0; j < tqpv; j++) {
1300 map_vector_to_txq(adapter, i, txr_idx);
1301 txr_idx++;
1302 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001303 }
Auke Kok9a799d72007-09-15 14:07:45 -07001304 }
1305
Auke Kok9a799d72007-09-15 14:07:45 -07001306out:
Auke Kok9a799d72007-09-15 14:07:45 -07001307 return err;
1308}
1309
1310/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001311 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1312 * @adapter: board private structure
1313 *
1314 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1315 * interrupts from the kernel.
1316 **/
1317static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1318{
1319 struct net_device *netdev = adapter->netdev;
1320 irqreturn_t (*handler)(int, void *);
1321 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001322 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001323
1324 /* Decrement for Other and TCP Timer vectors */
1325 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1326
1327 /* Map the Tx/Rx rings to the vectors we were allotted. */
1328 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1329 if (err)
1330 goto out;
1331
1332#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001333 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1334 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001335 for (vector = 0; vector < q_vectors; vector++) {
1336 handler = SET_HANDLER(&adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001337
1338 if(handler == &ixgbe_msix_clean_rx) {
1339 sprintf(adapter->name[vector], "%s-%s-%d",
1340 netdev->name, "rx", ri++);
1341 }
1342 else if(handler == &ixgbe_msix_clean_tx) {
1343 sprintf(adapter->name[vector], "%s-%s-%d",
1344 netdev->name, "tx", ti++);
1345 }
1346 else
1347 sprintf(adapter->name[vector], "%s-%s-%d",
1348 netdev->name, "TxRx", vector);
1349
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001350 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001351 handler, 0, adapter->name[vector],
1352 &(adapter->q_vector[vector]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001353 if (err) {
1354 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001355 "request_irq failed for MSIX interrupt "
1356 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001357 goto free_queue_irqs;
1358 }
1359 }
1360
1361 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1362 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001363 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001364 if (err) {
1365 DPRINTK(PROBE, ERR,
1366 "request_irq for msix_lsc failed: %d\n", err);
1367 goto free_queue_irqs;
1368 }
1369
1370 return 0;
1371
1372free_queue_irqs:
1373 for (i = vector - 1; i >= 0; i--)
1374 free_irq(adapter->msix_entries[--vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001375 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001376 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1377 pci_disable_msix(adapter->pdev);
1378 kfree(adapter->msix_entries);
1379 adapter->msix_entries = NULL;
1380out:
1381 return err;
1382}
1383
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001384static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1385{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001386 struct ixgbe_q_vector *q_vector = adapter->q_vector;
1387 u8 current_itr;
1388 u32 new_itr = q_vector->eitr;
1389 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1390 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1391
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001392 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001393 q_vector->tx_itr,
1394 tx_ring->total_packets,
1395 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001396 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001397 q_vector->rx_itr,
1398 rx_ring->total_packets,
1399 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001400
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001401 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001402
1403 switch (current_itr) {
1404 /* counts and packets in update_itr are dependent on these numbers */
1405 case lowest_latency:
1406 new_itr = 100000;
1407 break;
1408 case low_latency:
1409 new_itr = 20000; /* aka hwitr = ~200 */
1410 break;
1411 case bulk_latency:
1412 new_itr = 8000;
1413 break;
1414 default:
1415 break;
1416 }
1417
1418 if (new_itr != q_vector->eitr) {
1419 u32 itr_reg;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001420
1421 /* save the algorithm value here, not the smoothed one */
1422 q_vector->eitr = new_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001423 /* do an exponential smoothing */
1424 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001425 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001426 ixgbe_write_eitr(adapter, 0, itr_reg);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001427 }
1428
1429 return;
1430}
1431
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001432/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001433 * ixgbe_irq_enable - Enable default interrupt generation settings
1434 * @adapter: board private structure
1435 **/
1436static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1437{
1438 u32 mask;
1439 mask = IXGBE_EIMS_ENABLE_MASK;
David S. Miller6ab33d52008-11-20 16:44:00 -08001440 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1441 mask |= IXGBE_EIMS_GPI_SDP1;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001442 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001443 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001444 mask |= IXGBE_EIMS_GPI_SDP1;
1445 mask |= IXGBE_EIMS_GPI_SDP2;
1446 }
1447
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001448 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001449 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1450 /* enable the rest of the queue vectors */
1451 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1),
1452 (IXGBE_EIMS_RTX_QUEUE << 16));
1453 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(2),
1454 ((IXGBE_EIMS_RTX_QUEUE << 16) |
1455 IXGBE_EIMS_RTX_QUEUE));
1456 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001457 IXGBE_WRITE_FLUSH(&adapter->hw);
1458}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001459
1460/**
1461 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001462 * @irq: interrupt number
1463 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001464 **/
1465static irqreturn_t ixgbe_intr(int irq, void *data)
1466{
1467 struct net_device *netdev = data;
1468 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1469 struct ixgbe_hw *hw = &adapter->hw;
1470 u32 eicr;
1471
Don Skidmore54037502009-02-21 15:42:56 -08001472 /*
1473 * Workaround for silicon errata. Mask the interrupts
1474 * before the read of EICR.
1475 */
1476 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1477
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001478 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1479 * therefore no explict interrupt disable is necessary */
1480 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001481 if (!eicr) {
1482 /* shared interrupt alert!
1483 * make sure interrupts are enabled because the read will
1484 * have disabled interrupts due to EIAM */
1485 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001486 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001487 }
Auke Kok9a799d72007-09-15 14:07:45 -07001488
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001489 if (eicr & IXGBE_EICR_LSC)
1490 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001491
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001492 if (hw->mac.type == ixgbe_mac_82599EB)
1493 ixgbe_check_sfp_event(adapter, eicr);
1494
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001495 ixgbe_check_fan_failure(adapter, eicr);
1496
Ben Hutchings288379f2009-01-19 16:43:59 -08001497 if (napi_schedule_prep(&adapter->q_vector[0].napi)) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001498 adapter->tx_ring[0].total_packets = 0;
1499 adapter->tx_ring[0].total_bytes = 0;
1500 adapter->rx_ring[0].total_packets = 0;
1501 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001502 /* would disable interrupts here but EIAM disabled it */
Ben Hutchings288379f2009-01-19 16:43:59 -08001503 __napi_schedule(&adapter->q_vector[0].napi);
Auke Kok9a799d72007-09-15 14:07:45 -07001504 }
1505
1506 return IRQ_HANDLED;
1507}
1508
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001509static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1510{
1511 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1512
1513 for (i = 0; i < q_vectors; i++) {
1514 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
1515 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1516 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1517 q_vector->rxr_count = 0;
1518 q_vector->txr_count = 0;
1519 }
1520}
1521
Auke Kok9a799d72007-09-15 14:07:45 -07001522/**
1523 * ixgbe_request_irq - initialize interrupts
1524 * @adapter: board private structure
1525 *
1526 * Attempts to configure interrupts using the best available
1527 * capabilities of the hardware and kernel.
1528 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001529static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001530{
1531 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001532 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001533
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001534 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1535 err = ixgbe_request_msix_irqs(adapter);
1536 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1537 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001538 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001539 } else {
1540 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001541 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001542 }
1543
Auke Kok9a799d72007-09-15 14:07:45 -07001544 if (err)
1545 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1546
Auke Kok9a799d72007-09-15 14:07:45 -07001547 return err;
1548}
1549
1550static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1551{
1552 struct net_device *netdev = adapter->netdev;
1553
1554 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001555 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001556
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001557 q_vectors = adapter->num_msix_vectors;
1558
1559 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001560 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001561
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001562 i--;
1563 for (; i >= 0; i--) {
1564 free_irq(adapter->msix_entries[i].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001565 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001566 }
1567
1568 ixgbe_reset_q_vectors(adapter);
1569 } else {
1570 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001571 }
1572}
1573
1574/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001575 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1576 * @adapter: board private structure
1577 **/
1578static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1579{
1580 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1581 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1582 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
1583 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(2), ~0);
1584 }
1585 IXGBE_WRITE_FLUSH(&adapter->hw);
1586 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1587 int i;
1588 for (i = 0; i < adapter->num_msix_vectors; i++)
1589 synchronize_irq(adapter->msix_entries[i].vector);
1590 } else {
1591 synchronize_irq(adapter->pdev->irq);
1592 }
1593}
1594
1595static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter)
1596{
1597 u32 mask = IXGBE_EIMS_RTX_QUEUE;
1598 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1599 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1600 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask << 16);
1601 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(2),
1602 (mask << 16 | mask));
1603 }
1604 /* skip the flush */
1605}
1606
1607/**
Auke Kok9a799d72007-09-15 14:07:45 -07001608 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1609 *
1610 **/
1611static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1612{
Auke Kok9a799d72007-09-15 14:07:45 -07001613 struct ixgbe_hw *hw = &adapter->hw;
1614
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001615 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001616 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001617
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001618 ixgbe_set_ivar(adapter, 0, 0, 0);
1619 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001620
1621 map_vector_to_rxq(adapter, 0, 0);
1622 map_vector_to_txq(adapter, 0, 0);
1623
1624 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001625}
1626
1627/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001628 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001629 * @adapter: board private structure
1630 *
1631 * Configure the Tx unit of the MAC after a reset.
1632 **/
1633static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1634{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001635 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001636 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001637 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001638
1639 /* Setup the HW Tx Head and Tail descriptor pointers */
1640 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001641 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1642 j = ring->reg_idx;
1643 tdba = ring->dma;
1644 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001645 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001646 (tdba & DMA_32BIT_MASK));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001647 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1648 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1649 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1650 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1651 adapter->tx_ring[i].head = IXGBE_TDH(j);
1652 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1653 /* Disable Tx Head Writeback RO bit, since this hoses
1654 * bookkeeping if things aren't delivered in order.
1655 */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001656 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001657 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001658 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001659 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001660 if (hw->mac.type == ixgbe_mac_82599EB) {
1661 /* We enable 8 traffic classes, DCB only */
1662 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1663 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1664 IXGBE_MTQC_8TC_8TQ));
1665 }
Auke Kok9a799d72007-09-15 14:07:45 -07001666}
1667
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001668#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07001669
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001670static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1671{
1672 struct ixgbe_ring *rx_ring;
1673 u32 srrctl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001674 int queue0 = 0;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001675 unsigned long mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001676
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001677 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1678 queue0 = index;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001679 } else {
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001680 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1681 queue0 = index & mask;
1682 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001683 }
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001684
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001685 rx_ring = &adapter->rx_ring[queue0];
1686
1687 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1688
1689 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1690 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1691
1692 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg32344a32009-02-24 16:37:31 -08001693 u16 bufsz = IXGBE_RXBUFFER_2048;
1694 /* grow the amount we can receive on large page machines */
1695 if (bufsz < (PAGE_SIZE / 2))
1696 bufsz = (PAGE_SIZE / 2);
1697 /* cap the bufsz at our largest descriptor size */
1698 bufsz = min((u16)IXGBE_MAX_RXBUFFER, bufsz);
1699
1700 srrctl |= bufsz >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001701 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1702 srrctl |= ((IXGBE_RX_HDR_SIZE <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001703 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1704 IXGBE_SRRCTL_BSIZEHDR_MASK);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001705 } else {
1706 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1707
1708 if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1709 srrctl |= IXGBE_RXBUFFER_2048 >>
1710 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1711 else
1712 srrctl |= rx_ring->rx_buf_len >>
1713 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1714 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001715
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001716 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1717}
1718
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001719/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001720 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001721 * @adapter: board private structure
1722 *
1723 * Configure the Rx unit of the MAC after a reset.
1724 **/
1725static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1726{
1727 u64 rdba;
1728 struct ixgbe_hw *hw = &adapter->hw;
1729 struct net_device *netdev = adapter->netdev;
1730 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001731 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001732 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001733 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1734 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1735 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001736 u32 fctrl, hlreg0;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001737 u32 reta = 0, mrqc = 0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001738 u32 rdrxctl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001739 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07001740
1741 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001742 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07001743
1744 /* Set the RX buffer length according to the mode */
1745 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001746 rx_buf_len = IXGBE_RX_HDR_SIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001747 if (hw->mac.type == ixgbe_mac_82599EB) {
1748 /* PSRTYPE must be initialized in 82599 */
1749 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
1750 IXGBE_PSRTYPE_UDPHDR |
1751 IXGBE_PSRTYPE_IPV4HDR |
1752 IXGBE_PSRTYPE_IPV6HDR;
1753 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
1754 }
Auke Kok9a799d72007-09-15 14:07:45 -07001755 } else {
1756 if (netdev->mtu <= ETH_DATA_LEN)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001757 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001758 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001759 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07001760 }
1761
1762 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1763 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001764 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001765 fctrl |= IXGBE_FCTRL_PMCF;
Auke Kok9a799d72007-09-15 14:07:45 -07001766 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1767
1768 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1769 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1770 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1771 else
1772 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1773 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1774
Auke Kok9a799d72007-09-15 14:07:45 -07001775 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1776 /* disable receives while setting up the descriptors */
1777 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1778 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1779
1780 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1781 * the Base and Length of the Rx Descriptor Ring */
1782 for (i = 0; i < adapter->num_rx_queues; i++) {
1783 rdba = adapter->rx_ring[i].dma;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001784 j = adapter->rx_ring[i].reg_idx;
1785 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_32BIT_MASK));
1786 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
1787 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
1788 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
1789 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
1790 adapter->rx_ring[i].head = IXGBE_RDH(j);
1791 adapter->rx_ring[i].tail = IXGBE_RDT(j);
1792 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001793
1794 ixgbe_configure_srrctl(adapter, j);
Auke Kok9a799d72007-09-15 14:07:45 -07001795 }
1796
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001797 if (hw->mac.type == ixgbe_mac_82598EB) {
1798 /*
1799 * For VMDq support of different descriptor types or
1800 * buffer sizes through the use of multiple SRRCTL
1801 * registers, RDRXCTL.MVMEN must be set to 1
1802 *
1803 * also, the manual doesn't mention it clearly but DCA hints
1804 * will only use queue 0's tags unless this bit is set. Side
1805 * effects of setting this bit are only that SRRCTL must be
1806 * fully programmed [0..15]
1807 */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001808 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1809 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
1810 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
Alexander Duyck2f90b862008-11-20 20:52:10 -08001811 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001812
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001813 /* Program MRQC for the distribution of queues */
1814 if (hw->mac.type == ixgbe_mac_82599EB) {
1815 int mask = adapter->flags & (
1816 IXGBE_FLAG_RSS_ENABLED
1817 | IXGBE_FLAG_DCB_ENABLED
1818 );
1819
1820 switch (mask) {
1821 case (IXGBE_FLAG_RSS_ENABLED):
1822 mrqc = IXGBE_MRQC_RSSEN;
1823 break;
1824 case (IXGBE_FLAG_DCB_ENABLED):
1825 mrqc = IXGBE_MRQC_RT8TCEN;
1826 break;
1827 default:
1828 break;
1829 }
1830 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001831 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07001832 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001833 for (i = 0, j = 0; i < 128; i++, j++) {
1834 if (j == adapter->ring_feature[RING_F_RSS].indices)
1835 j = 0;
1836 /* reta = 4-byte sliding window of
1837 * 0x00..(indices-1)(indices-1)00..etc. */
1838 reta = (reta << 8) | (j * 0x11);
1839 if ((i & 3) == 3)
1840 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07001841 }
1842
1843 /* Fill out hash function seeds */
1844 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001845 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07001846
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001847 if (hw->mac.type == ixgbe_mac_82598EB)
1848 mrqc |= IXGBE_MRQC_RSSEN;
Auke Kok9a799d72007-09-15 14:07:45 -07001849 /* Perform hash on these packet types */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001850 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
1851 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1852 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1853 | IXGBE_MRQC_RSS_FIELD_IPV6
1854 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1855 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07001856 }
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001857 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001858
1859 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1860
1861 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
1862 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
1863 /* Disable indicating checksum in descriptor, enables
1864 * RSS hash */
1865 rxcsum |= IXGBE_RXCSUM_PCSD;
1866 }
1867 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
1868 /* Enable IPv4 payload checksum for UDP fragments
1869 * if PCSD is not set */
1870 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1871 }
1872
1873 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001874
1875 if (hw->mac.type == ixgbe_mac_82599EB) {
1876 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1877 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
1878 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
1879 }
Auke Kok9a799d72007-09-15 14:07:45 -07001880}
1881
Auke Kok9a799d72007-09-15 14:07:45 -07001882static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1883{
1884 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001885 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001886
1887 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001888 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07001889}
1890
1891static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1892{
1893 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001894 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001895
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001896 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1897 ixgbe_irq_disable(adapter);
1898
Auke Kok9a799d72007-09-15 14:07:45 -07001899 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001900
1901 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1902 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001903
1904 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001905 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07001906}
1907
Don Skidmore068c89b2009-01-19 16:54:36 -08001908static void ixgbe_vlan_rx_register(struct net_device *netdev,
1909 struct vlan_group *grp)
1910{
1911 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1912 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001913 int i, j;
Don Skidmore068c89b2009-01-19 16:54:36 -08001914
1915 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1916 ixgbe_irq_disable(adapter);
1917 adapter->vlgrp = grp;
1918
1919 /*
1920 * For a DCB driver, always enable VLAN tag stripping so we can
1921 * still receive traffic from a DCB-enabled host even if we're
1922 * not in DCB mode.
1923 */
1924 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001925 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1926 ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
Don Skidmore068c89b2009-01-19 16:54:36 -08001927 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1928 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001929 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1930 ctrl |= IXGBE_VLNCTRL_VFE;
1931 /* enable VLAN tag insert/strip */
1932 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1933 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1934 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1935 for (i = 0; i < adapter->num_rx_queues; i++) {
1936 j = adapter->rx_ring[i].reg_idx;
1937 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
1938 ctrl |= IXGBE_RXDCTL_VME;
1939 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
1940 }
Don Skidmore068c89b2009-01-19 16:54:36 -08001941 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001942 ixgbe_vlan_rx_add_vid(netdev, 0);
Don Skidmore068c89b2009-01-19 16:54:36 -08001943
1944 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1945 ixgbe_irq_enable(adapter);
1946}
1947
Auke Kok9a799d72007-09-15 14:07:45 -07001948static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
1949{
1950 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1951
1952 if (adapter->vlgrp) {
1953 u16 vid;
1954 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1955 if (!vlan_group_get_device(adapter->vlgrp, vid))
1956 continue;
1957 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
1958 }
1959 }
1960}
1961
Christopher Leech2c5645c2008-08-26 04:27:02 -07001962static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
1963{
1964 struct dev_mc_list *mc_ptr;
1965 u8 *addr = *mc_addr_ptr;
1966 *vmdq = 0;
1967
1968 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
1969 if (mc_ptr->next)
1970 *mc_addr_ptr = mc_ptr->next->dmi_addr;
1971 else
1972 *mc_addr_ptr = NULL;
1973
1974 return addr;
1975}
1976
Auke Kok9a799d72007-09-15 14:07:45 -07001977/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07001978 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07001979 * @netdev: network interface device structure
1980 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07001981 * The set_rx_method entry point is called whenever the unicast/multicast
1982 * address list or the network interface flags are updated. This routine is
1983 * responsible for configuring the hardware for proper unicast, multicast and
1984 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07001985 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07001986static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001987{
1988 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1989 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07001990 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001991 u8 *addr_list = NULL;
1992 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001993
1994 /* Check for Promiscuous and All Multicast modes */
1995
1996 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07001997 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07001998
1999 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07002000 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002001 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07002002 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07002003 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002004 if (netdev->flags & IFF_ALLMULTI) {
2005 fctrl |= IXGBE_FCTRL_MPE;
2006 fctrl &= ~IXGBE_FCTRL_UPE;
2007 } else {
2008 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2009 }
Alexander Duyck3d016252008-08-26 18:30:04 -07002010 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002011 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002012 }
2013
2014 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07002015 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07002016
Christopher Leech2c5645c2008-08-26 04:27:02 -07002017 /* reprogram secondary unicast list */
2018 addr_count = netdev->uc_count;
2019 if (addr_count)
2020 addr_list = netdev->uc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002021 hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count,
2022 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002023
Christopher Leech2c5645c2008-08-26 04:27:02 -07002024 /* reprogram multicast list */
2025 addr_count = netdev->mc_count;
2026 if (addr_count)
2027 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002028 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2029 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002030}
2031
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002032static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2033{
2034 int q_idx;
2035 struct ixgbe_q_vector *q_vector;
2036 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2037
2038 /* legacy and MSI only use one vector */
2039 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2040 q_vectors = 1;
2041
2042 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002043 struct napi_struct *napi;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002044 q_vector = &adapter->q_vector[q_idx];
2045 if (!q_vector->rxr_count)
2046 continue;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002047 napi = &q_vector->napi;
2048 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) &&
2049 (q_vector->rxr_count > 1))
2050 napi->poll = &ixgbe_clean_rxonly_many;
2051
2052 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002053 }
2054}
2055
2056static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2057{
2058 int q_idx;
2059 struct ixgbe_q_vector *q_vector;
2060 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2061
2062 /* legacy and MSI only use one vector */
2063 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2064 q_vectors = 1;
2065
2066 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
2067 q_vector = &adapter->q_vector[q_idx];
2068 if (!q_vector->rxr_count)
2069 continue;
2070 napi_disable(&q_vector->napi);
2071 }
2072}
2073
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002074#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002075/*
2076 * ixgbe_configure_dcb - Configure DCB hardware
2077 * @adapter: ixgbe adapter struct
2078 *
2079 * This is called by the driver on open to configure the DCB hardware.
2080 * This is also called by the gennetlink interface when reconfiguring
2081 * the DCB state.
2082 */
2083static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2084{
2085 struct ixgbe_hw *hw = &adapter->hw;
2086 u32 txdctl, vlnctrl;
2087 int i, j;
2088
2089 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2090 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2091 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2092
2093 /* reconfigure the hardware */
2094 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2095
2096 for (i = 0; i < adapter->num_tx_queues; i++) {
2097 j = adapter->tx_ring[i].reg_idx;
2098 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2099 /* PThresh workaround for Tx hang with DFP enabled. */
2100 txdctl |= 32;
2101 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2102 }
2103 /* Enable VLAN tag insert/strip */
2104 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002105 if (hw->mac.type == ixgbe_mac_82598EB) {
2106 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2107 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2108 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2109 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2110 vlnctrl |= IXGBE_VLNCTRL_VFE;
2111 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2112 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2113 for (i = 0; i < adapter->num_rx_queues; i++) {
2114 j = adapter->rx_ring[i].reg_idx;
2115 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2116 vlnctrl |= IXGBE_RXDCTL_VME;
2117 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2118 }
2119 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08002120 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2121}
2122
2123#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002124static void ixgbe_configure(struct ixgbe_adapter *adapter)
2125{
2126 struct net_device *netdev = adapter->netdev;
2127 int i;
2128
Christopher Leech2c5645c2008-08-26 04:27:02 -07002129 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002130
2131 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002132#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002133 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2134 netif_set_gso_max_size(netdev, 32768);
2135 ixgbe_configure_dcb(adapter);
2136 } else {
2137 netif_set_gso_max_size(netdev, 65536);
2138 }
2139#else
2140 netif_set_gso_max_size(netdev, 65536);
2141#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002142
2143 ixgbe_configure_tx(adapter);
2144 ixgbe_configure_rx(adapter);
2145 for (i = 0; i < adapter->num_rx_queues; i++)
2146 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002147 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07002148}
2149
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002150static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2151{
2152 switch (hw->phy.type) {
2153 case ixgbe_phy_sfp_avago:
2154 case ixgbe_phy_sfp_ftl:
2155 case ixgbe_phy_sfp_intel:
2156 case ixgbe_phy_sfp_unknown:
2157 case ixgbe_phy_tw_tyco:
2158 case ixgbe_phy_tw_unknown:
2159 return true;
2160 default:
2161 return false;
2162 }
2163}
2164
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002165/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002166 * ixgbe_sfp_link_config - set up SFP+ link
2167 * @adapter: pointer to private adapter struct
2168 **/
2169static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2170{
2171 struct ixgbe_hw *hw = &adapter->hw;
2172
2173 if (hw->phy.multispeed_fiber) {
2174 /*
2175 * In multispeed fiber setups, the device may not have
2176 * had a physical connection when the driver loaded.
2177 * If that's the case, the initial link configuration
2178 * couldn't get the MAC into 10G or 1G mode, so we'll
2179 * never have a link status change interrupt fire.
2180 * We need to try and force an autonegotiation
2181 * session, then bring up link.
2182 */
2183 hw->mac.ops.setup_sfp(hw);
2184 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2185 schedule_work(&adapter->multispeed_fiber_task);
2186 } else {
2187 /*
2188 * Direct Attach Cu and non-multispeed fiber modules
2189 * still need to be configured properly prior to
2190 * attempting link.
2191 */
2192 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2193 schedule_work(&adapter->sfp_config_module_task);
2194 }
2195}
2196
2197/**
2198 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002199 * @hw: pointer to private hardware struct
2200 *
2201 * Returns 0 on success, negative on failure
2202 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002203static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002204{
2205 u32 autoneg;
2206 bool link_up = false;
2207 u32 ret = IXGBE_ERR_LINK_SETUP;
2208
2209 if (hw->mac.ops.check_link)
2210 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2211
2212 if (ret)
2213 goto link_cfg_out;
2214
2215 if (hw->mac.ops.get_link_capabilities)
2216 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
2217 &hw->mac.autoneg);
2218 if (ret)
2219 goto link_cfg_out;
2220
2221 if (hw->mac.ops.setup_link_speed)
2222 ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002223link_cfg_out:
2224 return ret;
2225}
2226
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002227#define IXGBE_MAX_RX_DESC_POLL 10
2228static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2229 int rxr)
2230{
2231 int j = adapter->rx_ring[rxr].reg_idx;
2232 int k;
2233
2234 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2235 if (IXGBE_READ_REG(&adapter->hw,
2236 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2237 break;
2238 else
2239 msleep(1);
2240 }
2241 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2242 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2243 "not set within the polling period\n", rxr);
2244 }
2245 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2246 (adapter->rx_ring[rxr].count - 1));
2247}
2248
Auke Kok9a799d72007-09-15 14:07:45 -07002249static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2250{
2251 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07002252 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002253 int i, j = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002254 int num_rx_rings = adapter->num_rx_queues;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002255 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002256 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002257 u32 txdctl, rxdctl, mhadd;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002258 u32 dmatxctl;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002259 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002260
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002261 ixgbe_get_hw_control(adapter);
2262
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002263 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2264 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002265 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2266 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002267 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002268 } else {
2269 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002270 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002271 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002272 /* XXX: to interrupt immediately for EICS writes, enable this */
2273 /* gpie |= IXGBE_GPIE_EIMEN; */
2274 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2275 }
2276
2277 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2278 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2279 * specifically only auto mask tx and rx interrupts */
2280 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002281 }
2282
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002283 /* Enable fan failure interrupt if media type is copper */
2284 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2285 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2286 gpie |= IXGBE_SDP1_GPIEN;
2287 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2288 }
2289
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002290 if (hw->mac.type == ixgbe_mac_82599EB) {
2291 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2292 gpie |= IXGBE_SDP1_GPIEN;
2293 gpie |= IXGBE_SDP2_GPIEN;
2294 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2295 }
2296
Auke Kok9a799d72007-09-15 14:07:45 -07002297 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002298 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2299 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2300 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2301
2302 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2303 }
2304
2305 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002306 j = adapter->tx_ring[i].reg_idx;
2307 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002308 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2309 txdctl |= (8 << 16);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002310 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2311 }
2312
2313 if (hw->mac.type == ixgbe_mac_82599EB) {
2314 /* DMATXCTL.EN must be set after all Tx queue config is done */
2315 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2316 dmatxctl |= IXGBE_DMATXCTL_TE;
2317 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2318 }
2319 for (i = 0; i < adapter->num_tx_queues; i++) {
2320 j = adapter->tx_ring[i].reg_idx;
2321 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Auke Kok9a799d72007-09-15 14:07:45 -07002322 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002323 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002324 }
2325
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002326 for (i = 0; i < num_rx_rings; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002327 j = adapter->rx_ring[i].reg_idx;
2328 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2329 /* enable PTHRESH=32 descriptors (half the internal cache)
2330 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2331 * this also removes a pesky rx_no_buffer_count increment */
2332 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002333 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002334 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002335 if (hw->mac.type == ixgbe_mac_82599EB)
2336 ixgbe_rx_desc_queue_enable(adapter, i);
Auke Kok9a799d72007-09-15 14:07:45 -07002337 }
2338 /* enable all receives */
2339 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002340 if (hw->mac.type == ixgbe_mac_82598EB)
2341 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2342 else
2343 rxdctl |= IXGBE_RXCTRL_RXEN;
2344 hw->mac.ops.enable_rx_dma(hw, rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002345
2346 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2347 ixgbe_configure_msix(adapter);
2348 else
2349 ixgbe_configure_msi_and_legacy(adapter);
2350
2351 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002352 ixgbe_napi_enable_all(adapter);
2353
2354 /* clear any pending interrupts, may auto mask */
2355 IXGBE_READ_REG(hw, IXGBE_EICR);
2356
Auke Kok9a799d72007-09-15 14:07:45 -07002357 ixgbe_irq_enable(adapter);
2358
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002359 /*
2360 * For hot-pluggable SFP+ devices, a new SFP+ module may have
2361 * arrived before interrupts were enabled. We need to kick off
2362 * the SFP+ module setup first, then try to bring up link.
2363 * If we're not hot-pluggable SFP+, we just need to configure link
2364 * and bring it up.
2365 */
2366 err = hw->phy.ops.identify(hw);
2367 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2368 DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err);
2369 ixgbe_down(adapter);
2370 return err;
2371 }
2372
2373 if (ixgbe_is_sfp(hw)) {
2374 ixgbe_sfp_link_config(adapter);
2375 } else {
2376 err = ixgbe_non_sfp_link_config(hw);
2377 if (err)
2378 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2379 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002380
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002381 /* enable transmits */
2382 netif_tx_start_all_queues(netdev);
2383
Auke Kok9a799d72007-09-15 14:07:45 -07002384 /* bring the link up in the watchdog, this could race with our first
2385 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002386 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2387 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002388 mod_timer(&adapter->watchdog_timer, jiffies);
2389 return 0;
2390}
2391
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002392void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2393{
2394 WARN_ON(in_interrupt());
2395 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2396 msleep(1);
2397 ixgbe_down(adapter);
2398 ixgbe_up(adapter);
2399 clear_bit(__IXGBE_RESETTING, &adapter->state);
2400}
2401
Auke Kok9a799d72007-09-15 14:07:45 -07002402int ixgbe_up(struct ixgbe_adapter *adapter)
2403{
2404 /* hardware has been reset, we need to reload some things */
2405 ixgbe_configure(adapter);
2406
Jesse Brandeburg4dd64df2009-03-13 22:13:49 +00002407 ixgbe_napi_add_all(adapter);
2408
Auke Kok9a799d72007-09-15 14:07:45 -07002409 return ixgbe_up_complete(adapter);
2410}
2411
2412void ixgbe_reset(struct ixgbe_adapter *adapter)
2413{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002414 struct ixgbe_hw *hw = &adapter->hw;
2415 if (hw->mac.ops.init_hw(hw))
2416 dev_err(&adapter->pdev->dev, "Hardware Error\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002417
2418 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002419 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002420
2421}
2422
Auke Kok9a799d72007-09-15 14:07:45 -07002423/**
2424 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2425 * @adapter: board private structure
2426 * @rx_ring: ring to free buffers from
2427 **/
2428static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002429 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002430{
2431 struct pci_dev *pdev = adapter->pdev;
2432 unsigned long size;
2433 unsigned int i;
2434
2435 /* Free all the Rx ring sk_buffs */
2436
2437 for (i = 0; i < rx_ring->count; i++) {
2438 struct ixgbe_rx_buffer *rx_buffer_info;
2439
2440 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2441 if (rx_buffer_info->dma) {
2442 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002443 rx_ring->rx_buf_len,
2444 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002445 rx_buffer_info->dma = 0;
2446 }
2447 if (rx_buffer_info->skb) {
2448 dev_kfree_skb(rx_buffer_info->skb);
2449 rx_buffer_info->skb = NULL;
2450 }
2451 if (!rx_buffer_info->page)
2452 continue;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002453 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2454 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002455 rx_buffer_info->page_dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002456 put_page(rx_buffer_info->page);
2457 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002458 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002459 }
2460
2461 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2462 memset(rx_ring->rx_buffer_info, 0, size);
2463
2464 /* Zero out the descriptor ring */
2465 memset(rx_ring->desc, 0, rx_ring->size);
2466
2467 rx_ring->next_to_clean = 0;
2468 rx_ring->next_to_use = 0;
2469
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002470 if (rx_ring->head)
2471 writel(0, adapter->hw.hw_addr + rx_ring->head);
2472 if (rx_ring->tail)
2473 writel(0, adapter->hw.hw_addr + rx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002474}
2475
2476/**
2477 * ixgbe_clean_tx_ring - Free Tx Buffers
2478 * @adapter: board private structure
2479 * @tx_ring: ring to be cleaned
2480 **/
2481static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002482 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002483{
2484 struct ixgbe_tx_buffer *tx_buffer_info;
2485 unsigned long size;
2486 unsigned int i;
2487
2488 /* Free all the Tx ring sk_buffs */
2489
2490 for (i = 0; i < tx_ring->count; i++) {
2491 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2492 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2493 }
2494
2495 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2496 memset(tx_ring->tx_buffer_info, 0, size);
2497
2498 /* Zero out the descriptor ring */
2499 memset(tx_ring->desc, 0, tx_ring->size);
2500
2501 tx_ring->next_to_use = 0;
2502 tx_ring->next_to_clean = 0;
2503
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002504 if (tx_ring->head)
2505 writel(0, adapter->hw.hw_addr + tx_ring->head);
2506 if (tx_ring->tail)
2507 writel(0, adapter->hw.hw_addr + tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002508}
2509
2510/**
Auke Kok9a799d72007-09-15 14:07:45 -07002511 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2512 * @adapter: board private structure
2513 **/
2514static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2515{
2516 int i;
2517
2518 for (i = 0; i < adapter->num_rx_queues; i++)
2519 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2520}
2521
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002522/**
2523 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2524 * @adapter: board private structure
2525 **/
2526static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2527{
2528 int i;
2529
2530 for (i = 0; i < adapter->num_tx_queues; i++)
2531 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2532}
2533
Auke Kok9a799d72007-09-15 14:07:45 -07002534void ixgbe_down(struct ixgbe_adapter *adapter)
2535{
2536 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002537 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002538 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002539 u32 txdctl;
2540 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002541
2542 /* signal that we are down to the interrupt handler */
2543 set_bit(__IXGBE_DOWN, &adapter->state);
2544
2545 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002546 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2547 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002548
2549 netif_tx_disable(netdev);
2550
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002551 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002552 msleep(10);
2553
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002554 netif_tx_stop_all_queues(netdev);
2555
Auke Kok9a799d72007-09-15 14:07:45 -07002556 ixgbe_irq_disable(adapter);
2557
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002558 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002559
Auke Kok9a799d72007-09-15 14:07:45 -07002560 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002561 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002562
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002563 /* disable transmits in the hardware now that interrupts are off */
2564 for (i = 0; i < adapter->num_tx_queues; i++) {
2565 j = adapter->tx_ring[i].reg_idx;
2566 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2567 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2568 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2569 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00002570 /* Disable the Tx DMA engine on 82599 */
2571 if (hw->mac.type == ixgbe_mac_82599EB)
2572 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
2573 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
2574 ~IXGBE_DMATXCTL_TE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002575
Auke Kok9a799d72007-09-15 14:07:45 -07002576 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002577
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002578#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002579 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2580 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
2581 dca_remove_requester(&adapter->pdev->dev);
2582 }
2583
2584#endif
Paul Larson6f4a0e42008-06-24 17:00:56 -07002585 if (!pci_channel_offline(adapter->pdev))
2586 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002587 ixgbe_clean_all_tx_rings(adapter);
2588 ixgbe_clean_all_rx_rings(adapter);
2589
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002590#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002591 /* since we reset the hardware DCA settings were cleared */
2592 if (dca_add_requester(&adapter->pdev->dev) == 0) {
2593 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
2594 /* always use CB2 mode, difference is masked
2595 * in the CB driver */
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002596 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002597 ixgbe_setup_dca(adapter);
2598 }
2599#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002600}
2601
Auke Kok9a799d72007-09-15 14:07:45 -07002602/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002603 * ixgbe_poll - NAPI Rx polling callback
2604 * @napi: structure for representing this polling device
2605 * @budget: how many packets driver is allowed to clean
2606 *
2607 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002608 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002609static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002610{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002611 struct ixgbe_q_vector *q_vector =
2612 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002613 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002614 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002615
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002616#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002617 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2618 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2619 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2620 }
2621#endif
2622
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002623 tx_clean_complete = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002624 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002625
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002626 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002627 work_done = budget;
2628
David S. Miller53e52c72008-01-07 21:06:12 -08002629 /* If budget not fully consumed, exit the polling mode */
2630 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002631 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002632 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002633 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002634 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002635 ixgbe_irq_enable_queues(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002636 }
Auke Kok9a799d72007-09-15 14:07:45 -07002637 return work_done;
2638}
2639
2640/**
2641 * ixgbe_tx_timeout - Respond to a Tx Hang
2642 * @netdev: network interface device structure
2643 **/
2644static void ixgbe_tx_timeout(struct net_device *netdev)
2645{
2646 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2647
2648 /* Do the reset outside of interrupt context */
2649 schedule_work(&adapter->reset_task);
2650}
2651
2652static void ixgbe_reset_task(struct work_struct *work)
2653{
2654 struct ixgbe_adapter *adapter;
2655 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2656
Alexander Duyck2f90b862008-11-20 20:52:10 -08002657 /* If we're already down or resetting, just bail */
2658 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2659 test_bit(__IXGBE_RESETTING, &adapter->state))
2660 return;
2661
Auke Kok9a799d72007-09-15 14:07:45 -07002662 adapter->tx_timeout_count++;
2663
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002664 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002665}
2666
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002667#ifdef CONFIG_IXGBE_DCB
2668static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002669{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002670 bool ret = false;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002671
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002672 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2673 adapter->ring_feature[RING_F_DCB].mask = 0x7 << 3;
2674 adapter->num_rx_queues =
2675 adapter->ring_feature[RING_F_DCB].indices;
2676 adapter->num_tx_queues =
2677 adapter->ring_feature[RING_F_DCB].indices;
2678 ret = true;
2679 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002680 ret = false;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002681 }
2682
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002683 return ret;
2684}
2685#endif
2686
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002687/**
2688 * ixgbe_set_rss_queues: Allocate queues for RSS
2689 * @adapter: board private structure to initialize
2690 *
2691 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
2692 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
2693 *
2694 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002695static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
2696{
2697 bool ret = false;
2698
2699 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2700 adapter->ring_feature[RING_F_RSS].mask = 0xF;
2701 adapter->num_rx_queues =
2702 adapter->ring_feature[RING_F_RSS].indices;
2703 adapter->num_tx_queues =
2704 adapter->ring_feature[RING_F_RSS].indices;
2705 ret = true;
2706 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002707 ret = false;
2708 }
2709
2710 return ret;
2711}
2712
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002713/*
2714 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
2715 * @adapter: board private structure to initialize
2716 *
2717 * This is the top level queue allocation routine. The order here is very
2718 * important, starting with the "most" number of features turned on at once,
2719 * and ending with the smallest set of features. This way large combinations
2720 * can be allocated if they're turned on, and smaller combinations are the
2721 * fallthrough conditions.
2722 *
2723 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002724static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2725{
2726 /* Start with base case */
2727 adapter->num_rx_queues = 1;
2728 adapter->num_tx_queues = 1;
2729
2730#ifdef CONFIG_IXGBE_DCB
2731 if (ixgbe_set_dcb_queues(adapter))
2732 return;
2733
2734#endif
2735 if (ixgbe_set_rss_queues(adapter))
2736 return;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002737}
2738
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002739static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002740 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002741{
2742 int err, vector_threshold;
2743
2744 /* We'll want at least 3 (vector_threshold):
2745 * 1) TxQ[0] Cleanup
2746 * 2) RxQ[0] Cleanup
2747 * 3) Other (Link Status Change, etc.)
2748 * 4) TCP Timer (optional)
2749 */
2750 vector_threshold = MIN_MSIX_COUNT;
2751
2752 /* The more we get, the more we will assign to Tx/Rx Cleanup
2753 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2754 * Right now, we simply care about how many we'll get; we'll
2755 * set them up later while requesting irq's.
2756 */
2757 while (vectors >= vector_threshold) {
2758 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002759 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002760 if (!err) /* Success in acquiring all requested vectors. */
2761 break;
2762 else if (err < 0)
2763 vectors = 0; /* Nasty failure, quit now */
2764 else /* err == number of vectors we should try again with */
2765 vectors = err;
2766 }
2767
2768 if (vectors < vector_threshold) {
2769 /* Can't allocate enough MSI-X interrupts? Oh well.
2770 * This just means we'll go with either a single MSI
2771 * vector or fall back to legacy interrupts.
2772 */
2773 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2774 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2775 kfree(adapter->msix_entries);
2776 adapter->msix_entries = NULL;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002777 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002778 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002779 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002780 } else {
2781 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08002782 /*
2783 * Adjust for only the vectors we'll use, which is minimum
2784 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
2785 * vectors we were allocated.
2786 */
2787 adapter->num_msix_vectors = min(vectors,
2788 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002789 }
2790}
2791
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002792/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002793 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002794 * @adapter: board private structure to initialize
2795 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002796 * Cache the descriptor ring offsets for RSS to the assigned rings.
2797 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002798 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002799static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002800{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002801 int i;
2802 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002803
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002804 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2805 for (i = 0; i < adapter->num_rx_queues; i++)
2806 adapter->rx_ring[i].reg_idx = i;
2807 for (i = 0; i < adapter->num_tx_queues; i++)
2808 adapter->tx_ring[i].reg_idx = i;
2809 ret = true;
2810 } else {
2811 ret = false;
2812 }
2813
2814 return ret;
2815}
2816
2817#ifdef CONFIG_IXGBE_DCB
2818/**
2819 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
2820 * @adapter: board private structure to initialize
2821 *
2822 * Cache the descriptor ring offsets for DCB to the assigned rings.
2823 *
2824 **/
2825static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
2826{
2827 int i;
2828 bool ret = false;
2829 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2830
2831 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2832 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002833 /* the number of queues is assumed to be symmetric */
2834 for (i = 0; i < dcb_i; i++) {
2835 adapter->rx_ring[i].reg_idx = i << 3;
2836 adapter->tx_ring[i].reg_idx = i << 2;
2837 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002838 ret = true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002839 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
2840 for (i = 0; i < dcb_i; i++) {
2841 adapter->rx_ring[i].reg_idx = i << 4;
2842 adapter->tx_ring[i].reg_idx = i << 4;
2843 }
2844 ret = true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002845 } else {
2846 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002847 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002848 } else {
2849 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002850 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002851
2852 return ret;
2853}
2854#endif
2855
2856/**
2857 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2858 * @adapter: board private structure to initialize
2859 *
2860 * Once we know the feature-set enabled for the device, we'll cache
2861 * the register offset the descriptor ring is assigned to.
2862 *
2863 * Note, the order the various feature calls is important. It must start with
2864 * the "most" features enabled at the same time, then trickle down to the
2865 * least amount of features turned on at once.
2866 **/
2867static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
2868{
2869 /* start with default case */
2870 adapter->rx_ring[0].reg_idx = 0;
2871 adapter->tx_ring[0].reg_idx = 0;
2872
2873#ifdef CONFIG_IXGBE_DCB
2874 if (ixgbe_cache_ring_dcb(adapter))
2875 return;
2876
2877#endif
2878 if (ixgbe_cache_ring_rss(adapter))
2879 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002880}
2881
Auke Kok9a799d72007-09-15 14:07:45 -07002882/**
2883 * ixgbe_alloc_queues - Allocate memory for all rings
2884 * @adapter: board private structure to initialize
2885 *
2886 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002887 * number of queues at compile-time. The polling_netdev array is
2888 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07002889 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002890static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002891{
2892 int i;
2893
2894 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002895 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07002896 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002897 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07002898
2899 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002900 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002901 if (!adapter->rx_ring)
2902 goto err_rx_ring_allocation;
2903
2904 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002905 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002906 adapter->tx_ring[i].queue_index = i;
2907 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002908
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002909 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002910 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002911 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07002912 }
2913
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002914 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002915
2916 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002917
2918err_rx_ring_allocation:
2919 kfree(adapter->tx_ring);
2920err_tx_ring_allocation:
2921 return -ENOMEM;
2922}
2923
2924/**
2925 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
2926 * @adapter: board private structure to initialize
2927 *
2928 * Attempt to configure the interrupts using the best available
2929 * capabilities of the hardware and the kernel.
2930 **/
Al Virofeea6a52008-11-27 15:34:07 -08002931static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002932{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00002933 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002934 int err = 0;
2935 int vector, v_budget;
2936
2937 /*
2938 * It's easy to be greedy for MSI-X vectors, but it really
2939 * doesn't do us much good if we have a lot more vectors
2940 * than CPU's. So let's be conservative and only ask for
2941 * (roughly) twice the number of vectors as there are CPU's.
2942 */
2943 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002944 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002945
2946 /*
2947 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00002948 * hw.mac->max_msix_vectors vectors. With features
2949 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
2950 * descriptor queues supported by our device. Thus, we cap it off in
2951 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002952 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00002953 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002954
2955 /* A failure in MSI-X entry allocation isn't fatal, but it does
2956 * mean we disable MSI-X capabilities of the adapter. */
2957 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002958 sizeof(struct msix_entry), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002959 if (!adapter->msix_entries) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002960 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002961 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2962 ixgbe_set_num_queues(adapter);
2963 kfree(adapter->tx_ring);
2964 kfree(adapter->rx_ring);
2965 err = ixgbe_alloc_queues(adapter);
2966 if (err) {
2967 DPRINTK(PROBE, ERR, "Unable to allocate memory "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002968 "for queues\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002969 goto out;
2970 }
2971
2972 goto try_msi;
2973 }
2974
2975 for (vector = 0; vector < v_budget; vector++)
2976 adapter->msix_entries[vector].entry = vector;
2977
2978 ixgbe_acquire_msix_vectors(adapter, v_budget);
2979
2980 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2981 goto out;
2982
2983try_msi:
2984 err = pci_enable_msi(adapter->pdev);
2985 if (!err) {
2986 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
2987 } else {
2988 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002989 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002990 /* reset err */
2991 err = 0;
2992 }
2993
2994out:
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08002995 /* Notify the stack of the (possibly) reduced Tx Queue count. */
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002996 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002997
2998 return err;
2999}
3000
Alexander Duyck2f90b862008-11-20 20:52:10 -08003001void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003002{
3003 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3004 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3005 pci_disable_msix(adapter->pdev);
3006 kfree(adapter->msix_entries);
3007 adapter->msix_entries = NULL;
3008 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
3009 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
3010 pci_disable_msi(adapter->pdev);
3011 }
3012 return;
3013}
3014
3015/**
3016 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3017 * @adapter: board private structure to initialize
3018 *
3019 * We determine which interrupt scheme to use based on...
3020 * - Kernel support (MSI, MSI-X)
3021 * - which can be user-defined (via MODULE_PARAM)
3022 * - Hardware queue count (num_*_queues)
3023 * - defined by miscellaneous hardware support/features (RSS, etc.)
3024 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003025int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003026{
3027 int err;
3028
3029 /* Number of supported queues */
3030 ixgbe_set_num_queues(adapter);
3031
3032 err = ixgbe_alloc_queues(adapter);
3033 if (err) {
3034 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3035 goto err_alloc_queues;
3036 }
3037
3038 err = ixgbe_set_interrupt_capability(adapter);
3039 if (err) {
3040 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3041 goto err_set_interrupt;
3042 }
3043
3044 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003045 "Tx Queue count = %u\n",
3046 (adapter->num_rx_queues > 1) ? "Enabled" :
3047 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003048
3049 set_bit(__IXGBE_DOWN, &adapter->state);
3050
3051 return 0;
3052
3053err_set_interrupt:
3054 kfree(adapter->tx_ring);
3055 kfree(adapter->rx_ring);
3056err_alloc_queues:
3057 return err;
Auke Kok9a799d72007-09-15 14:07:45 -07003058}
3059
3060/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08003061 * ixgbe_sfp_timer - worker thread to find a missing module
3062 * @data: pointer to our adapter struct
3063 **/
3064static void ixgbe_sfp_timer(unsigned long data)
3065{
3066 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3067
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003068 /*
3069 * Do the sfp_timer outside of interrupt context due to the
Donald Skidmorec4900be2008-11-20 21:11:42 -08003070 * delays that sfp+ detection requires
3071 */
3072 schedule_work(&adapter->sfp_task);
3073}
3074
3075/**
3076 * ixgbe_sfp_task - worker thread to find a missing module
3077 * @work: pointer to work_struct containing our data
3078 **/
3079static void ixgbe_sfp_task(struct work_struct *work)
3080{
3081 struct ixgbe_adapter *adapter = container_of(work,
3082 struct ixgbe_adapter,
3083 sfp_task);
3084 struct ixgbe_hw *hw = &adapter->hw;
3085
3086 if ((hw->phy.type == ixgbe_phy_nl) &&
3087 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3088 s32 ret = hw->phy.ops.identify_sfp(hw);
3089 if (ret)
3090 goto reschedule;
3091 ret = hw->phy.ops.reset(hw);
3092 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
3093 DPRINTK(PROBE, ERR, "failed to initialize because an "
3094 "unsupported SFP+ module type was detected.\n"
3095 "Reload the driver after installing a "
3096 "supported module.\n");
3097 unregister_netdev(adapter->netdev);
3098 } else {
3099 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3100 hw->phy.sfp_type);
3101 }
3102 /* don't need this routine any more */
3103 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3104 }
3105 return;
3106reschedule:
3107 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3108 mod_timer(&adapter->sfp_timer,
3109 round_jiffies(jiffies + (2 * HZ)));
3110}
3111
3112/**
Auke Kok9a799d72007-09-15 14:07:45 -07003113 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3114 * @adapter: board private structure to initialize
3115 *
3116 * ixgbe_sw_init initializes the Adapter private data structure.
3117 * Fields are initialized based on PCI device information and
3118 * OS network device settings (MTU size).
3119 **/
3120static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3121{
3122 struct ixgbe_hw *hw = &adapter->hw;
3123 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003124 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003125#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003126 int j;
3127 struct tc_configuration *tc;
3128#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003129
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003130 /* PCI config space info */
3131
3132 hw->vendor_id = pdev->vendor;
3133 hw->device_id = pdev->device;
3134 hw->revision_id = pdev->revision;
3135 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3136 hw->subsystem_device_id = pdev->subsystem_device;
3137
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003138 /* Set capability flags */
3139 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3140 adapter->ring_feature[RING_F_RSS].indices = rss;
3141 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003142 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003143 if (hw->mac.type == ixgbe_mac_82598EB)
3144 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
3145 else if (hw->mac.type == ixgbe_mac_82599EB)
3146 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003147
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003148#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003149 /* Configure DCB traffic classes */
3150 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3151 tc = &adapter->dcb_cfg.tc_config[j];
3152 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3153 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3154 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3155 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3156 tc->dcb_pfc = pfc_disabled;
3157 }
3158 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3159 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3160 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
3161 adapter->dcb_cfg.round_robin_enable = false;
3162 adapter->dcb_set_bitmap = 0x00;
3163 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3164 adapter->ring_feature[RING_F_DCB].indices);
3165
3166#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003167
3168 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00003169 hw->fc.requested_mode = ixgbe_fc_full;
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07003170 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3171 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3172 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3173 hw->fc.send_xon = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003174
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07003175 /* enable itr by default in dynamic mode */
3176 adapter->itr_setting = 1;
3177 adapter->eitr_param = 20000;
3178
3179 /* set defaults for eitr in MegaBytes */
3180 adapter->eitr_low = 10;
3181 adapter->eitr_high = 20;
3182
3183 /* set default ring sizes */
3184 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
3185 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
3186
Auke Kok9a799d72007-09-15 14:07:45 -07003187 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003188 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003189 dev_err(&pdev->dev, "EEPROM initialization failed\n");
3190 return -EIO;
3191 }
3192
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003193 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07003194 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
3195
Auke Kok9a799d72007-09-15 14:07:45 -07003196 set_bit(__IXGBE_DOWN, &adapter->state);
3197
3198 return 0;
3199}
3200
3201/**
3202 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3203 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003204 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003205 *
3206 * Return 0 on success, negative on failure
3207 **/
3208int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003209 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003210{
3211 struct pci_dev *pdev = adapter->pdev;
3212 int size;
3213
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003214 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3215 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003216 if (!tx_ring->tx_buffer_info)
3217 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003218 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003219
3220 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08003221 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003222 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003223
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003224 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
3225 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003226 if (!tx_ring->desc)
3227 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07003228
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003229 tx_ring->next_to_use = 0;
3230 tx_ring->next_to_clean = 0;
3231 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07003232 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003233
3234err:
3235 vfree(tx_ring->tx_buffer_info);
3236 tx_ring->tx_buffer_info = NULL;
3237 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
3238 "descriptor ring\n");
3239 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003240}
3241
3242/**
Alexander Duyck69888672008-09-11 20:05:39 -07003243 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
3244 * @adapter: board private structure
3245 *
3246 * If this function returns with an error, then it's possible one or
3247 * more of the rings is populated (while the rest are not). It is the
3248 * callers duty to clean those orphaned rings.
3249 *
3250 * Return 0 on success, negative on failure
3251 **/
3252static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
3253{
3254 int i, err = 0;
3255
3256 for (i = 0; i < adapter->num_tx_queues; i++) {
3257 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
3258 if (!err)
3259 continue;
3260 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
3261 break;
3262 }
3263
3264 return err;
3265}
3266
3267/**
Auke Kok9a799d72007-09-15 14:07:45 -07003268 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
3269 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003270 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003271 *
3272 * Returns 0 on success, negative on failure
3273 **/
3274int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003275 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003276{
3277 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003278 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07003279
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003280 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
3281 rx_ring->rx_buffer_info = vmalloc(size);
3282 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07003283 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003284 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003285 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003286 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003287 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003288
Auke Kok9a799d72007-09-15 14:07:45 -07003289 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003290 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
3291 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003292
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003293 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07003294
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003295 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07003296 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003297 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003298 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003299 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003300 }
3301
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003302 rx_ring->next_to_clean = 0;
3303 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003304
3305 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003306
3307alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003308 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003309}
3310
3311/**
Alexander Duyck69888672008-09-11 20:05:39 -07003312 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
3313 * @adapter: board private structure
3314 *
3315 * If this function returns with an error, then it's possible one or
3316 * more of the rings is populated (while the rest are not). It is the
3317 * callers duty to clean those orphaned rings.
3318 *
3319 * Return 0 on success, negative on failure
3320 **/
3321
3322static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
3323{
3324 int i, err = 0;
3325
3326 for (i = 0; i < adapter->num_rx_queues; i++) {
3327 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
3328 if (!err)
3329 continue;
3330 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
3331 break;
3332 }
3333
3334 return err;
3335}
3336
3337/**
Auke Kok9a799d72007-09-15 14:07:45 -07003338 * ixgbe_free_tx_resources - Free Tx Resources per Queue
3339 * @adapter: board private structure
3340 * @tx_ring: Tx descriptor ring for a specific queue
3341 *
3342 * Free all transmit software resources
3343 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003344void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
3345 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003346{
3347 struct pci_dev *pdev = adapter->pdev;
3348
3349 ixgbe_clean_tx_ring(adapter, tx_ring);
3350
3351 vfree(tx_ring->tx_buffer_info);
3352 tx_ring->tx_buffer_info = NULL;
3353
3354 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
3355
3356 tx_ring->desc = NULL;
3357}
3358
3359/**
3360 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
3361 * @adapter: board private structure
3362 *
3363 * Free all transmit software resources
3364 **/
3365static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
3366{
3367 int i;
3368
3369 for (i = 0; i < adapter->num_tx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00003370 if (adapter->tx_ring[i].desc)
3371 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003372}
3373
3374/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003375 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07003376 * @adapter: board private structure
3377 * @rx_ring: ring to clean the resources from
3378 *
3379 * Free all receive software resources
3380 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003381void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
3382 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003383{
3384 struct pci_dev *pdev = adapter->pdev;
3385
3386 ixgbe_clean_rx_ring(adapter, rx_ring);
3387
3388 vfree(rx_ring->rx_buffer_info);
3389 rx_ring->rx_buffer_info = NULL;
3390
3391 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
3392
3393 rx_ring->desc = NULL;
3394}
3395
3396/**
3397 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
3398 * @adapter: board private structure
3399 *
3400 * Free all receive software resources
3401 **/
3402static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
3403{
3404 int i;
3405
3406 for (i = 0; i < adapter->num_rx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00003407 if (adapter->rx_ring[i].desc)
3408 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003409}
3410
3411/**
Auke Kok9a799d72007-09-15 14:07:45 -07003412 * ixgbe_change_mtu - Change the Maximum Transfer Unit
3413 * @netdev: network interface device structure
3414 * @new_mtu: new value for maximum frame size
3415 *
3416 * Returns 0 on success, negative on failure
3417 **/
3418static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
3419{
3420 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3421 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3422
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07003423 /* MTU < 68 is an error and causes problems on some kernels */
3424 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07003425 return -EINVAL;
3426
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003427 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003428 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003429 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07003430 netdev->mtu = new_mtu;
3431
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003432 if (netif_running(netdev))
3433 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003434
3435 return 0;
3436}
3437
3438/**
3439 * ixgbe_open - Called when a network interface is made active
3440 * @netdev: network interface device structure
3441 *
3442 * Returns 0 on success, negative value on failure
3443 *
3444 * The open entry point is called when a network interface is made
3445 * active by the system (IFF_UP). At this point all resources needed
3446 * for transmit and receive operations are allocated, the interrupt
3447 * handler is registered with the OS, the watchdog timer is started,
3448 * and the stack is notified that the interface is ready.
3449 **/
3450static int ixgbe_open(struct net_device *netdev)
3451{
3452 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3453 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003454
Auke Kok4bebfaa2008-02-11 09:26:01 -08003455 /* disallow open during test */
3456 if (test_bit(__IXGBE_TESTING, &adapter->state))
3457 return -EBUSY;
3458
Auke Kok9a799d72007-09-15 14:07:45 -07003459 /* allocate transmit descriptors */
3460 err = ixgbe_setup_all_tx_resources(adapter);
3461 if (err)
3462 goto err_setup_tx;
3463
Auke Kok9a799d72007-09-15 14:07:45 -07003464 /* allocate receive descriptors */
3465 err = ixgbe_setup_all_rx_resources(adapter);
3466 if (err)
3467 goto err_setup_rx;
3468
3469 ixgbe_configure(adapter);
3470
Jesse Brandeburg4dd64df2009-03-13 22:13:49 +00003471 ixgbe_napi_add_all(adapter);
3472
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003473 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003474 if (err)
3475 goto err_req_irq;
3476
Auke Kok9a799d72007-09-15 14:07:45 -07003477 err = ixgbe_up_complete(adapter);
3478 if (err)
3479 goto err_up;
3480
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003481 netif_tx_start_all_queues(netdev);
3482
Auke Kok9a799d72007-09-15 14:07:45 -07003483 return 0;
3484
3485err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003486 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003487 ixgbe_free_irq(adapter);
3488err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07003489err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00003490 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003491err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00003492 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003493 ixgbe_reset(adapter);
3494
3495 return err;
3496}
3497
3498/**
3499 * ixgbe_close - Disables a network interface
3500 * @netdev: network interface device structure
3501 *
3502 * Returns 0, this is not allowed to fail
3503 *
3504 * The close entry point is called when an interface is de-activated
3505 * by the OS. The hardware is still under the drivers control, but
3506 * needs to be disabled. A global MAC reset is issued to stop the
3507 * hardware, and all transmit and receive resources are freed.
3508 **/
3509static int ixgbe_close(struct net_device *netdev)
3510{
3511 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003512
3513 ixgbe_down(adapter);
3514 ixgbe_free_irq(adapter);
3515
3516 ixgbe_free_all_tx_resources(adapter);
3517 ixgbe_free_all_rx_resources(adapter);
3518
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003519 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003520
3521 return 0;
3522}
3523
3524/**
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003525 * ixgbe_napi_add_all - prep napi structs for use
3526 * @adapter: private struct
Jesse Brandeburg4dd64df2009-03-13 22:13:49 +00003527 *
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003528 * helper function to napi_add each possible q_vector->napi
3529 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08003530void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003531{
3532 int q_idx, q_vectors;
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003533 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003534 int (*poll)(struct napi_struct *, int);
3535
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003536 /* check if we already have our netdev->napi_list populated */
3537 if (&netdev->napi_list != netdev->napi_list.next)
3538 return;
3539
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003540 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3541 poll = &ixgbe_clean_rxonly;
3542 /* Only enable as many vectors as we have rx queues. */
3543 q_vectors = adapter->num_rx_queues;
3544 } else {
3545 poll = &ixgbe_poll;
3546 /* only one q_vector for legacy modes */
3547 q_vectors = 1;
3548 }
3549
3550 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3551 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3552 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
3553 }
3554}
3555
Alexander Duyck2f90b862008-11-20 20:52:10 -08003556void ixgbe_napi_del_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003557{
3558 int q_idx;
3559 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3560
3561 /* legacy and MSI only use one vector */
3562 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3563 q_vectors = 1;
3564
3565 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3566 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3567 if (!q_vector->rxr_count)
3568 continue;
3569 netif_napi_del(&q_vector->napi);
3570 }
3571}
3572
3573#ifdef CONFIG_PM
3574static int ixgbe_resume(struct pci_dev *pdev)
3575{
3576 struct net_device *netdev = pci_get_drvdata(pdev);
3577 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3578 u32 err;
3579
3580 pci_set_power_state(pdev, PCI_D0);
3581 pci_restore_state(pdev);
3582 err = pci_enable_device(pdev);
3583 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07003584 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003585 "suspend\n");
3586 return err;
3587 }
3588 pci_set_master(pdev);
3589
3590 pci_enable_wake(pdev, PCI_D3hot, 0);
3591 pci_enable_wake(pdev, PCI_D3cold, 0);
3592
3593 err = ixgbe_init_interrupt_scheme(adapter);
3594 if (err) {
3595 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
3596 "device\n");
3597 return err;
3598 }
3599
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003600 ixgbe_reset(adapter);
3601
3602 if (netif_running(netdev)) {
3603 err = ixgbe_open(adapter->netdev);
3604 if (err)
3605 return err;
3606 }
3607
3608 netif_device_attach(netdev);
3609
3610 return 0;
3611}
3612
3613#endif /* CONFIG_PM */
3614static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
3615{
3616 struct net_device *netdev = pci_get_drvdata(pdev);
3617 struct ixgbe_adapter *adapter = netdev_priv(netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003618 struct ixgbe_hw *hw = &adapter->hw;
3619 u32 ctrl, fctrl;
3620 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003621#ifdef CONFIG_PM
3622 int retval = 0;
3623#endif
3624
3625 netif_device_detach(netdev);
3626
3627 if (netif_running(netdev)) {
3628 ixgbe_down(adapter);
3629 ixgbe_free_irq(adapter);
3630 ixgbe_free_all_tx_resources(adapter);
3631 ixgbe_free_all_rx_resources(adapter);
3632 }
3633 ixgbe_reset_interrupt_capability(adapter);
3634 ixgbe_napi_del_all(adapter);
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003635 INIT_LIST_HEAD(&netdev->napi_list);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003636 kfree(adapter->tx_ring);
3637 kfree(adapter->rx_ring);
3638
3639#ifdef CONFIG_PM
3640 retval = pci_save_state(pdev);
3641 if (retval)
3642 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003643
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003644#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003645 if (wufc) {
3646 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003647
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003648 /* turn on all-multi mode if wake on multicast is enabled */
3649 if (wufc & IXGBE_WUFC_MC) {
3650 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3651 fctrl |= IXGBE_FCTRL_MPE;
3652 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3653 }
3654
3655 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
3656 ctrl |= IXGBE_CTRL_GIO_DIS;
3657 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
3658
3659 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
3660 } else {
3661 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
3662 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
3663 }
3664
3665 if (wufc && hw->mac.type == ixgbe_mac_82599EB) {
3666 pci_enable_wake(pdev, PCI_D3hot, 1);
3667 pci_enable_wake(pdev, PCI_D3cold, 1);
3668 } else {
3669 pci_enable_wake(pdev, PCI_D3hot, 0);
3670 pci_enable_wake(pdev, PCI_D3cold, 0);
3671 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003672
3673 ixgbe_release_hw_control(adapter);
3674
3675 pci_disable_device(pdev);
3676
3677 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3678
3679 return 0;
3680}
3681
3682static void ixgbe_shutdown(struct pci_dev *pdev)
3683{
3684 ixgbe_suspend(pdev, PMSG_SUSPEND);
3685}
3686
3687/**
Auke Kok9a799d72007-09-15 14:07:45 -07003688 * ixgbe_update_stats - Update the board statistics counters.
3689 * @adapter: board private structure
3690 **/
3691void ixgbe_update_stats(struct ixgbe_adapter *adapter)
3692{
3693 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003694 u64 total_mpc = 0;
3695 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003696
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00003697 if (hw->mac.type == ixgbe_mac_82599EB) {
3698 for (i = 0; i < 16; i++)
3699 adapter->hw_rx_no_dma_resources +=
3700 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
3701 }
3702
Auke Kok9a799d72007-09-15 14:07:45 -07003703 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003704 for (i = 0; i < 8; i++) {
3705 /* for packet buffers not used, the register should read 0 */
3706 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
3707 missed_rx += mpc;
3708 adapter->stats.mpc[i] += mpc;
3709 total_mpc += adapter->stats.mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003710 if (hw->mac.type == ixgbe_mac_82598EB)
3711 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08003712 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
3713 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
3714 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
3715 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003716 if (hw->mac.type == ixgbe_mac_82599EB) {
3717 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3718 IXGBE_PXONRXCNT(i));
3719 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3720 IXGBE_PXOFFRXCNT(i));
3721 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003722 } else {
3723 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3724 IXGBE_PXONRXC(i));
3725 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3726 IXGBE_PXOFFRXC(i));
3727 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003728 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
3729 IXGBE_PXONTXC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08003730 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003731 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003732 }
3733 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
3734 /* work around hardware counting issue */
3735 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07003736
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003737 /* 82598 hardware only has a 32 bit counter in the high register */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003738 if (hw->mac.type == ixgbe_mac_82599EB) {
3739 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
3740 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
3741 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
3742 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
3743 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
3744 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
3745 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
3746 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
3747 } else {
3748 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
3749 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
3750 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
3751 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
3752 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
3753 }
Auke Kok9a799d72007-09-15 14:07:45 -07003754 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
3755 adapter->stats.bprc += bprc;
3756 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003757 if (hw->mac.type == ixgbe_mac_82598EB)
3758 adapter->stats.mprc -= bprc;
Auke Kok9a799d72007-09-15 14:07:45 -07003759 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
3760 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
3761 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
3762 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
3763 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
3764 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
3765 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003766 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003767 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
3768 adapter->stats.lxontxc += lxon;
3769 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
3770 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07003771 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3772 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003773 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
3774 /*
3775 * 82598 errata - tx of flow control packets is included in tx counters
3776 */
3777 xon_off_tot = lxon + lxoff;
3778 adapter->stats.gptc -= xon_off_tot;
3779 adapter->stats.mptc -= xon_off_tot;
3780 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07003781 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3782 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
3783 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07003784 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
3785 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003786 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003787 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3788 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3789 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3790 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3791 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003792 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3793
3794 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07003795 adapter->net_stats.multicast = adapter->stats.mprc;
3796
3797 /* Rx Errors */
3798 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003799 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07003800 adapter->net_stats.rx_dropped = 0;
3801 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3802 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003803 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07003804}
3805
3806/**
3807 * ixgbe_watchdog - Timer Call-back
3808 * @data: pointer to adapter cast into an unsigned long
3809 **/
3810static void ixgbe_watchdog(unsigned long data)
3811{
3812 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003813 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003814
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003815 /* Do the watchdog outside of interrupt context due to the lovely
3816 * delays that some of the newer hardware requires */
3817 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003818 u64 eics = 0;
3819 int i;
3820
3821 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++)
3822 eics |= (1 << i);
3823
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003824 /* Cause software interrupt to ensure rx rings are cleaned */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003825 switch (hw->mac.type) {
3826 case ixgbe_mac_82598EB:
3827 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3828 IXGBE_WRITE_REG(hw, IXGBE_EICS, (u32)eics);
3829 } else {
3830 /*
3831 * for legacy and MSI interrupts don't set any
3832 * bits that are enabled for EIAM, because this
3833 * operation would set *both* EIMS and EICS for
3834 * any bit in EIAM
3835 */
3836 IXGBE_WRITE_REG(hw, IXGBE_EICS,
3837 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
3838 }
3839 break;
3840 case ixgbe_mac_82599EB:
3841 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3842 /*
3843 * EICS(0..15) first 0-15 q vectors
3844 * EICS[1] (16..31) q vectors 16-31
3845 * EICS[2] (0..31) q vectors 32-63
3846 */
3847 IXGBE_WRITE_REG(hw, IXGBE_EICS,
3848 (u32)(eics & 0xFFFF));
3849 IXGBE_WRITE_REG(hw, IXGBE_EICS_EX(1),
3850 (u32)(eics & 0xFFFF0000));
3851 IXGBE_WRITE_REG(hw, IXGBE_EICS_EX(2),
3852 (u32)(eics >> 32));
3853 } else {
3854 /*
3855 * for legacy and MSI interrupts don't set any
3856 * bits that are enabled for EIAM, because this
3857 * operation would set *both* EIMS and EICS for
3858 * any bit in EIAM
3859 */
3860 IXGBE_WRITE_REG(hw, IXGBE_EICS,
3861 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
3862 }
3863 break;
3864 default:
3865 break;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003866 }
3867 /* Reset the timer */
3868 mod_timer(&adapter->watchdog_timer,
3869 round_jiffies(jiffies + 2 * HZ));
3870 }
3871
3872 schedule_work(&adapter->watchdog_task);
3873}
3874
3875/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003876 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
3877 * @work: pointer to work_struct containing our data
3878 **/
3879static void ixgbe_multispeed_fiber_task(struct work_struct *work)
3880{
3881 struct ixgbe_adapter *adapter = container_of(work,
3882 struct ixgbe_adapter,
3883 multispeed_fiber_task);
3884 struct ixgbe_hw *hw = &adapter->hw;
3885 u32 autoneg;
3886
3887 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
3888 if (hw->mac.ops.get_link_capabilities)
3889 hw->mac.ops.get_link_capabilities(hw, &autoneg,
3890 &hw->mac.autoneg);
3891 if (hw->mac.ops.setup_link_speed)
3892 hw->mac.ops.setup_link_speed(hw, autoneg, true, true);
3893 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3894 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
3895}
3896
3897/**
3898 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
3899 * @work: pointer to work_struct containing our data
3900 **/
3901static void ixgbe_sfp_config_module_task(struct work_struct *work)
3902{
3903 struct ixgbe_adapter *adapter = container_of(work,
3904 struct ixgbe_adapter,
3905 sfp_config_module_task);
3906 struct ixgbe_hw *hw = &adapter->hw;
3907 u32 err;
3908
3909 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
3910 err = hw->phy.ops.identify_sfp(hw);
3911 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
3912 DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err);
3913 ixgbe_down(adapter);
3914 return;
3915 }
3916 hw->mac.ops.setup_sfp(hw);
3917
3918 if (!adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)
3919 /* This will also work for DA Twinax connections */
3920 schedule_work(&adapter->multispeed_fiber_task);
3921 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
3922}
3923
3924/**
Alexander Duyck69888672008-09-11 20:05:39 -07003925 * ixgbe_watchdog_task - worker thread to bring link up
3926 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003927 **/
3928static void ixgbe_watchdog_task(struct work_struct *work)
3929{
3930 struct ixgbe_adapter *adapter = container_of(work,
3931 struct ixgbe_adapter,
3932 watchdog_task);
3933 struct net_device *netdev = adapter->netdev;
3934 struct ixgbe_hw *hw = &adapter->hw;
3935 u32 link_speed = adapter->link_speed;
3936 bool link_up = adapter->link_up;
3937
3938 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
3939
3940 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3941 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
3942 if (link_up ||
3943 time_after(jiffies, (adapter->link_check_timeout +
3944 IXGBE_TRY_LINK_TIMEOUT))) {
3945 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
3946 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
3947 }
3948 adapter->link_up = link_up;
3949 adapter->link_speed = link_speed;
3950 }
Auke Kok9a799d72007-09-15 14:07:45 -07003951
3952 if (link_up) {
3953 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003954 bool flow_rx, flow_tx;
3955
3956 if (hw->mac.type == ixgbe_mac_82599EB) {
3957 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
3958 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
3959 flow_rx = (mflcn & IXGBE_MFLCN_RFCE);
3960 flow_tx = (fccfg & IXGBE_FCCFG_TFCE_802_3X);
3961 } else {
3962 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3963 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
3964 flow_rx = (frctl & IXGBE_FCTRL_RFCE);
3965 flow_tx = (rmcs & IXGBE_RMCS_TFCE_802_3X);
3966 }
3967
Jeff Kirshera46e5342008-11-27 00:22:21 -08003968 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
3969 "Flow Control: %s\n",
3970 netdev->name,
3971 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
3972 "10 Gbps" :
3973 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
3974 "1 Gbps" : "unknown speed")),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003975 ((flow_rx && flow_tx) ? "RX/TX" :
3976 (flow_rx ? "RX" :
3977 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07003978
3979 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003980 } else {
3981 /* Force detection of hung controller */
3982 adapter->detect_tx_hung = true;
3983 }
3984 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003985 adapter->link_up = false;
3986 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003987 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08003988 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
3989 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07003990 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003991 }
3992 }
3993
3994 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003995 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07003996}
3997
Auke Kok9a799d72007-09-15 14:07:45 -07003998static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003999 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
4000 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004001{
4002 struct ixgbe_adv_tx_context_desc *context_desc;
4003 unsigned int i;
4004 int err;
4005 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004006 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
4007 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07004008
4009 if (skb_is_gso(skb)) {
4010 if (skb_header_cloned(skb)) {
4011 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4012 if (err)
4013 return err;
4014 }
4015 l4len = tcp_hdrlen(skb);
4016 *hdr_len += l4len;
4017
Al Viro8327d002007-12-10 18:54:12 +00004018 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004019 struct iphdr *iph = ip_hdr(skb);
4020 iph->tot_len = 0;
4021 iph->check = 0;
4022 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004023 iph->daddr, 0,
4024 IPPROTO_TCP,
4025 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004026 adapter->hw_tso_ctxt++;
4027 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
4028 ipv6_hdr(skb)->payload_len = 0;
4029 tcp_hdr(skb)->check =
4030 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004031 &ipv6_hdr(skb)->daddr,
4032 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004033 adapter->hw_tso6_ctxt++;
4034 }
4035
4036 i = tx_ring->next_to_use;
4037
4038 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4039 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4040
4041 /* VLAN MACLEN IPLEN */
4042 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4043 vlan_macip_lens |=
4044 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4045 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004046 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004047 *hdr_len += skb_network_offset(skb);
4048 vlan_macip_lens |=
4049 (skb_transport_header(skb) - skb_network_header(skb));
4050 *hdr_len +=
4051 (skb_transport_header(skb) - skb_network_header(skb));
4052 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4053 context_desc->seqnum_seed = 0;
4054
4055 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004056 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004057 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004058
Al Viro8327d002007-12-10 18:54:12 +00004059 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004060 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4061 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
4062 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4063
4064 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004065 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07004066 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
4067 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004068 /* use index 1 for TSO */
4069 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004070 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4071
4072 tx_buffer_info->time_stamp = jiffies;
4073 tx_buffer_info->next_to_watch = i;
4074
4075 i++;
4076 if (i == tx_ring->count)
4077 i = 0;
4078 tx_ring->next_to_use = i;
4079
4080 return true;
4081 }
4082 return false;
4083}
4084
4085static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004086 struct ixgbe_ring *tx_ring,
4087 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07004088{
4089 struct ixgbe_adv_tx_context_desc *context_desc;
4090 unsigned int i;
4091 struct ixgbe_tx_buffer *tx_buffer_info;
4092 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4093
4094 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4095 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4096 i = tx_ring->next_to_use;
4097 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4098 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4099
4100 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4101 vlan_macip_lens |=
4102 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4103 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004104 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004105 if (skb->ip_summed == CHECKSUM_PARTIAL)
4106 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004107 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07004108
4109 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4110 context_desc->seqnum_seed = 0;
4111
4112 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004113 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004114
4115 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08004116 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004117 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07004118 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08004119 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4120 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004121 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08004122 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004123 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08004124 /* XXX what about other V6 headers?? */
4125 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4126 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004127 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08004128 break;
Auke Kok41825d72008-02-12 15:20:33 -08004129 default:
4130 if (unlikely(net_ratelimit())) {
4131 DPRINTK(PROBE, WARNING,
4132 "partial checksum but proto=%x!\n",
4133 skb->protocol);
4134 }
4135 break;
4136 }
Auke Kok9a799d72007-09-15 14:07:45 -07004137 }
4138
4139 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004140 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07004141 context_desc->mss_l4len_idx = 0;
4142
4143 tx_buffer_info->time_stamp = jiffies;
4144 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004145
Auke Kok9a799d72007-09-15 14:07:45 -07004146 adapter->hw_csum_tx_good++;
4147 i++;
4148 if (i == tx_ring->count)
4149 i = 0;
4150 tx_ring->next_to_use = i;
4151
4152 return true;
4153 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004154
Auke Kok9a799d72007-09-15 14:07:45 -07004155 return false;
4156}
4157
4158static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004159 struct ixgbe_ring *tx_ring,
4160 struct sk_buff *skb, unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07004161{
4162 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004163 unsigned int len = skb_headlen(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004164 unsigned int offset = 0, size, count = 0, i;
4165 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
4166 unsigned int f;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004167 dma_addr_t *map;
Auke Kok9a799d72007-09-15 14:07:45 -07004168
4169 i = tx_ring->next_to_use;
4170
Alexander Duyck44df32c2009-03-31 21:34:23 +00004171 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
4172 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
4173 return 0;
4174 }
4175
4176 map = skb_shinfo(skb)->dma_maps;
4177
Auke Kok9a799d72007-09-15 14:07:45 -07004178 while (len) {
4179 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4180 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4181
4182 tx_buffer_info->length = size;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004183 tx_buffer_info->dma = map[0] + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004184 tx_buffer_info->time_stamp = jiffies;
4185 tx_buffer_info->next_to_watch = i;
4186
4187 len -= size;
4188 offset += size;
4189 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004190
4191 if (len) {
4192 i++;
4193 if (i == tx_ring->count)
4194 i = 0;
4195 }
Auke Kok9a799d72007-09-15 14:07:45 -07004196 }
4197
4198 for (f = 0; f < nr_frags; f++) {
4199 struct skb_frag_struct *frag;
4200
4201 frag = &skb_shinfo(skb)->frags[f];
4202 len = frag->size;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004203 offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004204
4205 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00004206 i++;
4207 if (i == tx_ring->count)
4208 i = 0;
4209
Auke Kok9a799d72007-09-15 14:07:45 -07004210 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4211 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4212
4213 tx_buffer_info->length = size;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004214 tx_buffer_info->dma = map[f + 1] + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004215 tx_buffer_info->time_stamp = jiffies;
4216 tx_buffer_info->next_to_watch = i;
4217
4218 len -= size;
4219 offset += size;
4220 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07004221 }
4222 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00004223
Auke Kok9a799d72007-09-15 14:07:45 -07004224 tx_ring->tx_buffer_info[i].skb = skb;
4225 tx_ring->tx_buffer_info[first].next_to_watch = i;
4226
4227 return count;
4228}
4229
4230static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004231 struct ixgbe_ring *tx_ring,
4232 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004233{
4234 union ixgbe_adv_tx_desc *tx_desc = NULL;
4235 struct ixgbe_tx_buffer *tx_buffer_info;
4236 u32 olinfo_status = 0, cmd_type_len = 0;
4237 unsigned int i;
4238 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
4239
4240 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
4241
4242 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
4243
4244 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4245 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
4246
4247 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
4248 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4249
4250 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004251 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004252
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004253 /* use index 1 context for tso */
4254 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004255 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
4256 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004257 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004258
4259 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
4260 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004261 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004262
4263 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
4264
4265 i = tx_ring->next_to_use;
4266 while (count--) {
4267 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4268 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
4269 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
4270 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004271 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07004272 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07004273 i++;
4274 if (i == tx_ring->count)
4275 i = 0;
4276 }
4277
4278 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
4279
4280 /*
4281 * Force memory writes to complete before letting h/w
4282 * know there are new descriptors to fetch. (Only
4283 * applicable for weak-ordered memory model archs,
4284 * such as IA-64).
4285 */
4286 wmb();
4287
4288 tx_ring->next_to_use = i;
4289 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4290}
4291
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004292static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004293 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004294{
4295 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4296
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004297 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004298 /* Herbert's original patch had:
4299 * smp_mb__after_netif_stop_queue();
4300 * but since that doesn't exist yet, just open code it. */
4301 smp_mb();
4302
4303 /* We need to check again in a case another CPU has just
4304 * made room available. */
4305 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
4306 return -EBUSY;
4307
4308 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07004309 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004310 ++adapter->restart_queue;
4311 return 0;
4312}
4313
4314static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004315 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004316{
4317 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
4318 return 0;
4319 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
4320}
4321
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07004322static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
4323{
4324 struct ixgbe_adapter *adapter = netdev_priv(dev);
4325
4326 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4327 return 0; /* All traffic should default to class 0 */
4328
4329 return skb_tx_hash(dev, skb);
4330}
4331
Auke Kok9a799d72007-09-15 14:07:45 -07004332static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
4333{
4334 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4335 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004336 unsigned int first;
4337 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004338 u8 hdr_len = 0;
4339 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07004340 int count = 0;
4341 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004342
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004343 r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004344 tx_ring = &adapter->tx_ring[r_idx];
Auke Kok9a799d72007-09-15 14:07:45 -07004345
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004346 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
4347 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004348 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4349 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
4350 tx_flags |= (skb->queue_mapping << 13);
4351 }
4352 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
4353 tx_flags |= IXGBE_TX_FLAGS_VLAN;
4354 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4355 tx_flags |= (skb->queue_mapping << 13);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004356 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
4357 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07004358 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004359 /* three things can cause us to need a context descriptor */
4360 if (skb_is_gso(skb) ||
4361 (skb->ip_summed == CHECKSUM_PARTIAL) ||
4362 (tx_flags & IXGBE_TX_FLAGS_VLAN))
Auke Kok9a799d72007-09-15 14:07:45 -07004363 count++;
4364
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004365 count += TXD_USE_COUNT(skb_headlen(skb));
4366 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07004367 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
4368
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004369 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004370 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07004371 return NETDEV_TX_BUSY;
4372 }
Auke Kok9a799d72007-09-15 14:07:45 -07004373
Al Viro8327d002007-12-10 18:54:12 +00004374 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004375 tx_flags |= IXGBE_TX_FLAGS_IPV4;
4376 first = tx_ring->next_to_use;
4377 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
4378 if (tso < 0) {
4379 dev_kfree_skb_any(skb);
4380 return NETDEV_TX_OK;
4381 }
4382
4383 if (tso)
4384 tx_flags |= IXGBE_TX_FLAGS_TSO;
4385 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004386 (skb->ip_summed == CHECKSUM_PARTIAL))
Auke Kok9a799d72007-09-15 14:07:45 -07004387 tx_flags |= IXGBE_TX_FLAGS_CSUM;
4388
Alexander Duyck44df32c2009-03-31 21:34:23 +00004389 count = ixgbe_tx_map(adapter, tx_ring, skb, first);
Auke Kok9a799d72007-09-15 14:07:45 -07004390
Alexander Duyck44df32c2009-03-31 21:34:23 +00004391 if (count) {
4392 ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
4393 hdr_len);
4394 netdev->trans_start = jiffies;
4395 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07004396
Alexander Duyck44df32c2009-03-31 21:34:23 +00004397 } else {
4398 dev_kfree_skb_any(skb);
4399 tx_ring->tx_buffer_info[first].time_stamp = 0;
4400 tx_ring->next_to_use = first;
4401 }
Auke Kok9a799d72007-09-15 14:07:45 -07004402
4403 return NETDEV_TX_OK;
4404}
4405
4406/**
4407 * ixgbe_get_stats - Get System Network Statistics
4408 * @netdev: network interface device structure
4409 *
4410 * Returns the address of the device statistics structure.
4411 * The statistics are actually updated from the timer callback.
4412 **/
4413static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
4414{
4415 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4416
4417 /* only return the current stats */
4418 return &adapter->net_stats;
4419}
4420
4421/**
4422 * ixgbe_set_mac - Change the Ethernet Address of the NIC
4423 * @netdev: network interface device structure
4424 * @p: pointer to an address structure
4425 *
4426 * Returns 0 on success, negative on failure
4427 **/
4428static int ixgbe_set_mac(struct net_device *netdev, void *p)
4429{
4430 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004431 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004432 struct sockaddr *addr = p;
4433
4434 if (!is_valid_ether_addr(addr->sa_data))
4435 return -EADDRNOTAVAIL;
4436
4437 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004438 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07004439
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004440 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004441
4442 return 0;
4443}
4444
4445#ifdef CONFIG_NET_POLL_CONTROLLER
4446/*
4447 * Polling 'interrupt' - used by things like netconsole to send skbs
4448 * without having to re-enable interrupts. It's not called while
4449 * the interrupt routine is executing.
4450 */
4451static void ixgbe_netpoll(struct net_device *netdev)
4452{
4453 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4454
4455 disable_irq(adapter->pdev->irq);
4456 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
4457 ixgbe_intr(adapter->pdev->irq, netdev);
4458 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
4459 enable_irq(adapter->pdev->irq);
4460}
4461#endif
4462
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004463static const struct net_device_ops ixgbe_netdev_ops = {
4464 .ndo_open = ixgbe_open,
4465 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08004466 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07004467 .ndo_select_queue = ixgbe_select_queue,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004468 .ndo_get_stats = ixgbe_get_stats,
Chris Leeche90d4002009-03-10 16:00:24 +00004469 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004470 .ndo_set_multicast_list = ixgbe_set_rx_mode,
4471 .ndo_validate_addr = eth_validate_addr,
4472 .ndo_set_mac_address = ixgbe_set_mac,
4473 .ndo_change_mtu = ixgbe_change_mtu,
4474 .ndo_tx_timeout = ixgbe_tx_timeout,
4475 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
4476 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
4477 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
4478#ifdef CONFIG_NET_POLL_CONTROLLER
4479 .ndo_poll_controller = ixgbe_netpoll,
4480#endif
4481};
4482
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004483/**
Auke Kok9a799d72007-09-15 14:07:45 -07004484 * ixgbe_probe - Device Initialization Routine
4485 * @pdev: PCI device information struct
4486 * @ent: entry in ixgbe_pci_tbl
4487 *
4488 * Returns 0 on success, negative on failure
4489 *
4490 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
4491 * The OS initialization, configuring of the adapter private structure,
4492 * and a hardware reset occur.
4493 **/
4494static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004495 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07004496{
4497 struct net_device *netdev;
4498 struct ixgbe_adapter *adapter = NULL;
4499 struct ixgbe_hw *hw;
4500 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07004501 static int cards_found;
4502 int i, err, pci_using_dac;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004503 u16 pm_value = 0;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004504 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07004505
4506 err = pci_enable_device(pdev);
4507 if (err)
4508 return err;
4509
4510 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4511 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
4512 pci_using_dac = 1;
4513 } else {
4514 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4515 if (err) {
4516 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
4517 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004518 dev_err(&pdev->dev, "No usable DMA "
4519 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004520 goto err_dma;
4521 }
4522 }
4523 pci_using_dac = 0;
4524 }
4525
4526 err = pci_request_regions(pdev, ixgbe_driver_name);
4527 if (err) {
4528 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
4529 goto err_pci_reg;
4530 }
4531
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004532 err = pci_enable_pcie_error_reporting(pdev);
4533 if (err) {
4534 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
4535 "0x%x\n", err);
4536 /* non-fatal, continue */
4537 }
4538
Auke Kok9a799d72007-09-15 14:07:45 -07004539 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07004540 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004541
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004542 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07004543 if (!netdev) {
4544 err = -ENOMEM;
4545 goto err_alloc_etherdev;
4546 }
4547
Auke Kok9a799d72007-09-15 14:07:45 -07004548 SET_NETDEV_DEV(netdev, &pdev->dev);
4549
4550 pci_set_drvdata(pdev, netdev);
4551 adapter = netdev_priv(netdev);
4552
4553 adapter->netdev = netdev;
4554 adapter->pdev = pdev;
4555 hw = &adapter->hw;
4556 hw->back = adapter;
4557 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
4558
Jeff Kirsher05857982008-09-11 19:57:00 -07004559 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
4560 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07004561 if (!hw->hw_addr) {
4562 err = -EIO;
4563 goto err_ioremap;
4564 }
4565
4566 for (i = 1; i <= 5; i++) {
4567 if (pci_resource_len(pdev, i) == 0)
4568 continue;
4569 }
4570
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004571 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07004572 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004573 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07004574 strcpy(netdev->name, pci_name(pdev));
4575
Auke Kok9a799d72007-09-15 14:07:45 -07004576 adapter->bd_number = cards_found;
4577
Auke Kok9a799d72007-09-15 14:07:45 -07004578 /* Setup hw api */
4579 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004580 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07004581
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004582 /* EEPROM */
4583 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
4584 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
4585 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
4586 if (!(eec & (1 << 8)))
4587 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
4588
4589 /* PHY */
4590 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08004591 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
4592
4593 /* set up this timer and work struct before calling get_invariants
4594 * which might start the timer
4595 */
4596 init_timer(&adapter->sfp_timer);
4597 adapter->sfp_timer.function = &ixgbe_sfp_timer;
4598 adapter->sfp_timer.data = (unsigned long) adapter;
4599
4600 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004601
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004602 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
4603 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
4604
4605 /* a new SFP+ module arrival, called from GPI SDP2 context */
4606 INIT_WORK(&adapter->sfp_config_module_task,
4607 ixgbe_sfp_config_module_task);
4608
Auke Kok9a799d72007-09-15 14:07:45 -07004609 err = ii->get_invariants(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004610 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
4611 /* start a kernel thread to watch for a module to arrive */
4612 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4613 mod_timer(&adapter->sfp_timer,
4614 round_jiffies(jiffies + (2 * HZ)));
4615 err = 0;
4616 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4617 DPRINTK(PROBE, ERR, "failed to load because an "
4618 "unsupported SFP+ module type was detected.\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004619 goto err_hw_init;
Donald Skidmorec4900be2008-11-20 21:11:42 -08004620 } else if (err) {
4621 goto err_hw_init;
4622 }
Auke Kok9a799d72007-09-15 14:07:45 -07004623
4624 /* setup the private structure */
4625 err = ixgbe_sw_init(adapter);
4626 if (err)
4627 goto err_sw_init;
4628
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004629 /* reset_hw fills in the perm_addr as well */
4630 err = hw->mac.ops.reset_hw(hw);
4631 if (err) {
4632 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
4633 goto err_sw_init;
4634 }
4635
Auke Kok9a799d72007-09-15 14:07:45 -07004636 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004637 NETIF_F_IP_CSUM |
4638 NETIF_F_HW_VLAN_TX |
4639 NETIF_F_HW_VLAN_RX |
4640 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004641
Jesse Brandeburge9990a92008-08-26 04:27:24 -07004642 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07004643 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07004644 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08004645 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004646
4647 netdev->vlan_features |= NETIF_F_TSO;
4648 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07004649 netdev->vlan_features |= NETIF_F_IP_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004650 netdev->vlan_features |= NETIF_F_SG;
4651
Alexander Duyck2f90b862008-11-20 20:52:10 -08004652 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4653 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4654
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004655#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004656 netdev->dcbnl_ops = &dcbnl_ops;
4657#endif
4658
Auke Kok9a799d72007-09-15 14:07:45 -07004659 if (pci_using_dac)
4660 netdev->features |= NETIF_F_HIGHDMA;
4661
Auke Kok9a799d72007-09-15 14:07:45 -07004662 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004663 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07004664 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
4665 err = -EIO;
4666 goto err_eeprom;
4667 }
4668
4669 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
4670 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
4671
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004672 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
4673 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004674 err = -EIO;
4675 goto err_eeprom;
4676 }
4677
4678 init_timer(&adapter->watchdog_timer);
4679 adapter->watchdog_timer.function = &ixgbe_watchdog;
4680 adapter->watchdog_timer.data = (unsigned long)adapter;
4681
4682 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004683 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004684
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004685 err = ixgbe_init_interrupt_scheme(adapter);
4686 if (err)
4687 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07004688
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004689 switch (pdev->device) {
4690 case IXGBE_DEV_ID_82599_KX4:
4691#define IXGBE_PCIE_PMCSR 0x44
4692 adapter->wol = IXGBE_WUFC_MAG;
4693 pci_read_config_word(pdev, IXGBE_PCIE_PMCSR, &pm_value);
4694 pci_write_config_word(pdev, IXGBE_PCIE_PMCSR,
4695 (pm_value | (1 << 8)));
4696 break;
4697 default:
4698 adapter->wol = 0;
4699 break;
4700 }
4701 device_init_wakeup(&adapter->pdev->dev, true);
4702 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
4703
Auke Kok9a799d72007-09-15 14:07:45 -07004704 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07004705 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004706 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
4707 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
4708 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
4709 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
4710 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004711 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07004712 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004713 ixgbe_read_pba_num_generic(hw, &part_num);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004714 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
4715 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
4716 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
4717 (part_num >> 8), (part_num & 0xff));
4718 else
4719 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4720 hw->mac.type, hw->phy.type,
4721 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07004722
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004723 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Auke Kok0c254d82008-02-11 09:25:56 -08004724 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004725 "this card is not sufficient for optimal "
4726 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004727 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004728 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004729 }
4730
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08004731 /* save off EEPROM version number */
4732 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
4733
Auke Kok9a799d72007-09-15 14:07:45 -07004734 /* reset the hardware with the new settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004735 hw->mac.ops.start_hw(hw);
4736
Auke Kok9a799d72007-09-15 14:07:45 -07004737 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004738
4739 strcpy(netdev->name, "eth%d");
4740 err = register_netdev(netdev);
4741 if (err)
4742 goto err_register;
4743
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004744#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03004745 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004746 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
4747 /* always use CB2 mode, difference is masked
4748 * in the CB driver */
4749 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
4750 ixgbe_setup_dca(adapter);
4751 }
4752#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004753
4754 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
4755 cards_found++;
4756 return 0;
4757
4758err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004759 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004760err_hw_init:
4761err_sw_init:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004762 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004763err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08004764 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4765 del_timer_sync(&adapter->sfp_timer);
4766 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004767 cancel_work_sync(&adapter->multispeed_fiber_task);
4768 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004769 iounmap(hw->hw_addr);
4770err_ioremap:
4771 free_netdev(netdev);
4772err_alloc_etherdev:
4773 pci_release_regions(pdev);
4774err_pci_reg:
4775err_dma:
4776 pci_disable_device(pdev);
4777 return err;
4778}
4779
4780/**
4781 * ixgbe_remove - Device Removal Routine
4782 * @pdev: PCI device information struct
4783 *
4784 * ixgbe_remove is called by the PCI subsystem to alert the driver
4785 * that it should release a PCI device. The could be caused by a
4786 * Hot-Plug event, or because the driver is going to be removed from
4787 * memory.
4788 **/
4789static void __devexit ixgbe_remove(struct pci_dev *pdev)
4790{
4791 struct net_device *netdev = pci_get_drvdata(pdev);
4792 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004793 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004794
4795 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004796 /* clear the module not found bit to make sure the worker won't
4797 * reschedule
4798 */
4799 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07004800 del_timer_sync(&adapter->watchdog_timer);
4801
Donald Skidmorec4900be2008-11-20 21:11:42 -08004802 del_timer_sync(&adapter->sfp_timer);
4803 cancel_work_sync(&adapter->watchdog_task);
4804 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004805 cancel_work_sync(&adapter->multispeed_fiber_task);
4806 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004807 flush_scheduled_work();
4808
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004809#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004810 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
4811 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
4812 dca_remove_requester(&pdev->dev);
4813 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
4814 }
4815
4816#endif
Donald Skidmorec4900be2008-11-20 21:11:42 -08004817 if (netdev->reg_state == NETREG_REGISTERED)
4818 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004819
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004820 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004821
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004822 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004823
4824 iounmap(adapter->hw.hw_addr);
4825 pci_release_regions(pdev);
4826
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004827 DPRINTK(PROBE, INFO, "complete\n");
4828 kfree(adapter->tx_ring);
4829 kfree(adapter->rx_ring);
4830
Auke Kok9a799d72007-09-15 14:07:45 -07004831 free_netdev(netdev);
4832
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004833 err = pci_disable_pcie_error_reporting(pdev);
4834 if (err)
4835 dev_err(&pdev->dev,
4836 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
4837
Auke Kok9a799d72007-09-15 14:07:45 -07004838 pci_disable_device(pdev);
4839}
4840
4841/**
4842 * ixgbe_io_error_detected - called when PCI error is detected
4843 * @pdev: Pointer to PCI device
4844 * @state: The current pci connection state
4845 *
4846 * This function is called after a PCI bus error affecting
4847 * this device has been detected.
4848 */
4849static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004850 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07004851{
4852 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004853 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004854
4855 netif_device_detach(netdev);
4856
4857 if (netif_running(netdev))
4858 ixgbe_down(adapter);
4859 pci_disable_device(pdev);
4860
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004861 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07004862 return PCI_ERS_RESULT_NEED_RESET;
4863}
4864
4865/**
4866 * ixgbe_io_slot_reset - called after the pci bus has been reset.
4867 * @pdev: Pointer to PCI device
4868 *
4869 * Restart the card from scratch, as if from a cold-boot.
4870 */
4871static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
4872{
4873 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004874 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004875 pci_ers_result_t result;
4876 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004877
4878 if (pci_enable_device(pdev)) {
4879 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004880 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004881 result = PCI_ERS_RESULT_DISCONNECT;
4882 } else {
4883 pci_set_master(pdev);
4884 pci_restore_state(pdev);
4885
4886 pci_enable_wake(pdev, PCI_D3hot, 0);
4887 pci_enable_wake(pdev, PCI_D3cold, 0);
4888
4889 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00004890 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004891 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07004892 }
Auke Kok9a799d72007-09-15 14:07:45 -07004893
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004894 err = pci_cleanup_aer_uncorrect_error_status(pdev);
4895 if (err) {
4896 dev_err(&pdev->dev,
4897 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
4898 /* non-fatal, continue */
4899 }
Auke Kok9a799d72007-09-15 14:07:45 -07004900
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004901 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07004902}
4903
4904/**
4905 * ixgbe_io_resume - called when traffic can start flowing again.
4906 * @pdev: Pointer to PCI device
4907 *
4908 * This callback is called when the error recovery driver tells us that
4909 * its OK to resume normal operation.
4910 */
4911static void ixgbe_io_resume(struct pci_dev *pdev)
4912{
4913 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004914 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004915
4916 if (netif_running(netdev)) {
4917 if (ixgbe_up(adapter)) {
4918 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
4919 return;
4920 }
4921 }
4922
4923 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004924}
4925
4926static struct pci_error_handlers ixgbe_err_handler = {
4927 .error_detected = ixgbe_io_error_detected,
4928 .slot_reset = ixgbe_io_slot_reset,
4929 .resume = ixgbe_io_resume,
4930};
4931
4932static struct pci_driver ixgbe_driver = {
4933 .name = ixgbe_driver_name,
4934 .id_table = ixgbe_pci_tbl,
4935 .probe = ixgbe_probe,
4936 .remove = __devexit_p(ixgbe_remove),
4937#ifdef CONFIG_PM
4938 .suspend = ixgbe_suspend,
4939 .resume = ixgbe_resume,
4940#endif
4941 .shutdown = ixgbe_shutdown,
4942 .err_handler = &ixgbe_err_handler
4943};
4944
4945/**
4946 * ixgbe_init_module - Driver Registration Routine
4947 *
4948 * ixgbe_init_module is the first routine called when the driver is
4949 * loaded. All it does is register with the PCI subsystem.
4950 **/
4951static int __init ixgbe_init_module(void)
4952{
4953 int ret;
4954 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
4955 ixgbe_driver_string, ixgbe_driver_version);
4956
4957 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
4958
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004959#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004960 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004961#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004962
Auke Kok9a799d72007-09-15 14:07:45 -07004963 ret = pci_register_driver(&ixgbe_driver);
4964 return ret;
4965}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004966
Auke Kok9a799d72007-09-15 14:07:45 -07004967module_init(ixgbe_init_module);
4968
4969/**
4970 * ixgbe_exit_module - Driver Exit Cleanup Routine
4971 *
4972 * ixgbe_exit_module is called just before the driver is removed
4973 * from memory.
4974 **/
4975static void __exit ixgbe_exit_module(void)
4976{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004977#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004978 dca_unregister_notify(&dca_notifier);
4979#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004980 pci_unregister_driver(&ixgbe_driver);
4981}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004982
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004983#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004984static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004985 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004986{
4987 int ret_val;
4988
4989 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004990 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004991
4992 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4993}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004994
Alexander Duyckb4533682009-03-31 21:32:42 +00004995#endif /* CONFIG_IXGBE_DCA */
4996#ifdef DEBUG
4997/**
4998 * ixgbe_get_hw_dev_name - return device name string
4999 * used by hardware layer to print debugging information
5000 **/
5001char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
5002{
5003 struct ixgbe_adapter *adapter = hw->back;
5004 return adapter->netdev->name;
5005}
5006
5007#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005008module_exit(ixgbe_exit_module);
5009
5010/* ixgbe_main.c */