blob: 419ce472cef8dd90948d3c44d434c14a71615330 [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
Peter P Waskiewicz Jr04193052009-04-09 22:28:50 +000050#define DRV_VERSION "2.0.16-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]);
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000462 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
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 {
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000468 if (adapter->vlgrp && is_vlan && (tag != 0))
469 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
470 else
471 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700472 }
473}
474
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800475/**
476 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
477 * @adapter: address of board private structure
478 * @status_err: hardware indication of status of receive
479 * @skb: skb currently being received and modified
480 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700481static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700482 u32 status_err, struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700483{
484 skb->ip_summed = CHECKSUM_NONE;
485
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700486 /* Rx csum disabled */
487 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -0700488 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800489
490 /* if IP and error */
491 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
492 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700493 adapter->hw_csum_rx_error++;
494 return;
495 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800496
497 if (!(status_err & IXGBE_RXD_STAT_L4CS))
498 return;
499
500 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
501 adapter->hw_csum_rx_error++;
502 return;
503 }
504
Auke Kok9a799d72007-09-15 14:07:45 -0700505 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800506 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -0700507 adapter->hw_csum_rx_good++;
508}
509
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000510static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
511 struct ixgbe_ring *rx_ring, u32 val)
512{
513 /*
514 * Force memory writes to complete before letting h/w
515 * know there are new descriptors to fetch. (Only
516 * applicable for weak-ordered memory model archs,
517 * such as IA-64).
518 */
519 wmb();
520 IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
521}
522
Auke Kok9a799d72007-09-15 14:07:45 -0700523/**
524 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
525 * @adapter: address of board private structure
526 **/
527static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700528 struct ixgbe_ring *rx_ring,
529 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700530{
Auke Kok9a799d72007-09-15 14:07:45 -0700531 struct pci_dev *pdev = adapter->pdev;
532 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700533 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700534 unsigned int i;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000535 unsigned int bufsz = rx_ring->rx_buf_len + NET_IP_ALIGN;
Auke Kok9a799d72007-09-15 14:07:45 -0700536
537 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700538 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700539
540 while (cleaned_count--) {
541 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
542
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700543 if (!bi->page_dma &&
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700544 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700545 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700546 bi->page = alloc_page(GFP_ATOMIC);
547 if (!bi->page) {
548 adapter->alloc_rx_page_failed++;
549 goto no_buffers;
550 }
551 bi->page_offset = 0;
552 } else {
553 /* use a half page if we're re-using */
554 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700555 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700556
557 bi->page_dma = pci_map_page(pdev, bi->page,
558 bi->page_offset,
559 (PAGE_SIZE / 2),
560 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700561 }
562
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700563 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800564 struct sk_buff *skb;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000565 skb = netdev_alloc_skb(adapter->netdev, bufsz);
Auke Kok9a799d72007-09-15 14:07:45 -0700566
567 if (!skb) {
568 adapter->alloc_rx_buff_failed++;
569 goto no_buffers;
570 }
571
572 /*
573 * Make buffer alignment 2 beyond a 16 byte boundary
574 * this will result in a 16 byte aligned IP header after
575 * the 14 byte MAC header is removed
576 */
577 skb_reserve(skb, NET_IP_ALIGN);
578
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700579 bi->skb = skb;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000580 bi->dma = pci_map_single(pdev, skb->data, bufsz,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700581 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700582 }
583 /* Refresh the desc even if buffer_addrs didn't change because
584 * each write-back erases this info. */
585 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700586 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
587 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700588 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700589 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700590 }
591
592 i++;
593 if (i == rx_ring->count)
594 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700595 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700596 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700597
Auke Kok9a799d72007-09-15 14:07:45 -0700598no_buffers:
599 if (rx_ring->next_to_use != i) {
600 rx_ring->next_to_use = i;
601 if (i-- == 0)
602 i = (rx_ring->count - 1);
603
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000604 ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700605 }
606}
607
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700608static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
609{
610 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
611}
612
613static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
614{
615 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
616}
617
Alexander Duyckf8212f92009-04-27 22:42:37 +0000618static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
619{
620 return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
621 IXGBE_RXDADV_RSCCNT_MASK) >>
622 IXGBE_RXDADV_RSCCNT_SHIFT;
623}
624
625/**
626 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
627 * @skb: pointer to the last skb in the rsc queue
628 *
629 * This function changes a queue full of hw rsc buffers into a completed
630 * packet. It uses the ->prev pointers to find the first packet and then
631 * turns it into the frag list owner.
632 **/
633static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
634{
635 unsigned int frag_list_size = 0;
636
637 while (skb->prev) {
638 struct sk_buff *prev = skb->prev;
639 frag_list_size += skb->len;
640 skb->prev = NULL;
641 skb = prev;
642 }
643
644 skb_shinfo(skb)->frag_list = skb->next;
645 skb->next = NULL;
646 skb->len += frag_list_size;
647 skb->data_len += frag_list_size;
648 skb->truesize += frag_list_size;
649 return skb;
650}
651
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800652static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700653 struct ixgbe_ring *rx_ring,
654 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700655{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800656 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -0700657 struct pci_dev *pdev = adapter->pdev;
658 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
659 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
660 struct sk_buff *skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000661 unsigned int i, rsc_count = 0;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700662 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700663 u16 hdr_info;
664 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700665 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800666 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700667
668 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700669 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
670 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
671 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700672
673 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700674 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700675 if (*work_done >= work_to_do)
676 break;
677 (*work_done)++;
678
679 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700680 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
681 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700682 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700683 if (hdr_info & IXGBE_RXDADV_SPH)
684 adapter->rx_hdr_split++;
685 if (len > IXGBE_RX_HDR_SIZE)
686 len = IXGBE_RX_HDR_SIZE;
687 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700688 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700689 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700690 }
Auke Kok9a799d72007-09-15 14:07:45 -0700691
692 cleaned = true;
693 skb = rx_buffer_info->skb;
694 prefetch(skb->data - NET_IP_ALIGN);
695 rx_buffer_info->skb = NULL;
696
697 if (len && !skb_shinfo(skb)->nr_frags) {
698 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800699 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700700 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700701 skb_put(skb, len);
702 }
703
704 if (upper_len) {
705 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700706 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700707 rx_buffer_info->page_dma = 0;
708 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700709 rx_buffer_info->page,
710 rx_buffer_info->page_offset,
711 upper_len);
712
713 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
714 (page_count(rx_buffer_info->page) != 1))
715 rx_buffer_info->page = NULL;
716 else
717 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700718
719 skb->len += upper_len;
720 skb->data_len += upper_len;
721 skb->truesize += upper_len;
722 }
723
724 i++;
725 if (i == rx_ring->count)
726 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700727
728 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
729 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -0700730 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000731
732 if (adapter->flags & IXGBE_FLAG_RSC_CAPABLE)
733 rsc_count = ixgbe_get_rsc_count(rx_desc);
734
735 if (rsc_count) {
736 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
737 IXGBE_RXDADV_NEXTP_SHIFT;
738 next_buffer = &rx_ring->rx_buffer_info[nextp];
739 rx_ring->rsc_count += (rsc_count - 1);
740 } else {
741 next_buffer = &rx_ring->rx_buffer_info[i];
742 }
743
Auke Kok9a799d72007-09-15 14:07:45 -0700744 if (staterr & IXGBE_RXD_STAT_EOP) {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000745 if (skb->prev)
746 skb = ixgbe_transform_rsc_queue(skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700747 rx_ring->stats.packets++;
748 rx_ring->stats.bytes += skb->len;
749 } else {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000750 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
751 rx_buffer_info->skb = next_buffer->skb;
752 rx_buffer_info->dma = next_buffer->dma;
753 next_buffer->skb = skb;
754 next_buffer->dma = 0;
755 } else {
756 skb->next = next_buffer->skb;
757 skb->next->prev = skb;
758 }
Auke Kok9a799d72007-09-15 14:07:45 -0700759 adapter->non_eop_descs++;
760 goto next_desc;
761 }
762
763 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
764 dev_kfree_skb_irq(skb);
765 goto next_desc;
766 }
767
768 ixgbe_rx_checksum(adapter, staterr, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800769
770 /* probably a little skewed due to removing CRC */
771 total_rx_bytes += skb->len;
772 total_rx_packets++;
773
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700774 skb->protocol = eth_type_trans(skb, adapter->netdev);
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800775 ixgbe_receive_skb(q_vector, skb, staterr, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700776
777next_desc:
778 rx_desc->wb.upper.status_error = 0;
779
780 /* return some buffers to hardware, one at a time is too slow */
781 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
782 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
783 cleaned_count = 0;
784 }
785
786 /* use prefetched values */
787 rx_desc = next_rxd;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000788 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700789
790 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700791 }
792
Auke Kok9a799d72007-09-15 14:07:45 -0700793 rx_ring->next_to_clean = i;
794 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
795
796 if (cleaned_count)
797 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
798
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800799 rx_ring->total_packets += total_rx_packets;
800 rx_ring->total_bytes += total_rx_bytes;
801 adapter->net_stats.rx_bytes += total_rx_bytes;
802 adapter->net_stats.rx_packets += total_rx_packets;
803
Auke Kok9a799d72007-09-15 14:07:45 -0700804 return cleaned;
805}
806
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800807static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700808/**
809 * ixgbe_configure_msix - Configure MSI-X hardware
810 * @adapter: board private structure
811 *
812 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
813 * interrupts.
814 **/
815static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
816{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800817 struct ixgbe_q_vector *q_vector;
818 int i, j, q_vectors, v_idx, r_idx;
819 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700820
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800821 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
822
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000823 /*
824 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800825 * corresponding register.
826 */
827 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
828 q_vector = &adapter->q_vector[v_idx];
829 /* XXX for_each_bit(...) */
830 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700831 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800832
833 for (i = 0; i < q_vector->rxr_count; i++) {
834 j = adapter->rx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000835 ixgbe_set_ivar(adapter, 0, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800836 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700837 adapter->num_rx_queues,
838 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800839 }
840 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700841 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800842
843 for (i = 0; i < q_vector->txr_count; i++) {
844 j = adapter->tx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000845 ixgbe_set_ivar(adapter, 1, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800846 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700847 adapter->num_tx_queues,
848 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800849 }
850
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700851 /* if this is a tx only vector halve the interrupt rate */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800852 if (q_vector->txr_count && !q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700853 q_vector->eitr = (adapter->eitr_param >> 1);
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000854 else if (q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700855 /* rx only */
856 q_vector->eitr = adapter->eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800857
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000858 /*
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000859 * since this is initial set up don't need to call
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000860 * ixgbe_write_eitr helper
861 */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800862 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx),
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700863 EITR_INTS_PER_SEC_TO_REG(q_vector->eitr));
Auke Kok9a799d72007-09-15 14:07:45 -0700864 }
865
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000866 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
867 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
868 v_idx);
869 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
870 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800871 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -0700872
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700873 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800874 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700875 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800876 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -0700877}
878
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800879enum latency_range {
880 lowest_latency = 0,
881 low_latency = 1,
882 bulk_latency = 2,
883 latency_invalid = 255
884};
885
886/**
887 * ixgbe_update_itr - update the dynamic ITR value based on statistics
888 * @adapter: pointer to adapter
889 * @eitr: eitr setting (ints per sec) to give last timeslice
890 * @itr_setting: current throttle rate in ints/second
891 * @packets: the number of packets during this measurement interval
892 * @bytes: the number of bytes during this measurement interval
893 *
894 * Stores a new ITR value based on packets and byte
895 * counts during the last interrupt. The advantage of per interrupt
896 * computation is faster updates and more accurate ITR for the current
897 * traffic pattern. Constants in this function were computed
898 * based on theoretical maximum wire speed and thresholds were set based
899 * on testing data as well as attempting to minimize response time
900 * while increasing bulk throughput.
901 * this functionality is controlled by the InterruptThrottleRate module
902 * parameter (see ixgbe_param.c)
903 **/
904static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700905 u32 eitr, u8 itr_setting,
906 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800907{
908 unsigned int retval = itr_setting;
909 u32 timepassed_us;
910 u64 bytes_perint;
911
912 if (packets == 0)
913 goto update_itr_done;
914
915
916 /* simple throttlerate management
917 * 0-20MB/s lowest (100000 ints/s)
918 * 20-100MB/s low (20000 ints/s)
919 * 100-1249MB/s bulk (8000 ints/s)
920 */
921 /* what was last interrupt timeslice? */
922 timepassed_us = 1000000/eitr;
923 bytes_perint = bytes / timepassed_us; /* bytes/usec */
924
925 switch (itr_setting) {
926 case lowest_latency:
927 if (bytes_perint > adapter->eitr_low)
928 retval = low_latency;
929 break;
930 case low_latency:
931 if (bytes_perint > adapter->eitr_high)
932 retval = bulk_latency;
933 else if (bytes_perint <= adapter->eitr_low)
934 retval = lowest_latency;
935 break;
936 case bulk_latency:
937 if (bytes_perint <= adapter->eitr_high)
938 retval = low_latency;
939 break;
940 }
941
942update_itr_done:
943 return retval;
944}
945
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000946/**
947 * ixgbe_write_eitr - write EITR register in hardware specific way
948 * @adapter: pointer to adapter struct
949 * @v_idx: vector index into q_vector array
950 * @itr_reg: new value to be written in *register* format, not ints/s
951 *
952 * This function is made to be called by ethtool and by the driver
953 * when it needs to update EITR registers at runtime. Hardware
954 * specific quirks/differences are taken care of here.
955 */
956void ixgbe_write_eitr(struct ixgbe_adapter *adapter, int v_idx, u32 itr_reg)
957{
958 struct ixgbe_hw *hw = &adapter->hw;
959 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
960 /* must write high and low 16 bits to reset counter */
961 itr_reg |= (itr_reg << 16);
962 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
963 /*
964 * set the WDIS bit to not clear the timer bits and cause an
965 * immediate assertion of the interrupt
966 */
967 itr_reg |= IXGBE_EITR_CNT_WDIS;
968 }
969 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
970}
971
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800972static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
973{
974 struct ixgbe_adapter *adapter = q_vector->adapter;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800975 u32 new_itr;
976 u8 current_itr, ret_itr;
977 int i, r_idx, v_idx = ((void *)q_vector - (void *)(adapter->q_vector)) /
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700978 sizeof(struct ixgbe_q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800979 struct ixgbe_ring *rx_ring, *tx_ring;
980
981 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
982 for (i = 0; i < q_vector->txr_count; i++) {
983 tx_ring = &(adapter->tx_ring[r_idx]);
984 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700985 q_vector->tx_itr,
986 tx_ring->total_packets,
987 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800988 /* if the result for this queue would decrease interrupt
989 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700990 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700991 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800992 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700993 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800994 }
995
996 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
997 for (i = 0; i < q_vector->rxr_count; i++) {
998 rx_ring = &(adapter->rx_ring[r_idx]);
999 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001000 q_vector->rx_itr,
1001 rx_ring->total_packets,
1002 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001003 /* if the result for this queue would decrease interrupt
1004 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001005 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001006 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001007 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001008 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001009 }
1010
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001011 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001012
1013 switch (current_itr) {
1014 /* counts and packets in update_itr are dependent on these numbers */
1015 case lowest_latency:
1016 new_itr = 100000;
1017 break;
1018 case low_latency:
1019 new_itr = 20000; /* aka hwitr = ~200 */
1020 break;
1021 case bulk_latency:
1022 default:
1023 new_itr = 8000;
1024 break;
1025 }
1026
1027 if (new_itr != q_vector->eitr) {
1028 u32 itr_reg;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001029
1030 /* save the algorithm value here, not the smoothed one */
1031 q_vector->eitr = new_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001032 /* do an exponential smoothing */
1033 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001034 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001035 ixgbe_write_eitr(adapter, v_idx, itr_reg);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001036 }
1037
1038 return;
1039}
1040
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001041static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1042{
1043 struct ixgbe_hw *hw = &adapter->hw;
1044
1045 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1046 (eicr & IXGBE_EICR_GPI_SDP1)) {
1047 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
1048 /* write to clear the interrupt */
1049 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1050 }
1051}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001052
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001053static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1054{
1055 struct ixgbe_hw *hw = &adapter->hw;
1056
1057 if (eicr & IXGBE_EICR_GPI_SDP1) {
1058 /* Clear the interrupt */
1059 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1060 schedule_work(&adapter->multispeed_fiber_task);
1061 } else if (eicr & IXGBE_EICR_GPI_SDP2) {
1062 /* Clear the interrupt */
1063 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1064 schedule_work(&adapter->sfp_config_module_task);
1065 } else {
1066 /* Interrupt isn't for us... */
1067 return;
1068 }
1069}
1070
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001071static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1072{
1073 struct ixgbe_hw *hw = &adapter->hw;
1074
1075 adapter->lsc_int++;
1076 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1077 adapter->link_check_timeout = jiffies;
1078 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1079 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1080 schedule_work(&adapter->watchdog_task);
1081 }
1082}
1083
Auke Kok9a799d72007-09-15 14:07:45 -07001084static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1085{
1086 struct net_device *netdev = data;
1087 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1088 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001089 u32 eicr;
1090
1091 /*
1092 * Workaround for Silicon errata. Use clear-by-write instead
1093 * of clear-by-read. Reading with EICS will return the
1094 * interrupt causes without clearing, which later be done
1095 * with the write to EICR.
1096 */
1097 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1098 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001099
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001100 if (eicr & IXGBE_EICR_LSC)
1101 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001102
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001103 if (hw->mac.type == ixgbe_mac_82598EB)
1104 ixgbe_check_fan_failure(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001105
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001106 if (hw->mac.type == ixgbe_mac_82599EB)
1107 ixgbe_check_sfp_event(adapter, eicr);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001108 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1109 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -07001110
1111 return IRQ_HANDLED;
1112}
1113
1114static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1115{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001116 struct ixgbe_q_vector *q_vector = data;
1117 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001118 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001119 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001120
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001121 if (!q_vector->txr_count)
1122 return IRQ_HANDLED;
1123
1124 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1125 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001126 tx_ring = &(adapter->tx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001127#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001128 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001129 ixgbe_update_tx_dca(adapter, tx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001130#endif
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001131 tx_ring->total_bytes = 0;
1132 tx_ring->total_packets = 0;
1133 ixgbe_clean_tx_irq(adapter, tx_ring);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001134 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001135 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001136 }
1137
Auke Kok9a799d72007-09-15 14:07:45 -07001138 return IRQ_HANDLED;
1139}
1140
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001141/**
1142 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1143 * @irq: unused
1144 * @data: pointer to our q_vector struct for this interrupt vector
1145 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001146static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1147{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001148 struct ixgbe_q_vector *q_vector = data;
1149 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001150 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001151 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001152 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001153
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001154 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001155 for (i = 0; i < q_vector->rxr_count; i++) {
1156 rx_ring = &(adapter->rx_ring[r_idx]);
1157 rx_ring->total_bytes = 0;
1158 rx_ring->total_packets = 0;
1159 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1160 r_idx + 1);
1161 }
1162
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001163 if (!q_vector->rxr_count)
1164 return IRQ_HANDLED;
1165
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001166 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001167 rx_ring = &(adapter->rx_ring[r_idx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001168 /* disable interrupts on this vector only */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001169 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rx_ring->v_idx);
Ben Hutchings288379f2009-01-19 16:43:59 -08001170 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001171
Auke Kok9a799d72007-09-15 14:07:45 -07001172 return IRQ_HANDLED;
1173}
1174
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001175static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1176{
1177 ixgbe_msix_clean_rx(irq, data);
1178 ixgbe_msix_clean_tx(irq, data);
1179
1180 return IRQ_HANDLED;
1181}
1182
1183/**
1184 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1185 * @napi: napi struct with our devices info in it
1186 * @budget: amount of work driver is allowed to do this pass, in packets
1187 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001188 * This function is optimized for cleaning one queue only on a single
1189 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001190 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001191static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1192{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001193 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001194 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001195 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001196 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001197 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001198 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001199
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001200 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001201 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001202#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001203 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001204 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001205#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001206
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001207 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001208
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001209 /* If all Rx work done, exit the polling mode */
1210 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001211 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001212 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001213 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001214 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001215 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rx_ring->v_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07001216 }
1217
1218 return work_done;
1219}
1220
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001221/**
1222 * ixgbe_clean_rxonly_many - msix (aka one shot) rx clean routine
1223 * @napi: napi struct with our devices info in it
1224 * @budget: amount of work driver is allowed to do this pass, in packets
1225 *
1226 * This function will clean more than one rx queue associated with a
1227 * q_vector.
1228 **/
1229static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget)
1230{
1231 struct ixgbe_q_vector *q_vector =
1232 container_of(napi, struct ixgbe_q_vector, napi);
1233 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001234 struct ixgbe_ring *rx_ring = NULL;
1235 int work_done = 0, i;
1236 long r_idx;
1237 u16 enable_mask = 0;
1238
1239 /* attempt to distribute budget to each queue fairly, but don't allow
1240 * the budget to go below 1 because we'll exit polling */
1241 budget /= (q_vector->rxr_count ?: 1);
1242 budget = max(budget, 1);
1243 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1244 for (i = 0; i < q_vector->rxr_count; i++) {
1245 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001246#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001247 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1248 ixgbe_update_rx_dca(adapter, rx_ring);
1249#endif
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001250 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001251 enable_mask |= rx_ring->v_idx;
1252 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1253 r_idx + 1);
1254 }
1255
1256 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1257 rx_ring = &(adapter->rx_ring[r_idx]);
1258 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001259 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001260 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001261 if (adapter->itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001262 ixgbe_set_itr_msix(q_vector);
1263 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1264 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, enable_mask);
1265 return 0;
1266 }
1267
1268 return work_done;
1269}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001270static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001271 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001272{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001273 a->q_vector[v_idx].adapter = a;
1274 set_bit(r_idx, a->q_vector[v_idx].rxr_idx);
1275 a->q_vector[v_idx].rxr_count++;
1276 a->rx_ring[r_idx].v_idx = 1 << v_idx;
1277}
Auke Kok9a799d72007-09-15 14:07:45 -07001278
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001279static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001280 int r_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001281{
1282 a->q_vector[v_idx].adapter = a;
1283 set_bit(r_idx, a->q_vector[v_idx].txr_idx);
1284 a->q_vector[v_idx].txr_count++;
1285 a->tx_ring[r_idx].v_idx = 1 << v_idx;
1286}
Auke Kok9a799d72007-09-15 14:07:45 -07001287
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001288/**
1289 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1290 * @adapter: board private structure to initialize
1291 * @vectors: allotted vector count for descriptor rings
1292 *
1293 * This function maps descriptor rings to the queue-specific vectors
1294 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1295 * one vector per ring/queue, but on a constrained vector budget, we
1296 * group the rings as "efficiently" as possible. You would add new
1297 * mapping configurations in here.
1298 **/
1299static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001300 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001301{
1302 int v_start = 0;
1303 int rxr_idx = 0, txr_idx = 0;
1304 int rxr_remaining = adapter->num_rx_queues;
1305 int txr_remaining = adapter->num_tx_queues;
1306 int i, j;
1307 int rqpv, tqpv;
1308 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001309
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001310 /* No mapping required if MSI-X is disabled. */
1311 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001312 goto out;
1313
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001314 /*
1315 * The ideal configuration...
1316 * We have enough vectors to map one per queue.
1317 */
1318 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1319 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1320 map_vector_to_rxq(adapter, v_start, rxr_idx);
1321
1322 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1323 map_vector_to_txq(adapter, v_start, txr_idx);
1324
1325 goto out;
1326 }
1327
1328 /*
1329 * If we don't have enough vectors for a 1-to-1
1330 * mapping, we'll have to group them so there are
1331 * multiple queues per vector.
1332 */
1333 /* Re-adjusting *qpv takes care of the remainder. */
1334 for (i = v_start; i < vectors; i++) {
1335 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1336 for (j = 0; j < rqpv; j++) {
1337 map_vector_to_rxq(adapter, i, rxr_idx);
1338 rxr_idx++;
1339 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001340 }
Auke Kok9a799d72007-09-15 14:07:45 -07001341 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001342 for (i = v_start; i < vectors; i++) {
1343 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1344 for (j = 0; j < tqpv; j++) {
1345 map_vector_to_txq(adapter, i, txr_idx);
1346 txr_idx++;
1347 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001348 }
Auke Kok9a799d72007-09-15 14:07:45 -07001349 }
1350
Auke Kok9a799d72007-09-15 14:07:45 -07001351out:
Auke Kok9a799d72007-09-15 14:07:45 -07001352 return err;
1353}
1354
1355/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001356 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1357 * @adapter: board private structure
1358 *
1359 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1360 * interrupts from the kernel.
1361 **/
1362static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1363{
1364 struct net_device *netdev = adapter->netdev;
1365 irqreturn_t (*handler)(int, void *);
1366 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001367 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001368
1369 /* Decrement for Other and TCP Timer vectors */
1370 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1371
1372 /* Map the Tx/Rx rings to the vectors we were allotted. */
1373 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1374 if (err)
1375 goto out;
1376
1377#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001378 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1379 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001380 for (vector = 0; vector < q_vectors; vector++) {
1381 handler = SET_HANDLER(&adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001382
1383 if(handler == &ixgbe_msix_clean_rx) {
1384 sprintf(adapter->name[vector], "%s-%s-%d",
1385 netdev->name, "rx", ri++);
1386 }
1387 else if(handler == &ixgbe_msix_clean_tx) {
1388 sprintf(adapter->name[vector], "%s-%s-%d",
1389 netdev->name, "tx", ti++);
1390 }
1391 else
1392 sprintf(adapter->name[vector], "%s-%s-%d",
1393 netdev->name, "TxRx", vector);
1394
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001395 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001396 handler, 0, adapter->name[vector],
1397 &(adapter->q_vector[vector]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001398 if (err) {
1399 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001400 "request_irq failed for MSIX interrupt "
1401 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001402 goto free_queue_irqs;
1403 }
1404 }
1405
1406 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1407 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001408 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001409 if (err) {
1410 DPRINTK(PROBE, ERR,
1411 "request_irq for msix_lsc failed: %d\n", err);
1412 goto free_queue_irqs;
1413 }
1414
1415 return 0;
1416
1417free_queue_irqs:
1418 for (i = vector - 1; i >= 0; i--)
1419 free_irq(adapter->msix_entries[--vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001420 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001421 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1422 pci_disable_msix(adapter->pdev);
1423 kfree(adapter->msix_entries);
1424 adapter->msix_entries = NULL;
1425out:
1426 return err;
1427}
1428
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001429static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1430{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001431 struct ixgbe_q_vector *q_vector = adapter->q_vector;
1432 u8 current_itr;
1433 u32 new_itr = q_vector->eitr;
1434 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1435 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1436
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001437 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001438 q_vector->tx_itr,
1439 tx_ring->total_packets,
1440 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001441 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001442 q_vector->rx_itr,
1443 rx_ring->total_packets,
1444 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001445
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001446 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001447
1448 switch (current_itr) {
1449 /* counts and packets in update_itr are dependent on these numbers */
1450 case lowest_latency:
1451 new_itr = 100000;
1452 break;
1453 case low_latency:
1454 new_itr = 20000; /* aka hwitr = ~200 */
1455 break;
1456 case bulk_latency:
1457 new_itr = 8000;
1458 break;
1459 default:
1460 break;
1461 }
1462
1463 if (new_itr != q_vector->eitr) {
1464 u32 itr_reg;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001465
1466 /* save the algorithm value here, not the smoothed one */
1467 q_vector->eitr = new_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001468 /* do an exponential smoothing */
1469 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001470 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001471 ixgbe_write_eitr(adapter, 0, itr_reg);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001472 }
1473
1474 return;
1475}
1476
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001477/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001478 * ixgbe_irq_enable - Enable default interrupt generation settings
1479 * @adapter: board private structure
1480 **/
1481static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1482{
1483 u32 mask;
1484 mask = IXGBE_EIMS_ENABLE_MASK;
David S. Miller6ab33d52008-11-20 16:44:00 -08001485 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1486 mask |= IXGBE_EIMS_GPI_SDP1;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001487 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001488 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001489 mask |= IXGBE_EIMS_GPI_SDP1;
1490 mask |= IXGBE_EIMS_GPI_SDP2;
1491 }
1492
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001493 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001494 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1495 /* enable the rest of the queue vectors */
1496 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1),
1497 (IXGBE_EIMS_RTX_QUEUE << 16));
1498 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(2),
1499 ((IXGBE_EIMS_RTX_QUEUE << 16) |
1500 IXGBE_EIMS_RTX_QUEUE));
1501 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001502 IXGBE_WRITE_FLUSH(&adapter->hw);
1503}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001504
1505/**
1506 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001507 * @irq: interrupt number
1508 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001509 **/
1510static irqreturn_t ixgbe_intr(int irq, void *data)
1511{
1512 struct net_device *netdev = data;
1513 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1514 struct ixgbe_hw *hw = &adapter->hw;
1515 u32 eicr;
1516
Don Skidmore54037502009-02-21 15:42:56 -08001517 /*
1518 * Workaround for silicon errata. Mask the interrupts
1519 * before the read of EICR.
1520 */
1521 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1522
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001523 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1524 * therefore no explict interrupt disable is necessary */
1525 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001526 if (!eicr) {
1527 /* shared interrupt alert!
1528 * make sure interrupts are enabled because the read will
1529 * have disabled interrupts due to EIAM */
1530 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001531 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001532 }
Auke Kok9a799d72007-09-15 14:07:45 -07001533
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001534 if (eicr & IXGBE_EICR_LSC)
1535 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001536
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001537 if (hw->mac.type == ixgbe_mac_82599EB)
1538 ixgbe_check_sfp_event(adapter, eicr);
1539
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001540 ixgbe_check_fan_failure(adapter, eicr);
1541
Ben Hutchings288379f2009-01-19 16:43:59 -08001542 if (napi_schedule_prep(&adapter->q_vector[0].napi)) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001543 adapter->tx_ring[0].total_packets = 0;
1544 adapter->tx_ring[0].total_bytes = 0;
1545 adapter->rx_ring[0].total_packets = 0;
1546 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001547 /* would disable interrupts here but EIAM disabled it */
Ben Hutchings288379f2009-01-19 16:43:59 -08001548 __napi_schedule(&adapter->q_vector[0].napi);
Auke Kok9a799d72007-09-15 14:07:45 -07001549 }
1550
1551 return IRQ_HANDLED;
1552}
1553
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001554static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1555{
1556 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1557
1558 for (i = 0; i < q_vectors; i++) {
1559 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
1560 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1561 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1562 q_vector->rxr_count = 0;
1563 q_vector->txr_count = 0;
1564 }
1565}
1566
Auke Kok9a799d72007-09-15 14:07:45 -07001567/**
1568 * ixgbe_request_irq - initialize interrupts
1569 * @adapter: board private structure
1570 *
1571 * Attempts to configure interrupts using the best available
1572 * capabilities of the hardware and kernel.
1573 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001574static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001575{
1576 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001577 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001578
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001579 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1580 err = ixgbe_request_msix_irqs(adapter);
1581 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1582 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001583 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001584 } else {
1585 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001586 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001587 }
1588
Auke Kok9a799d72007-09-15 14:07:45 -07001589 if (err)
1590 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1591
Auke Kok9a799d72007-09-15 14:07:45 -07001592 return err;
1593}
1594
1595static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1596{
1597 struct net_device *netdev = adapter->netdev;
1598
1599 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001600 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001601
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001602 q_vectors = adapter->num_msix_vectors;
1603
1604 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001605 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001606
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001607 i--;
1608 for (; i >= 0; i--) {
1609 free_irq(adapter->msix_entries[i].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001610 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001611 }
1612
1613 ixgbe_reset_q_vectors(adapter);
1614 } else {
1615 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001616 }
1617}
1618
1619/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001620 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1621 * @adapter: board private structure
1622 **/
1623static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1624{
1625 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1626 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1627 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
1628 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(2), ~0);
1629 }
1630 IXGBE_WRITE_FLUSH(&adapter->hw);
1631 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1632 int i;
1633 for (i = 0; i < adapter->num_msix_vectors; i++)
1634 synchronize_irq(adapter->msix_entries[i].vector);
1635 } else {
1636 synchronize_irq(adapter->pdev->irq);
1637 }
1638}
1639
1640static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter)
1641{
1642 u32 mask = IXGBE_EIMS_RTX_QUEUE;
1643 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1644 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1645 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask << 16);
1646 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(2),
1647 (mask << 16 | mask));
1648 }
1649 /* skip the flush */
1650}
1651
1652/**
Auke Kok9a799d72007-09-15 14:07:45 -07001653 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1654 *
1655 **/
1656static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1657{
Auke Kok9a799d72007-09-15 14:07:45 -07001658 struct ixgbe_hw *hw = &adapter->hw;
1659
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001660 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001661 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001662
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001663 ixgbe_set_ivar(adapter, 0, 0, 0);
1664 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001665
1666 map_vector_to_rxq(adapter, 0, 0);
1667 map_vector_to_txq(adapter, 0, 0);
1668
1669 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001670}
1671
1672/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001673 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001674 * @adapter: board private structure
1675 *
1676 * Configure the Tx unit of the MAC after a reset.
1677 **/
1678static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1679{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001680 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001681 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001682 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001683
1684 /* Setup the HW Tx Head and Tail descriptor pointers */
1685 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001686 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1687 j = ring->reg_idx;
1688 tdba = ring->dma;
1689 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001690 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Yang Hongyang284901a2009-04-06 19:01:15 -07001691 (tdba & DMA_BIT_MASK(32)));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001692 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1693 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1694 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1695 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1696 adapter->tx_ring[i].head = IXGBE_TDH(j);
1697 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1698 /* Disable Tx Head Writeback RO bit, since this hoses
1699 * bookkeeping if things aren't delivered in order.
1700 */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001701 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001702 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001703 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001704 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001705 if (hw->mac.type == ixgbe_mac_82599EB) {
1706 /* We enable 8 traffic classes, DCB only */
1707 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1708 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1709 IXGBE_MTQC_8TC_8TQ));
1710 }
Auke Kok9a799d72007-09-15 14:07:45 -07001711}
1712
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001713#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07001714
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001715static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1716{
1717 struct ixgbe_ring *rx_ring;
1718 u32 srrctl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001719 int queue0 = 0;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001720 unsigned long mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001721
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001722 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1723 queue0 = index;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001724 } else {
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001725 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1726 queue0 = index & mask;
1727 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001728 }
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001729
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001730 rx_ring = &adapter->rx_ring[queue0];
1731
1732 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1733
1734 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1735 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1736
1737 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg32344a32009-02-24 16:37:31 -08001738 u16 bufsz = IXGBE_RXBUFFER_2048;
1739 /* grow the amount we can receive on large page machines */
1740 if (bufsz < (PAGE_SIZE / 2))
1741 bufsz = (PAGE_SIZE / 2);
1742 /* cap the bufsz at our largest descriptor size */
1743 bufsz = min((u16)IXGBE_MAX_RXBUFFER, bufsz);
1744
1745 srrctl |= bufsz >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001746 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1747 srrctl |= ((IXGBE_RX_HDR_SIZE <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001748 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1749 IXGBE_SRRCTL_BSIZEHDR_MASK);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001750 } else {
1751 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1752
1753 if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1754 srrctl |= IXGBE_RXBUFFER_2048 >>
1755 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1756 else
1757 srrctl |= rx_ring->rx_buf_len >>
1758 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1759 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001760
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001761 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1762}
1763
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001764/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001765 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001766 * @adapter: board private structure
1767 *
1768 * Configure the Rx unit of the MAC after a reset.
1769 **/
1770static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1771{
1772 u64 rdba;
1773 struct ixgbe_hw *hw = &adapter->hw;
1774 struct net_device *netdev = adapter->netdev;
1775 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001776 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001777 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001778 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1779 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1780 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001781 u32 fctrl, hlreg0;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001782 u32 reta = 0, mrqc = 0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001783 u32 rdrxctl;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001784 u32 rscctrl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001785 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07001786
1787 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001788 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07001789
1790 /* Set the RX buffer length according to the mode */
1791 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001792 rx_buf_len = IXGBE_RX_HDR_SIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001793 if (hw->mac.type == ixgbe_mac_82599EB) {
1794 /* PSRTYPE must be initialized in 82599 */
1795 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
1796 IXGBE_PSRTYPE_UDPHDR |
1797 IXGBE_PSRTYPE_IPV4HDR |
1798 IXGBE_PSRTYPE_IPV6HDR;
1799 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
1800 }
Auke Kok9a799d72007-09-15 14:07:45 -07001801 } else {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001802 if (!(adapter->flags & IXGBE_FLAG_RSC_ENABLED) &&
1803 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001804 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001805 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001806 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07001807 }
1808
1809 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1810 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001811 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001812 fctrl |= IXGBE_FCTRL_PMCF;
Auke Kok9a799d72007-09-15 14:07:45 -07001813 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1814
1815 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1816 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1817 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1818 else
1819 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1820 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1821
Auke Kok9a799d72007-09-15 14:07:45 -07001822 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1823 /* disable receives while setting up the descriptors */
1824 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1825 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1826
1827 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1828 * the Base and Length of the Rx Descriptor Ring */
1829 for (i = 0; i < adapter->num_rx_queues; i++) {
1830 rdba = adapter->rx_ring[i].dma;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001831 j = adapter->rx_ring[i].reg_idx;
Yang Hongyang284901a2009-04-06 19:01:15 -07001832 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32)));
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001833 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
1834 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
1835 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
1836 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
1837 adapter->rx_ring[i].head = IXGBE_RDH(j);
1838 adapter->rx_ring[i].tail = IXGBE_RDT(j);
1839 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001840
1841 ixgbe_configure_srrctl(adapter, j);
Auke Kok9a799d72007-09-15 14:07:45 -07001842 }
1843
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001844 if (hw->mac.type == ixgbe_mac_82598EB) {
1845 /*
1846 * For VMDq support of different descriptor types or
1847 * buffer sizes through the use of multiple SRRCTL
1848 * registers, RDRXCTL.MVMEN must be set to 1
1849 *
1850 * also, the manual doesn't mention it clearly but DCA hints
1851 * will only use queue 0's tags unless this bit is set. Side
1852 * effects of setting this bit are only that SRRCTL must be
1853 * fully programmed [0..15]
1854 */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001855 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1856 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
1857 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
Alexander Duyck2f90b862008-11-20 20:52:10 -08001858 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001859
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001860 /* Program MRQC for the distribution of queues */
1861 if (hw->mac.type == ixgbe_mac_82599EB) {
1862 int mask = adapter->flags & (
1863 IXGBE_FLAG_RSS_ENABLED
1864 | IXGBE_FLAG_DCB_ENABLED
1865 );
1866
1867 switch (mask) {
1868 case (IXGBE_FLAG_RSS_ENABLED):
1869 mrqc = IXGBE_MRQC_RSSEN;
1870 break;
1871 case (IXGBE_FLAG_DCB_ENABLED):
1872 mrqc = IXGBE_MRQC_RT8TCEN;
1873 break;
1874 default:
1875 break;
1876 }
1877 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001878 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07001879 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001880 for (i = 0, j = 0; i < 128; i++, j++) {
1881 if (j == adapter->ring_feature[RING_F_RSS].indices)
1882 j = 0;
1883 /* reta = 4-byte sliding window of
1884 * 0x00..(indices-1)(indices-1)00..etc. */
1885 reta = (reta << 8) | (j * 0x11);
1886 if ((i & 3) == 3)
1887 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07001888 }
1889
1890 /* Fill out hash function seeds */
1891 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001892 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07001893
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001894 if (hw->mac.type == ixgbe_mac_82598EB)
1895 mrqc |= IXGBE_MRQC_RSSEN;
Auke Kok9a799d72007-09-15 14:07:45 -07001896 /* Perform hash on these packet types */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001897 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
1898 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1899 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1900 | IXGBE_MRQC_RSS_FIELD_IPV6
1901 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1902 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07001903 }
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001904 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001905
1906 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1907
1908 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
1909 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
1910 /* Disable indicating checksum in descriptor, enables
1911 * RSS hash */
1912 rxcsum |= IXGBE_RXCSUM_PCSD;
1913 }
1914 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
1915 /* Enable IPv4 payload checksum for UDP fragments
1916 * if PCSD is not set */
1917 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1918 }
1919
1920 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001921
1922 if (hw->mac.type == ixgbe_mac_82599EB) {
1923 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1924 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001925 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001926 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
1927 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00001928
1929 if (adapter->flags & IXGBE_FLAG_RSC_ENABLED) {
1930 /* Enable 82599 HW-RSC */
1931 for (i = 0; i < adapter->num_rx_queues; i++) {
1932 j = adapter->rx_ring[i].reg_idx;
1933 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j));
1934 rscctrl |= IXGBE_RSCCTL_RSCEN;
1935 /*
1936 * if packet split is enabled we can only support up
1937 * to max frags + 1 descriptors.
1938 */
1939 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
1940#if (MAX_SKB_FRAGS < 3)
1941 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
1942#elif (MAX_SKB_FRAGS < 7)
1943 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
1944#elif (MAX_SKB_FRAGS < 15)
1945 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
1946#else
1947 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
1948#endif
1949 else
1950 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
1951 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl);
1952 }
1953 /* Disable RSC for ACK packets */
1954 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
1955 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
1956 }
Auke Kok9a799d72007-09-15 14:07:45 -07001957}
1958
Auke Kok9a799d72007-09-15 14:07:45 -07001959static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1960{
1961 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001962 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001963
1964 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001965 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07001966}
1967
1968static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1969{
1970 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001971 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001972
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001973 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1974 ixgbe_irq_disable(adapter);
1975
Auke Kok9a799d72007-09-15 14:07:45 -07001976 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001977
1978 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1979 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001980
1981 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001982 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07001983}
1984
Don Skidmore068c89b2009-01-19 16:54:36 -08001985static void ixgbe_vlan_rx_register(struct net_device *netdev,
1986 struct vlan_group *grp)
1987{
1988 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1989 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001990 int i, j;
Don Skidmore068c89b2009-01-19 16:54:36 -08001991
1992 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1993 ixgbe_irq_disable(adapter);
1994 adapter->vlgrp = grp;
1995
1996 /*
1997 * For a DCB driver, always enable VLAN tag stripping so we can
1998 * still receive traffic from a DCB-enabled host even if we're
1999 * not in DCB mode.
2000 */
2001 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002002 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
2003 ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
Don Skidmore068c89b2009-01-19 16:54:36 -08002004 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2005 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002006 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
2007 ctrl |= IXGBE_VLNCTRL_VFE;
2008 /* enable VLAN tag insert/strip */
2009 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
2010 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2011 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
2012 for (i = 0; i < adapter->num_rx_queues; i++) {
2013 j = adapter->rx_ring[i].reg_idx;
2014 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
2015 ctrl |= IXGBE_RXDCTL_VME;
2016 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
2017 }
Don Skidmore068c89b2009-01-19 16:54:36 -08002018 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002019 ixgbe_vlan_rx_add_vid(netdev, 0);
Don Skidmore068c89b2009-01-19 16:54:36 -08002020
2021 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2022 ixgbe_irq_enable(adapter);
2023}
2024
Auke Kok9a799d72007-09-15 14:07:45 -07002025static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
2026{
2027 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2028
2029 if (adapter->vlgrp) {
2030 u16 vid;
2031 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2032 if (!vlan_group_get_device(adapter->vlgrp, vid))
2033 continue;
2034 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
2035 }
2036 }
2037}
2038
Christopher Leech2c5645c2008-08-26 04:27:02 -07002039static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
2040{
2041 struct dev_mc_list *mc_ptr;
2042 u8 *addr = *mc_addr_ptr;
2043 *vmdq = 0;
2044
2045 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
2046 if (mc_ptr->next)
2047 *mc_addr_ptr = mc_ptr->next->dmi_addr;
2048 else
2049 *mc_addr_ptr = NULL;
2050
2051 return addr;
2052}
2053
Auke Kok9a799d72007-09-15 14:07:45 -07002054/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07002055 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07002056 * @netdev: network interface device structure
2057 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07002058 * The set_rx_method entry point is called whenever the unicast/multicast
2059 * address list or the network interface flags are updated. This routine is
2060 * responsible for configuring the hardware for proper unicast, multicast and
2061 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07002062 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07002063static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07002064{
2065 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2066 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07002067 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002068 u8 *addr_list = NULL;
2069 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002070
2071 /* Check for Promiscuous and All Multicast modes */
2072
2073 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07002074 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07002075
2076 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07002077 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002078 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07002079 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07002080 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002081 if (netdev->flags & IFF_ALLMULTI) {
2082 fctrl |= IXGBE_FCTRL_MPE;
2083 fctrl &= ~IXGBE_FCTRL_UPE;
2084 } else {
2085 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2086 }
Alexander Duyck3d016252008-08-26 18:30:04 -07002087 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002088 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002089 }
2090
2091 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07002092 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07002093
Christopher Leech2c5645c2008-08-26 04:27:02 -07002094 /* reprogram secondary unicast list */
2095 addr_count = netdev->uc_count;
2096 if (addr_count)
2097 addr_list = netdev->uc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002098 hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count,
2099 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002100
Christopher Leech2c5645c2008-08-26 04:27:02 -07002101 /* reprogram multicast list */
2102 addr_count = netdev->mc_count;
2103 if (addr_count)
2104 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002105 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2106 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002107}
2108
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002109static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2110{
2111 int q_idx;
2112 struct ixgbe_q_vector *q_vector;
2113 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2114
2115 /* legacy and MSI only use one vector */
2116 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2117 q_vectors = 1;
2118
2119 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002120 struct napi_struct *napi;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002121 q_vector = &adapter->q_vector[q_idx];
2122 if (!q_vector->rxr_count)
2123 continue;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002124 napi = &q_vector->napi;
2125 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) &&
2126 (q_vector->rxr_count > 1))
2127 napi->poll = &ixgbe_clean_rxonly_many;
2128
2129 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002130 }
2131}
2132
2133static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2134{
2135 int q_idx;
2136 struct ixgbe_q_vector *q_vector;
2137 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2138
2139 /* legacy and MSI only use one vector */
2140 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2141 q_vectors = 1;
2142
2143 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
2144 q_vector = &adapter->q_vector[q_idx];
2145 if (!q_vector->rxr_count)
2146 continue;
2147 napi_disable(&q_vector->napi);
2148 }
2149}
2150
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002151#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002152/*
2153 * ixgbe_configure_dcb - Configure DCB hardware
2154 * @adapter: ixgbe adapter struct
2155 *
2156 * This is called by the driver on open to configure the DCB hardware.
2157 * This is also called by the gennetlink interface when reconfiguring
2158 * the DCB state.
2159 */
2160static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2161{
2162 struct ixgbe_hw *hw = &adapter->hw;
2163 u32 txdctl, vlnctrl;
2164 int i, j;
2165
2166 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2167 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2168 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2169
2170 /* reconfigure the hardware */
2171 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2172
2173 for (i = 0; i < adapter->num_tx_queues; i++) {
2174 j = adapter->tx_ring[i].reg_idx;
2175 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2176 /* PThresh workaround for Tx hang with DFP enabled. */
2177 txdctl |= 32;
2178 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2179 }
2180 /* Enable VLAN tag insert/strip */
2181 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002182 if (hw->mac.type == ixgbe_mac_82598EB) {
2183 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2184 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2185 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2186 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2187 vlnctrl |= IXGBE_VLNCTRL_VFE;
2188 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2189 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2190 for (i = 0; i < adapter->num_rx_queues; i++) {
2191 j = adapter->rx_ring[i].reg_idx;
2192 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2193 vlnctrl |= IXGBE_RXDCTL_VME;
2194 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2195 }
2196 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08002197 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2198}
2199
2200#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002201static void ixgbe_configure(struct ixgbe_adapter *adapter)
2202{
2203 struct net_device *netdev = adapter->netdev;
2204 int i;
2205
Christopher Leech2c5645c2008-08-26 04:27:02 -07002206 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002207
2208 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002209#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002210 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2211 netif_set_gso_max_size(netdev, 32768);
2212 ixgbe_configure_dcb(adapter);
2213 } else {
2214 netif_set_gso_max_size(netdev, 65536);
2215 }
2216#else
2217 netif_set_gso_max_size(netdev, 65536);
2218#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002219
2220 ixgbe_configure_tx(adapter);
2221 ixgbe_configure_rx(adapter);
2222 for (i = 0; i < adapter->num_rx_queues; i++)
2223 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002224 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07002225}
2226
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002227static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2228{
2229 switch (hw->phy.type) {
2230 case ixgbe_phy_sfp_avago:
2231 case ixgbe_phy_sfp_ftl:
2232 case ixgbe_phy_sfp_intel:
2233 case ixgbe_phy_sfp_unknown:
2234 case ixgbe_phy_tw_tyco:
2235 case ixgbe_phy_tw_unknown:
2236 return true;
2237 default:
2238 return false;
2239 }
2240}
2241
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002242/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002243 * ixgbe_sfp_link_config - set up SFP+ link
2244 * @adapter: pointer to private adapter struct
2245 **/
2246static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2247{
2248 struct ixgbe_hw *hw = &adapter->hw;
2249
2250 if (hw->phy.multispeed_fiber) {
2251 /*
2252 * In multispeed fiber setups, the device may not have
2253 * had a physical connection when the driver loaded.
2254 * If that's the case, the initial link configuration
2255 * couldn't get the MAC into 10G or 1G mode, so we'll
2256 * never have a link status change interrupt fire.
2257 * We need to try and force an autonegotiation
2258 * session, then bring up link.
2259 */
2260 hw->mac.ops.setup_sfp(hw);
2261 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2262 schedule_work(&adapter->multispeed_fiber_task);
2263 } else {
2264 /*
2265 * Direct Attach Cu and non-multispeed fiber modules
2266 * still need to be configured properly prior to
2267 * attempting link.
2268 */
2269 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2270 schedule_work(&adapter->sfp_config_module_task);
2271 }
2272}
2273
2274/**
2275 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002276 * @hw: pointer to private hardware struct
2277 *
2278 * Returns 0 on success, negative on failure
2279 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002280static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002281{
2282 u32 autoneg;
2283 bool link_up = false;
2284 u32 ret = IXGBE_ERR_LINK_SETUP;
2285
2286 if (hw->mac.ops.check_link)
2287 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2288
2289 if (ret)
2290 goto link_cfg_out;
2291
2292 if (hw->mac.ops.get_link_capabilities)
2293 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
2294 &hw->mac.autoneg);
2295 if (ret)
2296 goto link_cfg_out;
2297
2298 if (hw->mac.ops.setup_link_speed)
2299 ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002300link_cfg_out:
2301 return ret;
2302}
2303
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002304#define IXGBE_MAX_RX_DESC_POLL 10
2305static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2306 int rxr)
2307{
2308 int j = adapter->rx_ring[rxr].reg_idx;
2309 int k;
2310
2311 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2312 if (IXGBE_READ_REG(&adapter->hw,
2313 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2314 break;
2315 else
2316 msleep(1);
2317 }
2318 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2319 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2320 "not set within the polling period\n", rxr);
2321 }
2322 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2323 (adapter->rx_ring[rxr].count - 1));
2324}
2325
Auke Kok9a799d72007-09-15 14:07:45 -07002326static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2327{
2328 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07002329 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002330 int i, j = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002331 int num_rx_rings = adapter->num_rx_queues;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002332 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002333 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002334 u32 txdctl, rxdctl, mhadd;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002335 u32 dmatxctl;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002336 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002337
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002338 ixgbe_get_hw_control(adapter);
2339
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002340 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2341 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002342 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2343 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002344 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002345 } else {
2346 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002347 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002348 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002349 /* XXX: to interrupt immediately for EICS writes, enable this */
2350 /* gpie |= IXGBE_GPIE_EIMEN; */
2351 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2352 }
2353
2354 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2355 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2356 * specifically only auto mask tx and rx interrupts */
2357 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002358 }
2359
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002360 /* Enable fan failure interrupt if media type is copper */
2361 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2362 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2363 gpie |= IXGBE_SDP1_GPIEN;
2364 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2365 }
2366
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002367 if (hw->mac.type == ixgbe_mac_82599EB) {
2368 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2369 gpie |= IXGBE_SDP1_GPIEN;
2370 gpie |= IXGBE_SDP2_GPIEN;
2371 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2372 }
2373
Auke Kok9a799d72007-09-15 14:07:45 -07002374 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002375 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2376 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2377 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2378
2379 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2380 }
2381
2382 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002383 j = adapter->tx_ring[i].reg_idx;
2384 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002385 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2386 txdctl |= (8 << 16);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002387 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2388 }
2389
2390 if (hw->mac.type == ixgbe_mac_82599EB) {
2391 /* DMATXCTL.EN must be set after all Tx queue config is done */
2392 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2393 dmatxctl |= IXGBE_DMATXCTL_TE;
2394 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2395 }
2396 for (i = 0; i < adapter->num_tx_queues; i++) {
2397 j = adapter->tx_ring[i].reg_idx;
2398 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Auke Kok9a799d72007-09-15 14:07:45 -07002399 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002400 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002401 }
2402
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002403 for (i = 0; i < num_rx_rings; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002404 j = adapter->rx_ring[i].reg_idx;
2405 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2406 /* enable PTHRESH=32 descriptors (half the internal cache)
2407 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2408 * this also removes a pesky rx_no_buffer_count increment */
2409 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002410 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002411 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002412 if (hw->mac.type == ixgbe_mac_82599EB)
2413 ixgbe_rx_desc_queue_enable(adapter, i);
Auke Kok9a799d72007-09-15 14:07:45 -07002414 }
2415 /* enable all receives */
2416 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002417 if (hw->mac.type == ixgbe_mac_82598EB)
2418 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2419 else
2420 rxdctl |= IXGBE_RXCTRL_RXEN;
2421 hw->mac.ops.enable_rx_dma(hw, rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002422
2423 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2424 ixgbe_configure_msix(adapter);
2425 else
2426 ixgbe_configure_msi_and_legacy(adapter);
2427
2428 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002429 ixgbe_napi_enable_all(adapter);
2430
2431 /* clear any pending interrupts, may auto mask */
2432 IXGBE_READ_REG(hw, IXGBE_EICR);
2433
Auke Kok9a799d72007-09-15 14:07:45 -07002434 ixgbe_irq_enable(adapter);
2435
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002436 /*
2437 * For hot-pluggable SFP+ devices, a new SFP+ module may have
2438 * arrived before interrupts were enabled. We need to kick off
2439 * the SFP+ module setup first, then try to bring up link.
2440 * If we're not hot-pluggable SFP+, we just need to configure link
2441 * and bring it up.
2442 */
2443 err = hw->phy.ops.identify(hw);
2444 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2445 DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err);
2446 ixgbe_down(adapter);
2447 return err;
2448 }
2449
2450 if (ixgbe_is_sfp(hw)) {
2451 ixgbe_sfp_link_config(adapter);
2452 } else {
2453 err = ixgbe_non_sfp_link_config(hw);
2454 if (err)
2455 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2456 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002457
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002458 /* enable transmits */
2459 netif_tx_start_all_queues(netdev);
2460
Auke Kok9a799d72007-09-15 14:07:45 -07002461 /* bring the link up in the watchdog, this could race with our first
2462 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002463 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2464 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002465 mod_timer(&adapter->watchdog_timer, jiffies);
2466 return 0;
2467}
2468
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002469void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2470{
2471 WARN_ON(in_interrupt());
2472 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2473 msleep(1);
2474 ixgbe_down(adapter);
2475 ixgbe_up(adapter);
2476 clear_bit(__IXGBE_RESETTING, &adapter->state);
2477}
2478
Auke Kok9a799d72007-09-15 14:07:45 -07002479int ixgbe_up(struct ixgbe_adapter *adapter)
2480{
2481 /* hardware has been reset, we need to reload some things */
2482 ixgbe_configure(adapter);
2483
Jesse Brandeburg4dd64df2009-03-13 22:13:49 +00002484 ixgbe_napi_add_all(adapter);
2485
Auke Kok9a799d72007-09-15 14:07:45 -07002486 return ixgbe_up_complete(adapter);
2487}
2488
2489void ixgbe_reset(struct ixgbe_adapter *adapter)
2490{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002491 struct ixgbe_hw *hw = &adapter->hw;
2492 if (hw->mac.ops.init_hw(hw))
2493 dev_err(&adapter->pdev->dev, "Hardware Error\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002494
2495 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002496 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002497
2498}
2499
Auke Kok9a799d72007-09-15 14:07:45 -07002500/**
2501 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2502 * @adapter: board private structure
2503 * @rx_ring: ring to free buffers from
2504 **/
2505static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002506 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002507{
2508 struct pci_dev *pdev = adapter->pdev;
2509 unsigned long size;
2510 unsigned int i;
2511
2512 /* Free all the Rx ring sk_buffs */
2513
2514 for (i = 0; i < rx_ring->count; i++) {
2515 struct ixgbe_rx_buffer *rx_buffer_info;
2516
2517 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2518 if (rx_buffer_info->dma) {
2519 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002520 rx_ring->rx_buf_len,
2521 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002522 rx_buffer_info->dma = 0;
2523 }
2524 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002525 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002526 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002527 do {
2528 struct sk_buff *this = skb;
2529 skb = skb->prev;
2530 dev_kfree_skb(this);
2531 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002532 }
2533 if (!rx_buffer_info->page)
2534 continue;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002535 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2536 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002537 rx_buffer_info->page_dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002538 put_page(rx_buffer_info->page);
2539 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002540 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002541 }
2542
2543 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2544 memset(rx_ring->rx_buffer_info, 0, size);
2545
2546 /* Zero out the descriptor ring */
2547 memset(rx_ring->desc, 0, rx_ring->size);
2548
2549 rx_ring->next_to_clean = 0;
2550 rx_ring->next_to_use = 0;
2551
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002552 if (rx_ring->head)
2553 writel(0, adapter->hw.hw_addr + rx_ring->head);
2554 if (rx_ring->tail)
2555 writel(0, adapter->hw.hw_addr + rx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002556}
2557
2558/**
2559 * ixgbe_clean_tx_ring - Free Tx Buffers
2560 * @adapter: board private structure
2561 * @tx_ring: ring to be cleaned
2562 **/
2563static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002564 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002565{
2566 struct ixgbe_tx_buffer *tx_buffer_info;
2567 unsigned long size;
2568 unsigned int i;
2569
2570 /* Free all the Tx ring sk_buffs */
2571
2572 for (i = 0; i < tx_ring->count; i++) {
2573 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2574 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2575 }
2576
2577 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2578 memset(tx_ring->tx_buffer_info, 0, size);
2579
2580 /* Zero out the descriptor ring */
2581 memset(tx_ring->desc, 0, tx_ring->size);
2582
2583 tx_ring->next_to_use = 0;
2584 tx_ring->next_to_clean = 0;
2585
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002586 if (tx_ring->head)
2587 writel(0, adapter->hw.hw_addr + tx_ring->head);
2588 if (tx_ring->tail)
2589 writel(0, adapter->hw.hw_addr + tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002590}
2591
2592/**
Auke Kok9a799d72007-09-15 14:07:45 -07002593 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2594 * @adapter: board private structure
2595 **/
2596static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2597{
2598 int i;
2599
2600 for (i = 0; i < adapter->num_rx_queues; i++)
2601 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2602}
2603
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002604/**
2605 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2606 * @adapter: board private structure
2607 **/
2608static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2609{
2610 int i;
2611
2612 for (i = 0; i < adapter->num_tx_queues; i++)
2613 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2614}
2615
Auke Kok9a799d72007-09-15 14:07:45 -07002616void ixgbe_down(struct ixgbe_adapter *adapter)
2617{
2618 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002619 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002620 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002621 u32 txdctl;
2622 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002623
2624 /* signal that we are down to the interrupt handler */
2625 set_bit(__IXGBE_DOWN, &adapter->state);
2626
2627 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002628 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2629 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002630
2631 netif_tx_disable(netdev);
2632
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002633 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002634 msleep(10);
2635
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002636 netif_tx_stop_all_queues(netdev);
2637
Auke Kok9a799d72007-09-15 14:07:45 -07002638 ixgbe_irq_disable(adapter);
2639
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002640 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002641
Auke Kok9a799d72007-09-15 14:07:45 -07002642 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002643 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002644
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002645 /* disable transmits in the hardware now that interrupts are off */
2646 for (i = 0; i < adapter->num_tx_queues; i++) {
2647 j = adapter->tx_ring[i].reg_idx;
2648 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2649 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2650 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2651 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00002652 /* Disable the Tx DMA engine on 82599 */
2653 if (hw->mac.type == ixgbe_mac_82599EB)
2654 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
2655 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
2656 ~IXGBE_DMATXCTL_TE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002657
Auke Kok9a799d72007-09-15 14:07:45 -07002658 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002659
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002660#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002661 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2662 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
2663 dca_remove_requester(&adapter->pdev->dev);
2664 }
2665
2666#endif
Paul Larson6f4a0e42008-06-24 17:00:56 -07002667 if (!pci_channel_offline(adapter->pdev))
2668 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002669 ixgbe_clean_all_tx_rings(adapter);
2670 ixgbe_clean_all_rx_rings(adapter);
2671
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002672#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002673 /* since we reset the hardware DCA settings were cleared */
2674 if (dca_add_requester(&adapter->pdev->dev) == 0) {
2675 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
2676 /* always use CB2 mode, difference is masked
2677 * in the CB driver */
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002678 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002679 ixgbe_setup_dca(adapter);
2680 }
2681#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002682}
2683
Auke Kok9a799d72007-09-15 14:07:45 -07002684/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002685 * ixgbe_poll - NAPI Rx polling callback
2686 * @napi: structure for representing this polling device
2687 * @budget: how many packets driver is allowed to clean
2688 *
2689 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002690 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002691static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002692{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002693 struct ixgbe_q_vector *q_vector =
2694 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002695 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002696 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002697
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002698#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002699 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2700 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2701 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2702 }
2703#endif
2704
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002705 tx_clean_complete = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002706 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002707
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002708 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002709 work_done = budget;
2710
David S. Miller53e52c72008-01-07 21:06:12 -08002711 /* If budget not fully consumed, exit the polling mode */
2712 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002713 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002714 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002715 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002716 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002717 ixgbe_irq_enable_queues(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002718 }
Auke Kok9a799d72007-09-15 14:07:45 -07002719 return work_done;
2720}
2721
2722/**
2723 * ixgbe_tx_timeout - Respond to a Tx Hang
2724 * @netdev: network interface device structure
2725 **/
2726static void ixgbe_tx_timeout(struct net_device *netdev)
2727{
2728 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2729
2730 /* Do the reset outside of interrupt context */
2731 schedule_work(&adapter->reset_task);
2732}
2733
2734static void ixgbe_reset_task(struct work_struct *work)
2735{
2736 struct ixgbe_adapter *adapter;
2737 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2738
Alexander Duyck2f90b862008-11-20 20:52:10 -08002739 /* If we're already down or resetting, just bail */
2740 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2741 test_bit(__IXGBE_RESETTING, &adapter->state))
2742 return;
2743
Auke Kok9a799d72007-09-15 14:07:45 -07002744 adapter->tx_timeout_count++;
2745
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002746 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002747}
2748
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002749#ifdef CONFIG_IXGBE_DCB
2750static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002751{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002752 bool ret = false;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002753
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002754 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2755 adapter->ring_feature[RING_F_DCB].mask = 0x7 << 3;
2756 adapter->num_rx_queues =
2757 adapter->ring_feature[RING_F_DCB].indices;
2758 adapter->num_tx_queues =
2759 adapter->ring_feature[RING_F_DCB].indices;
2760 ret = true;
2761 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002762 ret = false;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002763 }
2764
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002765 return ret;
2766}
2767#endif
2768
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002769/**
2770 * ixgbe_set_rss_queues: Allocate queues for RSS
2771 * @adapter: board private structure to initialize
2772 *
2773 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
2774 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
2775 *
2776 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002777static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
2778{
2779 bool ret = false;
2780
2781 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2782 adapter->ring_feature[RING_F_RSS].mask = 0xF;
2783 adapter->num_rx_queues =
2784 adapter->ring_feature[RING_F_RSS].indices;
2785 adapter->num_tx_queues =
2786 adapter->ring_feature[RING_F_RSS].indices;
2787 ret = true;
2788 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002789 ret = false;
2790 }
2791
2792 return ret;
2793}
2794
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002795/*
2796 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
2797 * @adapter: board private structure to initialize
2798 *
2799 * This is the top level queue allocation routine. The order here is very
2800 * important, starting with the "most" number of features turned on at once,
2801 * and ending with the smallest set of features. This way large combinations
2802 * can be allocated if they're turned on, and smaller combinations are the
2803 * fallthrough conditions.
2804 *
2805 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002806static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2807{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002808#ifdef CONFIG_IXGBE_DCB
2809 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07002810 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002811
2812#endif
2813 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07002814 goto done;
2815
2816 /* fallback to base case */
2817 adapter->num_rx_queues = 1;
2818 adapter->num_tx_queues = 1;
2819
2820done:
2821 /* Notify the stack of the (possibly) reduced Tx Queue count. */
2822 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002823}
2824
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002825static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002826 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002827{
2828 int err, vector_threshold;
2829
2830 /* We'll want at least 3 (vector_threshold):
2831 * 1) TxQ[0] Cleanup
2832 * 2) RxQ[0] Cleanup
2833 * 3) Other (Link Status Change, etc.)
2834 * 4) TCP Timer (optional)
2835 */
2836 vector_threshold = MIN_MSIX_COUNT;
2837
2838 /* The more we get, the more we will assign to Tx/Rx Cleanup
2839 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2840 * Right now, we simply care about how many we'll get; we'll
2841 * set them up later while requesting irq's.
2842 */
2843 while (vectors >= vector_threshold) {
2844 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002845 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002846 if (!err) /* Success in acquiring all requested vectors. */
2847 break;
2848 else if (err < 0)
2849 vectors = 0; /* Nasty failure, quit now */
2850 else /* err == number of vectors we should try again with */
2851 vectors = err;
2852 }
2853
2854 if (vectors < vector_threshold) {
2855 /* Can't allocate enough MSI-X interrupts? Oh well.
2856 * This just means we'll go with either a single MSI
2857 * vector or fall back to legacy interrupts.
2858 */
2859 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2860 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2861 kfree(adapter->msix_entries);
2862 adapter->msix_entries = NULL;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002863 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002864 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002865 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002866 } else {
2867 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08002868 /*
2869 * Adjust for only the vectors we'll use, which is minimum
2870 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
2871 * vectors we were allocated.
2872 */
2873 adapter->num_msix_vectors = min(vectors,
2874 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002875 }
2876}
2877
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002878/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002879 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002880 * @adapter: board private structure to initialize
2881 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002882 * Cache the descriptor ring offsets for RSS to the assigned rings.
2883 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002884 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002885static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002886{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002887 int i;
2888 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002889
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002890 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2891 for (i = 0; i < adapter->num_rx_queues; i++)
2892 adapter->rx_ring[i].reg_idx = i;
2893 for (i = 0; i < adapter->num_tx_queues; i++)
2894 adapter->tx_ring[i].reg_idx = i;
2895 ret = true;
2896 } else {
2897 ret = false;
2898 }
2899
2900 return ret;
2901}
2902
2903#ifdef CONFIG_IXGBE_DCB
2904/**
2905 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
2906 * @adapter: board private structure to initialize
2907 *
2908 * Cache the descriptor ring offsets for DCB to the assigned rings.
2909 *
2910 **/
2911static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
2912{
2913 int i;
2914 bool ret = false;
2915 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2916
2917 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2918 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002919 /* the number of queues is assumed to be symmetric */
2920 for (i = 0; i < dcb_i; i++) {
2921 adapter->rx_ring[i].reg_idx = i << 3;
2922 adapter->tx_ring[i].reg_idx = i << 2;
2923 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002924 ret = true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002925 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
PJ Waskiewiczf92ef202009-04-16 15:00:20 +00002926 if (dcb_i == 8) {
2927 /*
2928 * Tx TC0 starts at: descriptor queue 0
2929 * Tx TC1 starts at: descriptor queue 32
2930 * Tx TC2 starts at: descriptor queue 64
2931 * Tx TC3 starts at: descriptor queue 80
2932 * Tx TC4 starts at: descriptor queue 96
2933 * Tx TC5 starts at: descriptor queue 104
2934 * Tx TC6 starts at: descriptor queue 112
2935 * Tx TC7 starts at: descriptor queue 120
2936 *
2937 * Rx TC0-TC7 are offset by 16 queues each
2938 */
2939 for (i = 0; i < 3; i++) {
2940 adapter->tx_ring[i].reg_idx = i << 5;
2941 adapter->rx_ring[i].reg_idx = i << 4;
2942 }
2943 for ( ; i < 5; i++) {
2944 adapter->tx_ring[i].reg_idx =
2945 ((i + 2) << 4);
2946 adapter->rx_ring[i].reg_idx = i << 4;
2947 }
2948 for ( ; i < dcb_i; i++) {
2949 adapter->tx_ring[i].reg_idx =
2950 ((i + 8) << 3);
2951 adapter->rx_ring[i].reg_idx = i << 4;
2952 }
2953
2954 ret = true;
2955 } else if (dcb_i == 4) {
2956 /*
2957 * Tx TC0 starts at: descriptor queue 0
2958 * Tx TC1 starts at: descriptor queue 64
2959 * Tx TC2 starts at: descriptor queue 96
2960 * Tx TC3 starts at: descriptor queue 112
2961 *
2962 * Rx TC0-TC3 are offset by 32 queues each
2963 */
2964 adapter->tx_ring[0].reg_idx = 0;
2965 adapter->tx_ring[1].reg_idx = 64;
2966 adapter->tx_ring[2].reg_idx = 96;
2967 adapter->tx_ring[3].reg_idx = 112;
2968 for (i = 0 ; i < dcb_i; i++)
2969 adapter->rx_ring[i].reg_idx = i << 5;
2970
2971 ret = true;
2972 } else {
2973 ret = false;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002974 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002975 } else {
2976 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002977 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002978 } else {
2979 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002980 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002981
2982 return ret;
2983}
2984#endif
2985
2986/**
2987 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2988 * @adapter: board private structure to initialize
2989 *
2990 * Once we know the feature-set enabled for the device, we'll cache
2991 * the register offset the descriptor ring is assigned to.
2992 *
2993 * Note, the order the various feature calls is important. It must start with
2994 * the "most" features enabled at the same time, then trickle down to the
2995 * least amount of features turned on at once.
2996 **/
2997static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
2998{
2999 /* start with default case */
3000 adapter->rx_ring[0].reg_idx = 0;
3001 adapter->tx_ring[0].reg_idx = 0;
3002
3003#ifdef CONFIG_IXGBE_DCB
3004 if (ixgbe_cache_ring_dcb(adapter))
3005 return;
3006
3007#endif
3008 if (ixgbe_cache_ring_rss(adapter))
3009 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003010}
3011
Auke Kok9a799d72007-09-15 14:07:45 -07003012/**
3013 * ixgbe_alloc_queues - Allocate memory for all rings
3014 * @adapter: board private structure to initialize
3015 *
3016 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003017 * number of queues at compile-time. The polling_netdev array is
3018 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07003019 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003020static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003021{
3022 int i;
3023
3024 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003025 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07003026 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003027 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07003028
3029 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003030 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003031 if (!adapter->rx_ring)
3032 goto err_rx_ring_allocation;
3033
3034 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003035 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003036 adapter->tx_ring[i].queue_index = i;
3037 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003038
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003039 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003040 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003041 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07003042 }
3043
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003044 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003045
3046 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003047
3048err_rx_ring_allocation:
3049 kfree(adapter->tx_ring);
3050err_tx_ring_allocation:
3051 return -ENOMEM;
3052}
3053
3054/**
3055 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3056 * @adapter: board private structure to initialize
3057 *
3058 * Attempt to configure the interrupts using the best available
3059 * capabilities of the hardware and the kernel.
3060 **/
Al Virofeea6a52008-11-27 15:34:07 -08003061static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003062{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003063 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003064 int err = 0;
3065 int vector, v_budget;
3066
3067 /*
3068 * It's easy to be greedy for MSI-X vectors, but it really
3069 * doesn't do us much good if we have a lot more vectors
3070 * than CPU's. So let's be conservative and only ask for
3071 * (roughly) twice the number of vectors as there are CPU's.
3072 */
3073 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003074 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003075
3076 /*
3077 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003078 * hw.mac->max_msix_vectors vectors. With features
3079 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3080 * descriptor queues supported by our device. Thus, we cap it off in
3081 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003082 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003083 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003084
3085 /* A failure in MSI-X entry allocation isn't fatal, but it does
3086 * mean we disable MSI-X capabilities of the adapter. */
3087 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003088 sizeof(struct msix_entry), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003089 if (!adapter->msix_entries) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08003090 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003091 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
3092 ixgbe_set_num_queues(adapter);
3093 kfree(adapter->tx_ring);
3094 kfree(adapter->rx_ring);
3095 err = ixgbe_alloc_queues(adapter);
3096 if (err) {
3097 DPRINTK(PROBE, ERR, "Unable to allocate memory "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003098 "for queues\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003099 goto out;
3100 }
3101
3102 goto try_msi;
3103 }
3104
3105 for (vector = 0; vector < v_budget; vector++)
3106 adapter->msix_entries[vector].entry = vector;
3107
3108 ixgbe_acquire_msix_vectors(adapter, v_budget);
3109
3110 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3111 goto out;
3112
3113try_msi:
3114 err = pci_enable_msi(adapter->pdev);
3115 if (!err) {
3116 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
3117 } else {
3118 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003119 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003120 /* reset err */
3121 err = 0;
3122 }
3123
3124out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003125 return err;
3126}
3127
Alexander Duyck2f90b862008-11-20 20:52:10 -08003128void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003129{
3130 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3131 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3132 pci_disable_msix(adapter->pdev);
3133 kfree(adapter->msix_entries);
3134 adapter->msix_entries = NULL;
3135 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
3136 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
3137 pci_disable_msi(adapter->pdev);
3138 }
3139 return;
3140}
3141
3142/**
3143 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3144 * @adapter: board private structure to initialize
3145 *
3146 * We determine which interrupt scheme to use based on...
3147 * - Kernel support (MSI, MSI-X)
3148 * - which can be user-defined (via MODULE_PARAM)
3149 * - Hardware queue count (num_*_queues)
3150 * - defined by miscellaneous hardware support/features (RSS, etc.)
3151 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003152int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003153{
3154 int err;
3155
3156 /* Number of supported queues */
3157 ixgbe_set_num_queues(adapter);
3158
3159 err = ixgbe_alloc_queues(adapter);
3160 if (err) {
3161 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3162 goto err_alloc_queues;
3163 }
3164
3165 err = ixgbe_set_interrupt_capability(adapter);
3166 if (err) {
3167 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3168 goto err_set_interrupt;
3169 }
3170
3171 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003172 "Tx Queue count = %u\n",
3173 (adapter->num_rx_queues > 1) ? "Enabled" :
3174 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003175
3176 set_bit(__IXGBE_DOWN, &adapter->state);
3177
3178 return 0;
3179
3180err_set_interrupt:
3181 kfree(adapter->tx_ring);
3182 kfree(adapter->rx_ring);
3183err_alloc_queues:
3184 return err;
Auke Kok9a799d72007-09-15 14:07:45 -07003185}
3186
3187/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08003188 * ixgbe_sfp_timer - worker thread to find a missing module
3189 * @data: pointer to our adapter struct
3190 **/
3191static void ixgbe_sfp_timer(unsigned long data)
3192{
3193 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3194
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003195 /*
3196 * Do the sfp_timer outside of interrupt context due to the
Donald Skidmorec4900be2008-11-20 21:11:42 -08003197 * delays that sfp+ detection requires
3198 */
3199 schedule_work(&adapter->sfp_task);
3200}
3201
3202/**
3203 * ixgbe_sfp_task - worker thread to find a missing module
3204 * @work: pointer to work_struct containing our data
3205 **/
3206static void ixgbe_sfp_task(struct work_struct *work)
3207{
3208 struct ixgbe_adapter *adapter = container_of(work,
3209 struct ixgbe_adapter,
3210 sfp_task);
3211 struct ixgbe_hw *hw = &adapter->hw;
3212
3213 if ((hw->phy.type == ixgbe_phy_nl) &&
3214 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3215 s32 ret = hw->phy.ops.identify_sfp(hw);
3216 if (ret)
3217 goto reschedule;
3218 ret = hw->phy.ops.reset(hw);
3219 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
3220 DPRINTK(PROBE, ERR, "failed to initialize because an "
3221 "unsupported SFP+ module type was detected.\n"
3222 "Reload the driver after installing a "
3223 "supported module.\n");
3224 unregister_netdev(adapter->netdev);
3225 } else {
3226 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3227 hw->phy.sfp_type);
3228 }
3229 /* don't need this routine any more */
3230 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3231 }
3232 return;
3233reschedule:
3234 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3235 mod_timer(&adapter->sfp_timer,
3236 round_jiffies(jiffies + (2 * HZ)));
3237}
3238
3239/**
Auke Kok9a799d72007-09-15 14:07:45 -07003240 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3241 * @adapter: board private structure to initialize
3242 *
3243 * ixgbe_sw_init initializes the Adapter private data structure.
3244 * Fields are initialized based on PCI device information and
3245 * OS network device settings (MTU size).
3246 **/
3247static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3248{
3249 struct ixgbe_hw *hw = &adapter->hw;
3250 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003251 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003252#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003253 int j;
3254 struct tc_configuration *tc;
3255#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003256
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003257 /* PCI config space info */
3258
3259 hw->vendor_id = pdev->vendor;
3260 hw->device_id = pdev->device;
3261 hw->revision_id = pdev->revision;
3262 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3263 hw->subsystem_device_id = pdev->subsystem_device;
3264
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003265 /* Set capability flags */
3266 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3267 adapter->ring_feature[RING_F_RSS].indices = rss;
3268 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003269 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003270 if (hw->mac.type == ixgbe_mac_82598EB)
3271 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckf8212f92009-04-27 22:42:37 +00003272 else if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003273 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Alexander Duyckf8212f92009-04-27 22:42:37 +00003274 adapter->flags |= IXGBE_FLAG_RSC_CAPABLE;
3275 adapter->flags |= IXGBE_FLAG_RSC_ENABLED;
3276 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003277
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003278#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003279 /* Configure DCB traffic classes */
3280 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3281 tc = &adapter->dcb_cfg.tc_config[j];
3282 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3283 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3284 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3285 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3286 tc->dcb_pfc = pfc_disabled;
3287 }
3288 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3289 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3290 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
3291 adapter->dcb_cfg.round_robin_enable = false;
3292 adapter->dcb_set_bitmap = 0x00;
3293 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3294 adapter->ring_feature[RING_F_DCB].indices);
3295
3296#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003297
3298 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00003299 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00003300 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07003301 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3302 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3303 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3304 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00003305 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07003306
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07003307 /* enable itr by default in dynamic mode */
3308 adapter->itr_setting = 1;
3309 adapter->eitr_param = 20000;
3310
3311 /* set defaults for eitr in MegaBytes */
3312 adapter->eitr_low = 10;
3313 adapter->eitr_high = 20;
3314
3315 /* set default ring sizes */
3316 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
3317 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
3318
Auke Kok9a799d72007-09-15 14:07:45 -07003319 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003320 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003321 dev_err(&pdev->dev, "EEPROM initialization failed\n");
3322 return -EIO;
3323 }
3324
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003325 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07003326 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
3327
Auke Kok9a799d72007-09-15 14:07:45 -07003328 set_bit(__IXGBE_DOWN, &adapter->state);
3329
3330 return 0;
3331}
3332
3333/**
3334 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3335 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003336 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003337 *
3338 * Return 0 on success, negative on failure
3339 **/
3340int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003341 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003342{
3343 struct pci_dev *pdev = adapter->pdev;
3344 int size;
3345
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003346 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3347 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003348 if (!tx_ring->tx_buffer_info)
3349 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003350 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003351
3352 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08003353 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003354 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003355
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003356 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
3357 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003358 if (!tx_ring->desc)
3359 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07003360
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003361 tx_ring->next_to_use = 0;
3362 tx_ring->next_to_clean = 0;
3363 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07003364 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003365
3366err:
3367 vfree(tx_ring->tx_buffer_info);
3368 tx_ring->tx_buffer_info = NULL;
3369 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
3370 "descriptor ring\n");
3371 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003372}
3373
3374/**
Alexander Duyck69888672008-09-11 20:05:39 -07003375 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
3376 * @adapter: board private structure
3377 *
3378 * If this function returns with an error, then it's possible one or
3379 * more of the rings is populated (while the rest are not). It is the
3380 * callers duty to clean those orphaned rings.
3381 *
3382 * Return 0 on success, negative on failure
3383 **/
3384static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
3385{
3386 int i, err = 0;
3387
3388 for (i = 0; i < adapter->num_tx_queues; i++) {
3389 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
3390 if (!err)
3391 continue;
3392 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
3393 break;
3394 }
3395
3396 return err;
3397}
3398
3399/**
Auke Kok9a799d72007-09-15 14:07:45 -07003400 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
3401 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003402 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003403 *
3404 * Returns 0 on success, negative on failure
3405 **/
3406int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003407 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003408{
3409 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003410 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07003411
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003412 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
3413 rx_ring->rx_buffer_info = vmalloc(size);
3414 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07003415 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003416 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003417 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003418 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003419 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003420
Auke Kok9a799d72007-09-15 14:07:45 -07003421 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003422 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
3423 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003424
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003425 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07003426
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003427 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07003428 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003429 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003430 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003431 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003432 }
3433
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003434 rx_ring->next_to_clean = 0;
3435 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003436
3437 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003438
3439alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003440 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003441}
3442
3443/**
Alexander Duyck69888672008-09-11 20:05:39 -07003444 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
3445 * @adapter: board private structure
3446 *
3447 * If this function returns with an error, then it's possible one or
3448 * more of the rings is populated (while the rest are not). It is the
3449 * callers duty to clean those orphaned rings.
3450 *
3451 * Return 0 on success, negative on failure
3452 **/
3453
3454static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
3455{
3456 int i, err = 0;
3457
3458 for (i = 0; i < adapter->num_rx_queues; i++) {
3459 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
3460 if (!err)
3461 continue;
3462 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
3463 break;
3464 }
3465
3466 return err;
3467}
3468
3469/**
Auke Kok9a799d72007-09-15 14:07:45 -07003470 * ixgbe_free_tx_resources - Free Tx Resources per Queue
3471 * @adapter: board private structure
3472 * @tx_ring: Tx descriptor ring for a specific queue
3473 *
3474 * Free all transmit software resources
3475 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003476void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
3477 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003478{
3479 struct pci_dev *pdev = adapter->pdev;
3480
3481 ixgbe_clean_tx_ring(adapter, tx_ring);
3482
3483 vfree(tx_ring->tx_buffer_info);
3484 tx_ring->tx_buffer_info = NULL;
3485
3486 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
3487
3488 tx_ring->desc = NULL;
3489}
3490
3491/**
3492 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
3493 * @adapter: board private structure
3494 *
3495 * Free all transmit software resources
3496 **/
3497static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
3498{
3499 int i;
3500
3501 for (i = 0; i < adapter->num_tx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00003502 if (adapter->tx_ring[i].desc)
3503 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003504}
3505
3506/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003507 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07003508 * @adapter: board private structure
3509 * @rx_ring: ring to clean the resources from
3510 *
3511 * Free all receive software resources
3512 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003513void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
3514 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003515{
3516 struct pci_dev *pdev = adapter->pdev;
3517
3518 ixgbe_clean_rx_ring(adapter, rx_ring);
3519
3520 vfree(rx_ring->rx_buffer_info);
3521 rx_ring->rx_buffer_info = NULL;
3522
3523 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
3524
3525 rx_ring->desc = NULL;
3526}
3527
3528/**
3529 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
3530 * @adapter: board private structure
3531 *
3532 * Free all receive software resources
3533 **/
3534static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
3535{
3536 int i;
3537
3538 for (i = 0; i < adapter->num_rx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00003539 if (adapter->rx_ring[i].desc)
3540 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003541}
3542
3543/**
Auke Kok9a799d72007-09-15 14:07:45 -07003544 * ixgbe_change_mtu - Change the Maximum Transfer Unit
3545 * @netdev: network interface device structure
3546 * @new_mtu: new value for maximum frame size
3547 *
3548 * Returns 0 on success, negative on failure
3549 **/
3550static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
3551{
3552 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3553 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3554
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07003555 /* MTU < 68 is an error and causes problems on some kernels */
3556 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07003557 return -EINVAL;
3558
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003559 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003560 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003561 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07003562 netdev->mtu = new_mtu;
3563
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003564 if (netif_running(netdev))
3565 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003566
3567 return 0;
3568}
3569
3570/**
3571 * ixgbe_open - Called when a network interface is made active
3572 * @netdev: network interface device structure
3573 *
3574 * Returns 0 on success, negative value on failure
3575 *
3576 * The open entry point is called when a network interface is made
3577 * active by the system (IFF_UP). At this point all resources needed
3578 * for transmit and receive operations are allocated, the interrupt
3579 * handler is registered with the OS, the watchdog timer is started,
3580 * and the stack is notified that the interface is ready.
3581 **/
3582static int ixgbe_open(struct net_device *netdev)
3583{
3584 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3585 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003586
Auke Kok4bebfaa2008-02-11 09:26:01 -08003587 /* disallow open during test */
3588 if (test_bit(__IXGBE_TESTING, &adapter->state))
3589 return -EBUSY;
3590
Jesse Brandeburg54386462009-04-17 20:44:27 +00003591 netif_carrier_off(netdev);
3592
Auke Kok9a799d72007-09-15 14:07:45 -07003593 /* allocate transmit descriptors */
3594 err = ixgbe_setup_all_tx_resources(adapter);
3595 if (err)
3596 goto err_setup_tx;
3597
Auke Kok9a799d72007-09-15 14:07:45 -07003598 /* allocate receive descriptors */
3599 err = ixgbe_setup_all_rx_resources(adapter);
3600 if (err)
3601 goto err_setup_rx;
3602
3603 ixgbe_configure(adapter);
3604
Jesse Brandeburg4dd64df2009-03-13 22:13:49 +00003605 ixgbe_napi_add_all(adapter);
3606
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003607 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003608 if (err)
3609 goto err_req_irq;
3610
Auke Kok9a799d72007-09-15 14:07:45 -07003611 err = ixgbe_up_complete(adapter);
3612 if (err)
3613 goto err_up;
3614
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003615 netif_tx_start_all_queues(netdev);
3616
Auke Kok9a799d72007-09-15 14:07:45 -07003617 return 0;
3618
3619err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003620 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003621 ixgbe_free_irq(adapter);
3622err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07003623err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00003624 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003625err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00003626 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003627 ixgbe_reset(adapter);
3628
3629 return err;
3630}
3631
3632/**
3633 * ixgbe_close - Disables a network interface
3634 * @netdev: network interface device structure
3635 *
3636 * Returns 0, this is not allowed to fail
3637 *
3638 * The close entry point is called when an interface is de-activated
3639 * by the OS. The hardware is still under the drivers control, but
3640 * needs to be disabled. A global MAC reset is issued to stop the
3641 * hardware, and all transmit and receive resources are freed.
3642 **/
3643static int ixgbe_close(struct net_device *netdev)
3644{
3645 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003646
3647 ixgbe_down(adapter);
3648 ixgbe_free_irq(adapter);
3649
3650 ixgbe_free_all_tx_resources(adapter);
3651 ixgbe_free_all_rx_resources(adapter);
3652
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003653 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003654
3655 return 0;
3656}
3657
3658/**
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003659 * ixgbe_napi_add_all - prep napi structs for use
3660 * @adapter: private struct
Jesse Brandeburg4dd64df2009-03-13 22:13:49 +00003661 *
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003662 * helper function to napi_add each possible q_vector->napi
3663 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08003664void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003665{
3666 int q_idx, q_vectors;
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003667 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003668 int (*poll)(struct napi_struct *, int);
3669
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003670 /* check if we already have our netdev->napi_list populated */
3671 if (&netdev->napi_list != netdev->napi_list.next)
3672 return;
3673
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003674 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3675 poll = &ixgbe_clean_rxonly;
3676 /* Only enable as many vectors as we have rx queues. */
3677 q_vectors = adapter->num_rx_queues;
3678 } else {
3679 poll = &ixgbe_poll;
3680 /* only one q_vector for legacy modes */
3681 q_vectors = 1;
3682 }
3683
3684 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3685 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3686 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
3687 }
3688}
3689
Alexander Duyck2f90b862008-11-20 20:52:10 -08003690void ixgbe_napi_del_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003691{
3692 int q_idx;
3693 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3694
3695 /* legacy and MSI only use one vector */
3696 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3697 q_vectors = 1;
3698
3699 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3700 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3701 if (!q_vector->rxr_count)
3702 continue;
3703 netif_napi_del(&q_vector->napi);
3704 }
3705}
3706
3707#ifdef CONFIG_PM
3708static int ixgbe_resume(struct pci_dev *pdev)
3709{
3710 struct net_device *netdev = pci_get_drvdata(pdev);
3711 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3712 u32 err;
3713
3714 pci_set_power_state(pdev, PCI_D0);
3715 pci_restore_state(pdev);
3716 err = pci_enable_device(pdev);
3717 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07003718 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003719 "suspend\n");
3720 return err;
3721 }
3722 pci_set_master(pdev);
3723
3724 pci_enable_wake(pdev, PCI_D3hot, 0);
3725 pci_enable_wake(pdev, PCI_D3cold, 0);
3726
3727 err = ixgbe_init_interrupt_scheme(adapter);
3728 if (err) {
3729 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
3730 "device\n");
3731 return err;
3732 }
3733
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003734 ixgbe_reset(adapter);
3735
3736 if (netif_running(netdev)) {
3737 err = ixgbe_open(adapter->netdev);
3738 if (err)
3739 return err;
3740 }
3741
3742 netif_device_attach(netdev);
3743
3744 return 0;
3745}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003746#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00003747
3748static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003749{
3750 struct net_device *netdev = pci_get_drvdata(pdev);
3751 struct ixgbe_adapter *adapter = netdev_priv(netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003752 struct ixgbe_hw *hw = &adapter->hw;
3753 u32 ctrl, fctrl;
3754 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003755#ifdef CONFIG_PM
3756 int retval = 0;
3757#endif
3758
3759 netif_device_detach(netdev);
3760
3761 if (netif_running(netdev)) {
3762 ixgbe_down(adapter);
3763 ixgbe_free_irq(adapter);
3764 ixgbe_free_all_tx_resources(adapter);
3765 ixgbe_free_all_rx_resources(adapter);
3766 }
3767 ixgbe_reset_interrupt_capability(adapter);
3768 ixgbe_napi_del_all(adapter);
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003769 INIT_LIST_HEAD(&netdev->napi_list);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003770 kfree(adapter->tx_ring);
3771 kfree(adapter->rx_ring);
3772
3773#ifdef CONFIG_PM
3774 retval = pci_save_state(pdev);
3775 if (retval)
3776 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003777
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003778#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003779 if (wufc) {
3780 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003781
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003782 /* turn on all-multi mode if wake on multicast is enabled */
3783 if (wufc & IXGBE_WUFC_MC) {
3784 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3785 fctrl |= IXGBE_FCTRL_MPE;
3786 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3787 }
3788
3789 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
3790 ctrl |= IXGBE_CTRL_GIO_DIS;
3791 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
3792
3793 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
3794 } else {
3795 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
3796 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
3797 }
3798
3799 if (wufc && hw->mac.type == ixgbe_mac_82599EB) {
3800 pci_enable_wake(pdev, PCI_D3hot, 1);
3801 pci_enable_wake(pdev, PCI_D3cold, 1);
3802 } else {
3803 pci_enable_wake(pdev, PCI_D3hot, 0);
3804 pci_enable_wake(pdev, PCI_D3cold, 0);
3805 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003806
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00003807 *enable_wake = !!wufc;
3808
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003809 ixgbe_release_hw_control(adapter);
3810
3811 pci_disable_device(pdev);
3812
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003813 return 0;
3814}
3815
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00003816#ifdef CONFIG_PM
3817static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
3818{
3819 int retval;
3820 bool wake;
3821
3822 retval = __ixgbe_shutdown(pdev, &wake);
3823 if (retval)
3824 return retval;
3825
3826 if (wake) {
3827 pci_prepare_to_sleep(pdev);
3828 } else {
3829 pci_wake_from_d3(pdev, false);
3830 pci_set_power_state(pdev, PCI_D3hot);
3831 }
3832
3833 return 0;
3834}
3835#endif /* CONFIG_PM */
3836
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003837static void ixgbe_shutdown(struct pci_dev *pdev)
3838{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00003839 bool wake;
3840
3841 __ixgbe_shutdown(pdev, &wake);
3842
3843 if (system_state == SYSTEM_POWER_OFF) {
3844 pci_wake_from_d3(pdev, wake);
3845 pci_set_power_state(pdev, PCI_D3hot);
3846 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003847}
3848
3849/**
Auke Kok9a799d72007-09-15 14:07:45 -07003850 * ixgbe_update_stats - Update the board statistics counters.
3851 * @adapter: board private structure
3852 **/
3853void ixgbe_update_stats(struct ixgbe_adapter *adapter)
3854{
3855 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003856 u64 total_mpc = 0;
3857 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003858
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00003859 if (hw->mac.type == ixgbe_mac_82599EB) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00003860 u64 rsc_count = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00003861 for (i = 0; i < 16; i++)
3862 adapter->hw_rx_no_dma_resources +=
3863 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Alexander Duyckf8212f92009-04-27 22:42:37 +00003864 for (i = 0; i < adapter->num_rx_queues; i++)
3865 rsc_count += adapter->rx_ring[i].rsc_count;
3866 adapter->rsc_count = rsc_count;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00003867 }
3868
Auke Kok9a799d72007-09-15 14:07:45 -07003869 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003870 for (i = 0; i < 8; i++) {
3871 /* for packet buffers not used, the register should read 0 */
3872 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
3873 missed_rx += mpc;
3874 adapter->stats.mpc[i] += mpc;
3875 total_mpc += adapter->stats.mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003876 if (hw->mac.type == ixgbe_mac_82598EB)
3877 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08003878 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
3879 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
3880 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
3881 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003882 if (hw->mac.type == ixgbe_mac_82599EB) {
3883 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3884 IXGBE_PXONRXCNT(i));
3885 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3886 IXGBE_PXOFFRXCNT(i));
3887 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003888 } else {
3889 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3890 IXGBE_PXONRXC(i));
3891 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3892 IXGBE_PXOFFRXC(i));
3893 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003894 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
3895 IXGBE_PXONTXC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08003896 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003897 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003898 }
3899 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
3900 /* work around hardware counting issue */
3901 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07003902
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003903 /* 82598 hardware only has a 32 bit counter in the high register */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003904 if (hw->mac.type == ixgbe_mac_82599EB) {
3905 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
3906 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
3907 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
3908 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
3909 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
3910 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
3911 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
3912 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
3913 } else {
3914 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
3915 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
3916 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
3917 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
3918 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
3919 }
Auke Kok9a799d72007-09-15 14:07:45 -07003920 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
3921 adapter->stats.bprc += bprc;
3922 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003923 if (hw->mac.type == ixgbe_mac_82598EB)
3924 adapter->stats.mprc -= bprc;
Auke Kok9a799d72007-09-15 14:07:45 -07003925 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
3926 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
3927 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
3928 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
3929 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
3930 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
3931 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003932 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003933 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
3934 adapter->stats.lxontxc += lxon;
3935 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
3936 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07003937 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3938 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003939 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
3940 /*
3941 * 82598 errata - tx of flow control packets is included in tx counters
3942 */
3943 xon_off_tot = lxon + lxoff;
3944 adapter->stats.gptc -= xon_off_tot;
3945 adapter->stats.mptc -= xon_off_tot;
3946 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07003947 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3948 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
3949 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07003950 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
3951 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003952 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003953 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3954 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3955 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3956 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3957 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003958 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3959
3960 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07003961 adapter->net_stats.multicast = adapter->stats.mprc;
3962
3963 /* Rx Errors */
3964 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003965 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07003966 adapter->net_stats.rx_dropped = 0;
3967 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3968 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003969 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07003970}
3971
3972/**
3973 * ixgbe_watchdog - Timer Call-back
3974 * @data: pointer to adapter cast into an unsigned long
3975 **/
3976static void ixgbe_watchdog(unsigned long data)
3977{
3978 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003979 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003980
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003981 /* Do the watchdog outside of interrupt context due to the lovely
3982 * delays that some of the newer hardware requires */
3983 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003984 u64 eics = 0;
3985 int i;
3986
3987 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++)
3988 eics |= (1 << i);
3989
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003990 /* Cause software interrupt to ensure rx rings are cleaned */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003991 switch (hw->mac.type) {
3992 case ixgbe_mac_82598EB:
3993 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3994 IXGBE_WRITE_REG(hw, IXGBE_EICS, (u32)eics);
3995 } else {
3996 /*
3997 * for legacy and MSI interrupts don't set any
3998 * bits that are enabled for EIAM, because this
3999 * operation would set *both* EIMS and EICS for
4000 * any bit in EIAM
4001 */
4002 IXGBE_WRITE_REG(hw, IXGBE_EICS,
4003 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
4004 }
4005 break;
4006 case ixgbe_mac_82599EB:
4007 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4008 /*
4009 * EICS(0..15) first 0-15 q vectors
4010 * EICS[1] (16..31) q vectors 16-31
4011 * EICS[2] (0..31) q vectors 32-63
4012 */
4013 IXGBE_WRITE_REG(hw, IXGBE_EICS,
4014 (u32)(eics & 0xFFFF));
4015 IXGBE_WRITE_REG(hw, IXGBE_EICS_EX(1),
4016 (u32)(eics & 0xFFFF0000));
4017 IXGBE_WRITE_REG(hw, IXGBE_EICS_EX(2),
4018 (u32)(eics >> 32));
4019 } else {
4020 /*
4021 * for legacy and MSI interrupts don't set any
4022 * bits that are enabled for EIAM, because this
4023 * operation would set *both* EIMS and EICS for
4024 * any bit in EIAM
4025 */
4026 IXGBE_WRITE_REG(hw, IXGBE_EICS,
4027 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
4028 }
4029 break;
4030 default:
4031 break;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004032 }
4033 /* Reset the timer */
4034 mod_timer(&adapter->watchdog_timer,
4035 round_jiffies(jiffies + 2 * HZ));
4036 }
4037
4038 schedule_work(&adapter->watchdog_task);
4039}
4040
4041/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004042 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
4043 * @work: pointer to work_struct containing our data
4044 **/
4045static void ixgbe_multispeed_fiber_task(struct work_struct *work)
4046{
4047 struct ixgbe_adapter *adapter = container_of(work,
4048 struct ixgbe_adapter,
4049 multispeed_fiber_task);
4050 struct ixgbe_hw *hw = &adapter->hw;
4051 u32 autoneg;
4052
4053 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
4054 if (hw->mac.ops.get_link_capabilities)
4055 hw->mac.ops.get_link_capabilities(hw, &autoneg,
4056 &hw->mac.autoneg);
4057 if (hw->mac.ops.setup_link_speed)
4058 hw->mac.ops.setup_link_speed(hw, autoneg, true, true);
4059 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4060 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
4061}
4062
4063/**
4064 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
4065 * @work: pointer to work_struct containing our data
4066 **/
4067static void ixgbe_sfp_config_module_task(struct work_struct *work)
4068{
4069 struct ixgbe_adapter *adapter = container_of(work,
4070 struct ixgbe_adapter,
4071 sfp_config_module_task);
4072 struct ixgbe_hw *hw = &adapter->hw;
4073 u32 err;
4074
4075 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
4076 err = hw->phy.ops.identify_sfp(hw);
4077 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4078 DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err);
4079 ixgbe_down(adapter);
4080 return;
4081 }
4082 hw->mac.ops.setup_sfp(hw);
4083
Tony Breeds8d1c3c02009-04-09 22:29:10 +00004084 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004085 /* This will also work for DA Twinax connections */
4086 schedule_work(&adapter->multispeed_fiber_task);
4087 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
4088}
4089
4090/**
Alexander Duyck69888672008-09-11 20:05:39 -07004091 * ixgbe_watchdog_task - worker thread to bring link up
4092 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004093 **/
4094static void ixgbe_watchdog_task(struct work_struct *work)
4095{
4096 struct ixgbe_adapter *adapter = container_of(work,
4097 struct ixgbe_adapter,
4098 watchdog_task);
4099 struct net_device *netdev = adapter->netdev;
4100 struct ixgbe_hw *hw = &adapter->hw;
4101 u32 link_speed = adapter->link_speed;
4102 bool link_up = adapter->link_up;
4103
4104 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
4105
4106 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4107 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
4108 if (link_up ||
4109 time_after(jiffies, (adapter->link_check_timeout +
4110 IXGBE_TRY_LINK_TIMEOUT))) {
4111 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
4112 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4113 }
4114 adapter->link_up = link_up;
4115 adapter->link_speed = link_speed;
4116 }
Auke Kok9a799d72007-09-15 14:07:45 -07004117
4118 if (link_up) {
4119 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004120 bool flow_rx, flow_tx;
4121
4122 if (hw->mac.type == ixgbe_mac_82599EB) {
4123 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4124 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
4125 flow_rx = (mflcn & IXGBE_MFLCN_RFCE);
4126 flow_tx = (fccfg & IXGBE_FCCFG_TFCE_802_3X);
4127 } else {
4128 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4129 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
4130 flow_rx = (frctl & IXGBE_FCTRL_RFCE);
4131 flow_tx = (rmcs & IXGBE_RMCS_TFCE_802_3X);
4132 }
4133
Jeff Kirshera46e5342008-11-27 00:22:21 -08004134 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
4135 "Flow Control: %s\n",
4136 netdev->name,
4137 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
4138 "10 Gbps" :
4139 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
4140 "1 Gbps" : "unknown speed")),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004141 ((flow_rx && flow_tx) ? "RX/TX" :
4142 (flow_rx ? "RX" :
4143 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07004144
4145 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004146 } else {
4147 /* Force detection of hung controller */
4148 adapter->detect_tx_hung = true;
4149 }
4150 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004151 adapter->link_up = false;
4152 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004153 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08004154 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
4155 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07004156 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004157 }
4158 }
4159
4160 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004161 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07004162}
4163
Auke Kok9a799d72007-09-15 14:07:45 -07004164static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004165 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
4166 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004167{
4168 struct ixgbe_adv_tx_context_desc *context_desc;
4169 unsigned int i;
4170 int err;
4171 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004172 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
4173 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07004174
4175 if (skb_is_gso(skb)) {
4176 if (skb_header_cloned(skb)) {
4177 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4178 if (err)
4179 return err;
4180 }
4181 l4len = tcp_hdrlen(skb);
4182 *hdr_len += l4len;
4183
Al Viro8327d002007-12-10 18:54:12 +00004184 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004185 struct iphdr *iph = ip_hdr(skb);
4186 iph->tot_len = 0;
4187 iph->check = 0;
4188 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004189 iph->daddr, 0,
4190 IPPROTO_TCP,
4191 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004192 adapter->hw_tso_ctxt++;
4193 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
4194 ipv6_hdr(skb)->payload_len = 0;
4195 tcp_hdr(skb)->check =
4196 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004197 &ipv6_hdr(skb)->daddr,
4198 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004199 adapter->hw_tso6_ctxt++;
4200 }
4201
4202 i = tx_ring->next_to_use;
4203
4204 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4205 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4206
4207 /* VLAN MACLEN IPLEN */
4208 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4209 vlan_macip_lens |=
4210 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4211 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004212 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004213 *hdr_len += skb_network_offset(skb);
4214 vlan_macip_lens |=
4215 (skb_transport_header(skb) - skb_network_header(skb));
4216 *hdr_len +=
4217 (skb_transport_header(skb) - skb_network_header(skb));
4218 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4219 context_desc->seqnum_seed = 0;
4220
4221 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004222 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004223 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004224
Al Viro8327d002007-12-10 18:54:12 +00004225 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004226 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4227 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
4228 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4229
4230 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004231 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07004232 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
4233 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004234 /* use index 1 for TSO */
4235 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004236 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4237
4238 tx_buffer_info->time_stamp = jiffies;
4239 tx_buffer_info->next_to_watch = i;
4240
4241 i++;
4242 if (i == tx_ring->count)
4243 i = 0;
4244 tx_ring->next_to_use = i;
4245
4246 return true;
4247 }
4248 return false;
4249}
4250
4251static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004252 struct ixgbe_ring *tx_ring,
4253 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07004254{
4255 struct ixgbe_adv_tx_context_desc *context_desc;
4256 unsigned int i;
4257 struct ixgbe_tx_buffer *tx_buffer_info;
4258 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4259
4260 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4261 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4262 i = tx_ring->next_to_use;
4263 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4264 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4265
4266 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4267 vlan_macip_lens |=
4268 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4269 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004270 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004271 if (skb->ip_summed == CHECKSUM_PARTIAL)
4272 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004273 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07004274
4275 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4276 context_desc->seqnum_seed = 0;
4277
4278 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004279 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004280
4281 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08004282 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004283 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07004284 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08004285 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4286 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004287 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004288 else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
4289 type_tucmd_mlhl |=
4290 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004291 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004292 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08004293 /* XXX what about other V6 headers?? */
4294 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4295 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004296 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004297 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
4298 type_tucmd_mlhl |=
4299 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004300 break;
Auke Kok41825d72008-02-12 15:20:33 -08004301 default:
4302 if (unlikely(net_ratelimit())) {
4303 DPRINTK(PROBE, WARNING,
4304 "partial checksum but proto=%x!\n",
4305 skb->protocol);
4306 }
4307 break;
4308 }
Auke Kok9a799d72007-09-15 14:07:45 -07004309 }
4310
4311 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004312 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07004313 context_desc->mss_l4len_idx = 0;
4314
4315 tx_buffer_info->time_stamp = jiffies;
4316 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004317
Auke Kok9a799d72007-09-15 14:07:45 -07004318 adapter->hw_csum_tx_good++;
4319 i++;
4320 if (i == tx_ring->count)
4321 i = 0;
4322 tx_ring->next_to_use = i;
4323
4324 return true;
4325 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004326
Auke Kok9a799d72007-09-15 14:07:45 -07004327 return false;
4328}
4329
4330static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004331 struct ixgbe_ring *tx_ring,
4332 struct sk_buff *skb, unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07004333{
4334 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004335 unsigned int len = skb_headlen(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004336 unsigned int offset = 0, size, count = 0, i;
4337 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
4338 unsigned int f;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004339 dma_addr_t *map;
Auke Kok9a799d72007-09-15 14:07:45 -07004340
4341 i = tx_ring->next_to_use;
4342
Alexander Duyck44df32c2009-03-31 21:34:23 +00004343 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
4344 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
4345 return 0;
4346 }
4347
4348 map = skb_shinfo(skb)->dma_maps;
4349
Auke Kok9a799d72007-09-15 14:07:45 -07004350 while (len) {
4351 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4352 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4353
4354 tx_buffer_info->length = size;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004355 tx_buffer_info->dma = map[0] + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004356 tx_buffer_info->time_stamp = jiffies;
4357 tx_buffer_info->next_to_watch = i;
4358
4359 len -= size;
4360 offset += size;
4361 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004362
4363 if (len) {
4364 i++;
4365 if (i == tx_ring->count)
4366 i = 0;
4367 }
Auke Kok9a799d72007-09-15 14:07:45 -07004368 }
4369
4370 for (f = 0; f < nr_frags; f++) {
4371 struct skb_frag_struct *frag;
4372
4373 frag = &skb_shinfo(skb)->frags[f];
4374 len = frag->size;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004375 offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004376
4377 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00004378 i++;
4379 if (i == tx_ring->count)
4380 i = 0;
4381
Auke Kok9a799d72007-09-15 14:07:45 -07004382 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4383 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4384
4385 tx_buffer_info->length = size;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004386 tx_buffer_info->dma = map[f + 1] + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004387 tx_buffer_info->time_stamp = jiffies;
4388 tx_buffer_info->next_to_watch = i;
4389
4390 len -= size;
4391 offset += size;
4392 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07004393 }
4394 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00004395
Auke Kok9a799d72007-09-15 14:07:45 -07004396 tx_ring->tx_buffer_info[i].skb = skb;
4397 tx_ring->tx_buffer_info[first].next_to_watch = i;
4398
4399 return count;
4400}
4401
4402static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004403 struct ixgbe_ring *tx_ring,
4404 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004405{
4406 union ixgbe_adv_tx_desc *tx_desc = NULL;
4407 struct ixgbe_tx_buffer *tx_buffer_info;
4408 u32 olinfo_status = 0, cmd_type_len = 0;
4409 unsigned int i;
4410 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
4411
4412 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
4413
4414 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
4415
4416 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4417 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
4418
4419 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
4420 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4421
4422 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004423 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004424
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004425 /* use index 1 context for tso */
4426 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004427 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
4428 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004429 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004430
4431 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
4432 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004433 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004434
4435 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
4436
4437 i = tx_ring->next_to_use;
4438 while (count--) {
4439 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4440 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
4441 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
4442 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004443 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07004444 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07004445 i++;
4446 if (i == tx_ring->count)
4447 i = 0;
4448 }
4449
4450 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
4451
4452 /*
4453 * Force memory writes to complete before letting h/w
4454 * know there are new descriptors to fetch. (Only
4455 * applicable for weak-ordered memory model archs,
4456 * such as IA-64).
4457 */
4458 wmb();
4459
4460 tx_ring->next_to_use = i;
4461 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4462}
4463
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004464static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004465 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004466{
4467 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4468
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004469 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004470 /* Herbert's original patch had:
4471 * smp_mb__after_netif_stop_queue();
4472 * but since that doesn't exist yet, just open code it. */
4473 smp_mb();
4474
4475 /* We need to check again in a case another CPU has just
4476 * made room available. */
4477 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
4478 return -EBUSY;
4479
4480 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07004481 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004482 ++adapter->restart_queue;
4483 return 0;
4484}
4485
4486static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004487 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004488{
4489 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
4490 return 0;
4491 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
4492}
4493
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07004494static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
4495{
4496 struct ixgbe_adapter *adapter = netdev_priv(dev);
4497
4498 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4499 return 0; /* All traffic should default to class 0 */
4500
4501 return skb_tx_hash(dev, skb);
4502}
4503
Auke Kok9a799d72007-09-15 14:07:45 -07004504static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
4505{
4506 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4507 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004508 unsigned int first;
4509 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004510 u8 hdr_len = 0;
4511 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07004512 int count = 0;
4513 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004514
Wu Fengguang95615d92009-04-14 21:53:48 -07004515 r_idx = skb->queue_mapping;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004516 tx_ring = &adapter->tx_ring[r_idx];
Auke Kok9a799d72007-09-15 14:07:45 -07004517
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004518 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
4519 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004520 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4521 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
4522 tx_flags |= (skb->queue_mapping << 13);
4523 }
4524 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
4525 tx_flags |= IXGBE_TX_FLAGS_VLAN;
4526 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4527 tx_flags |= (skb->queue_mapping << 13);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004528 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
4529 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07004530 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004531 /* three things can cause us to need a context descriptor */
4532 if (skb_is_gso(skb) ||
4533 (skb->ip_summed == CHECKSUM_PARTIAL) ||
4534 (tx_flags & IXGBE_TX_FLAGS_VLAN))
Auke Kok9a799d72007-09-15 14:07:45 -07004535 count++;
4536
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004537 count += TXD_USE_COUNT(skb_headlen(skb));
4538 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07004539 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
4540
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004541 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004542 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07004543 return NETDEV_TX_BUSY;
4544 }
Auke Kok9a799d72007-09-15 14:07:45 -07004545
Al Viro8327d002007-12-10 18:54:12 +00004546 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004547 tx_flags |= IXGBE_TX_FLAGS_IPV4;
4548 first = tx_ring->next_to_use;
4549 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
4550 if (tso < 0) {
4551 dev_kfree_skb_any(skb);
4552 return NETDEV_TX_OK;
4553 }
4554
4555 if (tso)
4556 tx_flags |= IXGBE_TX_FLAGS_TSO;
4557 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004558 (skb->ip_summed == CHECKSUM_PARTIAL))
Auke Kok9a799d72007-09-15 14:07:45 -07004559 tx_flags |= IXGBE_TX_FLAGS_CSUM;
4560
Alexander Duyck44df32c2009-03-31 21:34:23 +00004561 count = ixgbe_tx_map(adapter, tx_ring, skb, first);
Auke Kok9a799d72007-09-15 14:07:45 -07004562
Alexander Duyck44df32c2009-03-31 21:34:23 +00004563 if (count) {
4564 ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
4565 hdr_len);
4566 netdev->trans_start = jiffies;
4567 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07004568
Alexander Duyck44df32c2009-03-31 21:34:23 +00004569 } else {
4570 dev_kfree_skb_any(skb);
4571 tx_ring->tx_buffer_info[first].time_stamp = 0;
4572 tx_ring->next_to_use = first;
4573 }
Auke Kok9a799d72007-09-15 14:07:45 -07004574
4575 return NETDEV_TX_OK;
4576}
4577
4578/**
4579 * ixgbe_get_stats - Get System Network Statistics
4580 * @netdev: network interface device structure
4581 *
4582 * Returns the address of the device statistics structure.
4583 * The statistics are actually updated from the timer callback.
4584 **/
4585static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
4586{
4587 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4588
4589 /* only return the current stats */
4590 return &adapter->net_stats;
4591}
4592
4593/**
4594 * ixgbe_set_mac - Change the Ethernet Address of the NIC
4595 * @netdev: network interface device structure
4596 * @p: pointer to an address structure
4597 *
4598 * Returns 0 on success, negative on failure
4599 **/
4600static int ixgbe_set_mac(struct net_device *netdev, void *p)
4601{
4602 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004603 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004604 struct sockaddr *addr = p;
4605
4606 if (!is_valid_ether_addr(addr->sa_data))
4607 return -EADDRNOTAVAIL;
4608
4609 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004610 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07004611
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004612 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004613
4614 return 0;
4615}
4616
4617#ifdef CONFIG_NET_POLL_CONTROLLER
4618/*
4619 * Polling 'interrupt' - used by things like netconsole to send skbs
4620 * without having to re-enable interrupts. It's not called while
4621 * the interrupt routine is executing.
4622 */
4623static void ixgbe_netpoll(struct net_device *netdev)
4624{
4625 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4626
4627 disable_irq(adapter->pdev->irq);
4628 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
4629 ixgbe_intr(adapter->pdev->irq, netdev);
4630 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
4631 enable_irq(adapter->pdev->irq);
4632}
4633#endif
4634
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004635static const struct net_device_ops ixgbe_netdev_ops = {
4636 .ndo_open = ixgbe_open,
4637 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08004638 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07004639 .ndo_select_queue = ixgbe_select_queue,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004640 .ndo_get_stats = ixgbe_get_stats,
Chris Leeche90d4002009-03-10 16:00:24 +00004641 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004642 .ndo_set_multicast_list = ixgbe_set_rx_mode,
4643 .ndo_validate_addr = eth_validate_addr,
4644 .ndo_set_mac_address = ixgbe_set_mac,
4645 .ndo_change_mtu = ixgbe_change_mtu,
4646 .ndo_tx_timeout = ixgbe_tx_timeout,
4647 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
4648 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
4649 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
4650#ifdef CONFIG_NET_POLL_CONTROLLER
4651 .ndo_poll_controller = ixgbe_netpoll,
4652#endif
4653};
4654
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004655/**
Auke Kok9a799d72007-09-15 14:07:45 -07004656 * ixgbe_probe - Device Initialization Routine
4657 * @pdev: PCI device information struct
4658 * @ent: entry in ixgbe_pci_tbl
4659 *
4660 * Returns 0 on success, negative on failure
4661 *
4662 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
4663 * The OS initialization, configuring of the adapter private structure,
4664 * and a hardware reset occur.
4665 **/
4666static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004667 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07004668{
4669 struct net_device *netdev;
4670 struct ixgbe_adapter *adapter = NULL;
4671 struct ixgbe_hw *hw;
4672 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07004673 static int cards_found;
4674 int i, err, pci_using_dac;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004675 u16 pm_value = 0;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004676 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07004677
4678 err = pci_enable_device(pdev);
4679 if (err)
4680 return err;
4681
Yang Hongyang6a355282009-04-06 19:01:13 -07004682 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
4683 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07004684 pci_using_dac = 1;
4685 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07004686 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07004687 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -07004688 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07004689 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004690 dev_err(&pdev->dev, "No usable DMA "
4691 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004692 goto err_dma;
4693 }
4694 }
4695 pci_using_dac = 0;
4696 }
4697
4698 err = pci_request_regions(pdev, ixgbe_driver_name);
4699 if (err) {
4700 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
4701 goto err_pci_reg;
4702 }
4703
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004704 err = pci_enable_pcie_error_reporting(pdev);
4705 if (err) {
4706 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
4707 "0x%x\n", err);
4708 /* non-fatal, continue */
4709 }
4710
Auke Kok9a799d72007-09-15 14:07:45 -07004711 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07004712 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004713
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004714 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07004715 if (!netdev) {
4716 err = -ENOMEM;
4717 goto err_alloc_etherdev;
4718 }
4719
Auke Kok9a799d72007-09-15 14:07:45 -07004720 SET_NETDEV_DEV(netdev, &pdev->dev);
4721
4722 pci_set_drvdata(pdev, netdev);
4723 adapter = netdev_priv(netdev);
4724
4725 adapter->netdev = netdev;
4726 adapter->pdev = pdev;
4727 hw = &adapter->hw;
4728 hw->back = adapter;
4729 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
4730
Jeff Kirsher05857982008-09-11 19:57:00 -07004731 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
4732 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07004733 if (!hw->hw_addr) {
4734 err = -EIO;
4735 goto err_ioremap;
4736 }
4737
4738 for (i = 1; i <= 5; i++) {
4739 if (pci_resource_len(pdev, i) == 0)
4740 continue;
4741 }
4742
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004743 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07004744 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004745 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07004746 strcpy(netdev->name, pci_name(pdev));
4747
Auke Kok9a799d72007-09-15 14:07:45 -07004748 adapter->bd_number = cards_found;
4749
Auke Kok9a799d72007-09-15 14:07:45 -07004750 /* Setup hw api */
4751 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004752 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07004753
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004754 /* EEPROM */
4755 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
4756 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
4757 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
4758 if (!(eec & (1 << 8)))
4759 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
4760
4761 /* PHY */
4762 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08004763 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
4764
4765 /* set up this timer and work struct before calling get_invariants
4766 * which might start the timer
4767 */
4768 init_timer(&adapter->sfp_timer);
4769 adapter->sfp_timer.function = &ixgbe_sfp_timer;
4770 adapter->sfp_timer.data = (unsigned long) adapter;
4771
4772 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004773
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004774 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
4775 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
4776
4777 /* a new SFP+ module arrival, called from GPI SDP2 context */
4778 INIT_WORK(&adapter->sfp_config_module_task,
4779 ixgbe_sfp_config_module_task);
4780
Auke Kok9a799d72007-09-15 14:07:45 -07004781 err = ii->get_invariants(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004782 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
4783 /* start a kernel thread to watch for a module to arrive */
4784 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4785 mod_timer(&adapter->sfp_timer,
4786 round_jiffies(jiffies + (2 * HZ)));
4787 err = 0;
4788 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4789 DPRINTK(PROBE, ERR, "failed to load because an "
4790 "unsupported SFP+ module type was detected.\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004791 goto err_hw_init;
Donald Skidmorec4900be2008-11-20 21:11:42 -08004792 } else if (err) {
4793 goto err_hw_init;
4794 }
Auke Kok9a799d72007-09-15 14:07:45 -07004795
4796 /* setup the private structure */
4797 err = ixgbe_sw_init(adapter);
4798 if (err)
4799 goto err_sw_init;
4800
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004801 /* reset_hw fills in the perm_addr as well */
4802 err = hw->mac.ops.reset_hw(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00004803 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4804 dev_err(&adapter->pdev->dev, "failed to load because an "
4805 "unsupported SFP+ module type was detected.\n");
4806 goto err_sw_init;
4807 } else if (err) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004808 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
4809 goto err_sw_init;
4810 }
4811
Auke Kok9a799d72007-09-15 14:07:45 -07004812 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004813 NETIF_F_IP_CSUM |
4814 NETIF_F_HW_VLAN_TX |
4815 NETIF_F_HW_VLAN_RX |
4816 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004817
Jesse Brandeburge9990a92008-08-26 04:27:24 -07004818 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07004819 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07004820 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08004821 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004822
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004823 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
4824 netdev->features |= NETIF_F_SCTP_CSUM;
4825
Jeff Kirsherad31c402008-06-05 04:05:30 -07004826 netdev->vlan_features |= NETIF_F_TSO;
4827 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07004828 netdev->vlan_features |= NETIF_F_IP_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004829 netdev->vlan_features |= NETIF_F_SG;
4830
Alexander Duyck2f90b862008-11-20 20:52:10 -08004831 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4832 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4833
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004834#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004835 netdev->dcbnl_ops = &dcbnl_ops;
4836#endif
4837
Auke Kok9a799d72007-09-15 14:07:45 -07004838 if (pci_using_dac)
4839 netdev->features |= NETIF_F_HIGHDMA;
4840
Alexander Duyckf8212f92009-04-27 22:42:37 +00004841 if (adapter->flags & IXGBE_FLAG_RSC_ENABLED)
4842 netdev->features |= NETIF_F_LRO;
4843
Auke Kok9a799d72007-09-15 14:07:45 -07004844 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004845 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07004846 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
4847 err = -EIO;
4848 goto err_eeprom;
4849 }
4850
4851 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
4852 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
4853
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004854 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
4855 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004856 err = -EIO;
4857 goto err_eeprom;
4858 }
4859
4860 init_timer(&adapter->watchdog_timer);
4861 adapter->watchdog_timer.function = &ixgbe_watchdog;
4862 adapter->watchdog_timer.data = (unsigned long)adapter;
4863
4864 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004865 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004866
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004867 err = ixgbe_init_interrupt_scheme(adapter);
4868 if (err)
4869 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07004870
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004871 switch (pdev->device) {
4872 case IXGBE_DEV_ID_82599_KX4:
4873#define IXGBE_PCIE_PMCSR 0x44
4874 adapter->wol = IXGBE_WUFC_MAG;
4875 pci_read_config_word(pdev, IXGBE_PCIE_PMCSR, &pm_value);
4876 pci_write_config_word(pdev, IXGBE_PCIE_PMCSR,
4877 (pm_value | (1 << 8)));
4878 break;
4879 default:
4880 adapter->wol = 0;
4881 break;
4882 }
4883 device_init_wakeup(&adapter->pdev->dev, true);
4884 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
4885
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00004886 /* pick up the PCI bus settings for reporting later */
4887 hw->mac.ops.get_bus_info(hw);
4888
Auke Kok9a799d72007-09-15 14:07:45 -07004889 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07004890 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004891 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
4892 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
4893 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
4894 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
4895 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004896 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07004897 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004898 ixgbe_read_pba_num_generic(hw, &part_num);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004899 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
4900 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
4901 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
4902 (part_num >> 8), (part_num & 0xff));
4903 else
4904 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4905 hw->mac.type, hw->phy.type,
4906 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07004907
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004908 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Auke Kok0c254d82008-02-11 09:25:56 -08004909 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004910 "this card is not sufficient for optimal "
4911 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004912 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004913 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004914 }
4915
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08004916 /* save off EEPROM version number */
4917 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
4918
Auke Kok9a799d72007-09-15 14:07:45 -07004919 /* reset the hardware with the new settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004920 hw->mac.ops.start_hw(hw);
4921
Auke Kok9a799d72007-09-15 14:07:45 -07004922 strcpy(netdev->name, "eth%d");
4923 err = register_netdev(netdev);
4924 if (err)
4925 goto err_register;
4926
Jesse Brandeburg54386462009-04-17 20:44:27 +00004927 /* carrier off reporting is important to ethtool even BEFORE open */
4928 netif_carrier_off(netdev);
4929
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004930#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03004931 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004932 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
4933 /* always use CB2 mode, difference is masked
4934 * in the CB driver */
4935 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
4936 ixgbe_setup_dca(adapter);
4937 }
4938#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004939
4940 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
4941 cards_found++;
4942 return 0;
4943
4944err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004945 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004946err_hw_init:
4947err_sw_init:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004948 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004949err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08004950 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4951 del_timer_sync(&adapter->sfp_timer);
4952 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004953 cancel_work_sync(&adapter->multispeed_fiber_task);
4954 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004955 iounmap(hw->hw_addr);
4956err_ioremap:
4957 free_netdev(netdev);
4958err_alloc_etherdev:
4959 pci_release_regions(pdev);
4960err_pci_reg:
4961err_dma:
4962 pci_disable_device(pdev);
4963 return err;
4964}
4965
4966/**
4967 * ixgbe_remove - Device Removal Routine
4968 * @pdev: PCI device information struct
4969 *
4970 * ixgbe_remove is called by the PCI subsystem to alert the driver
4971 * that it should release a PCI device. The could be caused by a
4972 * Hot-Plug event, or because the driver is going to be removed from
4973 * memory.
4974 **/
4975static void __devexit ixgbe_remove(struct pci_dev *pdev)
4976{
4977 struct net_device *netdev = pci_get_drvdata(pdev);
4978 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004979 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004980
4981 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004982 /* clear the module not found bit to make sure the worker won't
4983 * reschedule
4984 */
4985 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07004986 del_timer_sync(&adapter->watchdog_timer);
4987
Donald Skidmorec4900be2008-11-20 21:11:42 -08004988 del_timer_sync(&adapter->sfp_timer);
4989 cancel_work_sync(&adapter->watchdog_task);
4990 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004991 cancel_work_sync(&adapter->multispeed_fiber_task);
4992 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004993 flush_scheduled_work();
4994
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004995#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004996 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
4997 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
4998 dca_remove_requester(&pdev->dev);
4999 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
5000 }
5001
5002#endif
Donald Skidmorec4900be2008-11-20 21:11:42 -08005003 if (netdev->reg_state == NETREG_REGISTERED)
5004 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005005
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005006 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005007
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005008 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005009
5010 iounmap(adapter->hw.hw_addr);
5011 pci_release_regions(pdev);
5012
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005013 DPRINTK(PROBE, INFO, "complete\n");
5014 kfree(adapter->tx_ring);
5015 kfree(adapter->rx_ring);
5016
Auke Kok9a799d72007-09-15 14:07:45 -07005017 free_netdev(netdev);
5018
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005019 err = pci_disable_pcie_error_reporting(pdev);
5020 if (err)
5021 dev_err(&pdev->dev,
5022 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
5023
Auke Kok9a799d72007-09-15 14:07:45 -07005024 pci_disable_device(pdev);
5025}
5026
5027/**
5028 * ixgbe_io_error_detected - called when PCI error is detected
5029 * @pdev: Pointer to PCI device
5030 * @state: The current pci connection state
5031 *
5032 * This function is called after a PCI bus error affecting
5033 * this device has been detected.
5034 */
5035static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005036 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07005037{
5038 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005039 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005040
5041 netif_device_detach(netdev);
5042
5043 if (netif_running(netdev))
5044 ixgbe_down(adapter);
5045 pci_disable_device(pdev);
5046
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005047 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07005048 return PCI_ERS_RESULT_NEED_RESET;
5049}
5050
5051/**
5052 * ixgbe_io_slot_reset - called after the pci bus has been reset.
5053 * @pdev: Pointer to PCI device
5054 *
5055 * Restart the card from scratch, as if from a cold-boot.
5056 */
5057static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
5058{
5059 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005060 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005061 pci_ers_result_t result;
5062 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005063
5064 if (pci_enable_device(pdev)) {
5065 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005066 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005067 result = PCI_ERS_RESULT_DISCONNECT;
5068 } else {
5069 pci_set_master(pdev);
5070 pci_restore_state(pdev);
5071
5072 pci_enable_wake(pdev, PCI_D3hot, 0);
5073 pci_enable_wake(pdev, PCI_D3cold, 0);
5074
5075 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00005076 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005077 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07005078 }
Auke Kok9a799d72007-09-15 14:07:45 -07005079
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005080 err = pci_cleanup_aer_uncorrect_error_status(pdev);
5081 if (err) {
5082 dev_err(&pdev->dev,
5083 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
5084 /* non-fatal, continue */
5085 }
Auke Kok9a799d72007-09-15 14:07:45 -07005086
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005087 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07005088}
5089
5090/**
5091 * ixgbe_io_resume - called when traffic can start flowing again.
5092 * @pdev: Pointer to PCI device
5093 *
5094 * This callback is called when the error recovery driver tells us that
5095 * its OK to resume normal operation.
5096 */
5097static void ixgbe_io_resume(struct pci_dev *pdev)
5098{
5099 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005100 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005101
5102 if (netif_running(netdev)) {
5103 if (ixgbe_up(adapter)) {
5104 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
5105 return;
5106 }
5107 }
5108
5109 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005110}
5111
5112static struct pci_error_handlers ixgbe_err_handler = {
5113 .error_detected = ixgbe_io_error_detected,
5114 .slot_reset = ixgbe_io_slot_reset,
5115 .resume = ixgbe_io_resume,
5116};
5117
5118static struct pci_driver ixgbe_driver = {
5119 .name = ixgbe_driver_name,
5120 .id_table = ixgbe_pci_tbl,
5121 .probe = ixgbe_probe,
5122 .remove = __devexit_p(ixgbe_remove),
5123#ifdef CONFIG_PM
5124 .suspend = ixgbe_suspend,
5125 .resume = ixgbe_resume,
5126#endif
5127 .shutdown = ixgbe_shutdown,
5128 .err_handler = &ixgbe_err_handler
5129};
5130
5131/**
5132 * ixgbe_init_module - Driver Registration Routine
5133 *
5134 * ixgbe_init_module is the first routine called when the driver is
5135 * loaded. All it does is register with the PCI subsystem.
5136 **/
5137static int __init ixgbe_init_module(void)
5138{
5139 int ret;
5140 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
5141 ixgbe_driver_string, ixgbe_driver_version);
5142
5143 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
5144
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005145#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005146 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005147#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005148
Auke Kok9a799d72007-09-15 14:07:45 -07005149 ret = pci_register_driver(&ixgbe_driver);
5150 return ret;
5151}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005152
Auke Kok9a799d72007-09-15 14:07:45 -07005153module_init(ixgbe_init_module);
5154
5155/**
5156 * ixgbe_exit_module - Driver Exit Cleanup Routine
5157 *
5158 * ixgbe_exit_module is called just before the driver is removed
5159 * from memory.
5160 **/
5161static void __exit ixgbe_exit_module(void)
5162{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005163#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005164 dca_unregister_notify(&dca_notifier);
5165#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005166 pci_unregister_driver(&ixgbe_driver);
5167}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005168
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005169#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005170static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005171 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005172{
5173 int ret_val;
5174
5175 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005176 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005177
5178 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
5179}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005180
Alexander Duyckb4533682009-03-31 21:32:42 +00005181#endif /* CONFIG_IXGBE_DCA */
5182#ifdef DEBUG
5183/**
5184 * ixgbe_get_hw_dev_name - return device name string
5185 * used by hardware layer to print debugging information
5186 **/
5187char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
5188{
5189 struct ixgbe_adapter *adapter = hw->back;
5190 return adapter->netdev->name;
5191}
5192
5193#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005194module_exit(ixgbe_exit_module);
5195
5196/* ixgbe_main.c */