blob: 47a3c6d705698113e4bd338be8a6c6182341f0bf [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>
Lucy Liu60127862009-07-22 14:07:33 +000037#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070038#include <linux/ipv6.h>
39#include <net/checksum.h>
40#include <net/ip6_checksum.h>
41#include <linux/ethtool.h>
42#include <linux/if_vlan.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000043#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070044
45#include "ixgbe.h"
46#include "ixgbe_common.h"
47
48char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070049static const char ixgbe_driver_string[] =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070050 "Intel(R) 10 Gigabit PCI Express Network Driver";
Auke Kok9a799d72007-09-15 14:07:45 -070051
Peter P Waskiewicz Jra1c1db32009-06-04 16:02:44 +000052#define DRV_VERSION "2.0.34-k2"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070053const char ixgbe_driver_version[] = DRV_VERSION;
Peter P Waskiewicz Jr3efac5a2009-02-01 01:19:20 -080054static char ixgbe_copyright[] = "Copyright (c) 1999-2009 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070055
56static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070057 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000058 [board_82599] = &ixgbe_82599_info,
Auke Kok9a799d72007-09-15 14:07:45 -070059};
60
61/* ixgbe_pci_tbl - PCI Device ID Table
62 *
63 * Wildcard entries (PCI_ANY_ID) should come last
64 * Last entry must be all 0s
65 *
66 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
67 * Class, Class Mask, private data (not used) }
68 */
69static struct pci_device_id ixgbe_pci_tbl[] = {
Don Skidmore1e336d02009-01-26 20:57:51 -080070 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
71 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070072 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070073 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070074 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070075 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070076 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
77 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070078 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070079 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070080 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
81 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080082 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
83 board_82598 },
84 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
85 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070086 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
87 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080088 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
89 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -080090 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
91 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +000092 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
93 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +000094 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
95 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +000096 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
97 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -070098
99 /* required last entry */
100 {0, }
101};
102MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
103
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400104#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800105static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700106 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800107static struct notifier_block dca_notifier = {
108 .notifier_call = ixgbe_notify_dca,
109 .next = NULL,
110 .priority = 0
111};
112#endif
113
Auke Kok9a799d72007-09-15 14:07:45 -0700114MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
115MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
116MODULE_LICENSE("GPL");
117MODULE_VERSION(DRV_VERSION);
118
119#define DEFAULT_DEBUG_LEVEL_SHIFT 3
120
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800121static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
122{
123 u32 ctrl_ext;
124
125 /* Let firmware take over control of h/w */
126 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
127 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700128 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800129}
130
131static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
132{
133 u32 ctrl_ext;
134
135 /* Let firmware know the driver has taken over */
136 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
137 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700138 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800139}
Auke Kok9a799d72007-09-15 14:07:45 -0700140
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000141/*
142 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
143 * @adapter: pointer to adapter struct
144 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
145 * @queue: queue to map the corresponding interrupt to
146 * @msix_vector: the vector to map to the corresponding queue
147 *
148 */
149static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
150 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700151{
152 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000153 struct ixgbe_hw *hw = &adapter->hw;
154 switch (hw->mac.type) {
155 case ixgbe_mac_82598EB:
156 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
157 if (direction == -1)
158 direction = 0;
159 index = (((direction * 64) + queue) >> 2) & 0x1F;
160 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
161 ivar &= ~(0xFF << (8 * (queue & 0x3)));
162 ivar |= (msix_vector << (8 * (queue & 0x3)));
163 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
164 break;
165 case ixgbe_mac_82599EB:
166 if (direction == -1) {
167 /* other causes */
168 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
169 index = ((queue & 1) * 8);
170 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
171 ivar &= ~(0xFF << index);
172 ivar |= (msix_vector << index);
173 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
174 break;
175 } else {
176 /* tx or rx causes */
177 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
178 index = ((16 * (queue & 1)) + (8 * direction));
179 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
180 ivar &= ~(0xFF << index);
181 ivar |= (msix_vector << index);
182 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
183 break;
184 }
185 default:
186 break;
187 }
Auke Kok9a799d72007-09-15 14:07:45 -0700188}
189
Alexander Duyckfe49f042009-06-04 16:00:09 +0000190static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
191 u64 qmask)
192{
193 u32 mask;
194
195 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
196 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
197 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
198 } else {
199 mask = (qmask & 0xFFFFFFFF);
200 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
201 mask = (qmask >> 32);
202 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
203 }
204}
205
Auke Kok9a799d72007-09-15 14:07:45 -0700206static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700207 struct ixgbe_tx_buffer
208 *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700209{
Alexander Duyck44df32c2009-03-31 21:34:23 +0000210 tx_buffer_info->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700211 if (tx_buffer_info->skb) {
Alexander Duyck44df32c2009-03-31 21:34:23 +0000212 skb_dma_unmap(&adapter->pdev->dev, tx_buffer_info->skb,
213 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700214 dev_kfree_skb_any(tx_buffer_info->skb);
215 tx_buffer_info->skb = NULL;
216 }
Alexander Duyck44df32c2009-03-31 21:34:23 +0000217 tx_buffer_info->time_stamp = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700218 /* tx_buffer_info must be completely set up in the transmit path */
219}
220
221static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700222 struct ixgbe_ring *tx_ring,
223 unsigned int eop)
Auke Kok9a799d72007-09-15 14:07:45 -0700224{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700225 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700226
Auke Kok9a799d72007-09-15 14:07:45 -0700227 /* Detect a transmit hang in hardware, this serializes the
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700228 * check with the clearing of time_stamp and movement of eop */
Auke Kok9a799d72007-09-15 14:07:45 -0700229 adapter->detect_tx_hung = false;
Alexander Duyck44df32c2009-03-31 21:34:23 +0000230 if (tx_ring->tx_buffer_info[eop].time_stamp &&
Auke Kok9a799d72007-09-15 14:07:45 -0700231 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
232 !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) {
233 /* detected Tx unit hang */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700234 union ixgbe_adv_tx_desc *tx_desc;
235 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
Auke Kok9a799d72007-09-15 14:07:45 -0700236 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700237 " Tx Queue <%d>\n"
238 " TDH, TDT <%x>, <%x>\n"
Auke Kok9a799d72007-09-15 14:07:45 -0700239 " next_to_use <%x>\n"
240 " next_to_clean <%x>\n"
241 "tx_buffer_info[next_to_clean]\n"
242 " time_stamp <%lx>\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700243 " jiffies <%lx>\n",
244 tx_ring->queue_index,
Alexander Duyck44df32c2009-03-31 21:34:23 +0000245 IXGBE_READ_REG(hw, tx_ring->head),
246 IXGBE_READ_REG(hw, tx_ring->tail),
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700247 tx_ring->next_to_use, eop,
248 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
Auke Kok9a799d72007-09-15 14:07:45 -0700249 return true;
250 }
251
252 return false;
253}
254
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700255#define IXGBE_MAX_TXD_PWR 14
256#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800257
258/* Tx Descriptors needed, worst case */
259#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
260 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
261#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700262 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800263
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700264static void ixgbe_tx_timeout(struct net_device *netdev);
265
Auke Kok9a799d72007-09-15 14:07:45 -0700266/**
267 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000268 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700269 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700270 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000271static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700272 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700273{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000274 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700275 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800276 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
277 struct ixgbe_tx_buffer *tx_buffer_info;
278 unsigned int i, eop, count = 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700279 unsigned int total_bytes = 0, total_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700280
281 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800282 eop = tx_ring->tx_buffer_info[i].next_to_watch;
283 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
284
285 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000286 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800287 bool cleaned = false;
288 for ( ; !cleaned; count++) {
289 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700290 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
291 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800292 cleaned = (i == eop);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700293 skb = tx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700294
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800295 if (cleaned && skb) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800296 unsigned int segs, bytecount;
Yi Zou3d8fd382009-06-08 14:38:44 +0000297 unsigned int hlen = skb_headlen(skb);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700298
299 /* gso_segs is currently only valid for tcp */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800300 segs = skb_shinfo(skb)->gso_segs ?: 1;
Yi Zou3d8fd382009-06-08 14:38:44 +0000301#ifdef IXGBE_FCOE
302 /* adjust for FCoE Sequence Offload */
303 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
304 && (skb->protocol == htons(ETH_P_FCOE)) &&
305 skb_is_gso(skb)) {
306 hlen = skb_transport_offset(skb) +
307 sizeof(struct fc_frame_header) +
308 sizeof(struct fcoe_crc_eof);
309 segs = DIV_ROUND_UP(skb->len - hlen,
310 skb_shinfo(skb)->gso_size);
311 }
312#endif /* IXGBE_FCOE */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800313 /* multiply data chunks by size of headers */
Yi Zou3d8fd382009-06-08 14:38:44 +0000314 bytecount = ((segs - 1) * hlen) + skb->len;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700315 total_packets += segs;
316 total_bytes += bytecount;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800317 }
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700318
Auke Kok9a799d72007-09-15 14:07:45 -0700319 ixgbe_unmap_and_free_tx_resource(adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700320 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700321
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800322 tx_desc->wb.status = 0;
323
Auke Kok9a799d72007-09-15 14:07:45 -0700324 i++;
325 if (i == tx_ring->count)
326 i = 0;
327 }
328
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800329 eop = tx_ring->tx_buffer_info[i].next_to_watch;
330 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
331 }
332
Auke Kok9a799d72007-09-15 14:07:45 -0700333 tx_ring->next_to_clean = i;
334
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800335#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700336 if (unlikely(count && netif_carrier_ok(netdev) &&
337 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800338 /* Make sure that anybody stopping the queue after this
339 * sees the new next_to_clean.
340 */
341 smp_mb();
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800342 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
343 !test_bit(__IXGBE_DOWN, &adapter->state)) {
344 netif_wake_subqueue(netdev, tx_ring->queue_index);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700345 ++adapter->restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800346 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800347 }
Auke Kok9a799d72007-09-15 14:07:45 -0700348
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700349 if (adapter->detect_tx_hung) {
350 if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
351 /* schedule immediate reset if we believe we hung */
352 DPRINTK(PROBE, INFO,
353 "tx hang %d detected, resetting adapter\n",
354 adapter->tx_timeout_count + 1);
355 ixgbe_tx_timeout(adapter->netdev);
356 }
357 }
Auke Kok9a799d72007-09-15 14:07:45 -0700358
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700359 /* re-arm the interrupt */
Alexander Duyckfe49f042009-06-04 16:00:09 +0000360 if (count >= tx_ring->work_limit)
361 ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -0700362
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700363 tx_ring->total_bytes += total_bytes;
364 tx_ring->total_packets += total_packets;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700365 tx_ring->stats.packets += total_packets;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800366 tx_ring->stats.bytes += total_bytes;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700367 adapter->net_stats.tx_bytes += total_bytes;
368 adapter->net_stats.tx_packets += total_packets;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000369 return (count < tx_ring->work_limit);
Auke Kok9a799d72007-09-15 14:07:45 -0700370}
371
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400372#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800373static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700374 struct ixgbe_ring *rx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800375{
376 u32 rxctrl;
377 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700378 int q = rx_ring - adapter->rx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800379
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700380 if (rx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800381 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000382 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
383 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
384 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
385 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
386 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
387 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
388 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
389 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800390 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
391 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
Don Skidmore15005a32009-01-19 16:54:13 -0800392 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
393 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000394 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800395 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700396 rx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800397 }
398 put_cpu();
399}
400
401static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700402 struct ixgbe_ring *tx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800403{
404 u32 txctrl;
405 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700406 int q = tx_ring - adapter->tx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800407
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700408 if (tx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800409 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000410 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
411 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
412 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
413 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
414 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
415 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
416 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
417 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800418 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
419 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700420 tx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800421 }
422 put_cpu();
423}
424
425static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
426{
427 int i;
428
429 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
430 return;
431
Alexander Duycke35ec122009-05-21 13:07:12 +0000432 /* always use CB2 mode, difference is masked in the CB driver */
433 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
434
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800435 for (i = 0; i < adapter->num_tx_queues; i++) {
436 adapter->tx_ring[i].cpu = -1;
437 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
438 }
439 for (i = 0; i < adapter->num_rx_queues; i++) {
440 adapter->rx_ring[i].cpu = -1;
441 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
442 }
443}
444
445static int __ixgbe_notify_dca(struct device *dev, void *data)
446{
447 struct net_device *netdev = dev_get_drvdata(dev);
448 struct ixgbe_adapter *adapter = netdev_priv(netdev);
449 unsigned long event = *(unsigned long *)data;
450
451 switch (event) {
452 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700453 /* if we're already enabled, don't do it again */
454 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
455 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300456 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700457 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800458 ixgbe_setup_dca(adapter);
459 break;
460 }
461 /* Fall Through since DCA is disabled. */
462 case DCA_PROVIDER_REMOVE:
463 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
464 dca_remove_requester(dev);
465 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
466 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
467 }
468 break;
469 }
470
Denis V. Lunev652f0932008-03-27 14:39:17 +0300471 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800472}
473
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400474#endif /* CONFIG_IXGBE_DCA */
Auke Kok9a799d72007-09-15 14:07:45 -0700475/**
476 * ixgbe_receive_skb - Send a completed packet up the stack
477 * @adapter: board private structure
478 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700479 * @status: hardware indication of status of receive
480 * @rx_ring: rx descriptor ring (for a specific queue) to setup
481 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -0700482 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800483static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700484 struct sk_buff *skb, u8 status,
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000485 struct ixgbe_ring *ring,
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700486 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -0700487{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800488 struct ixgbe_adapter *adapter = q_vector->adapter;
489 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700490 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
491 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -0700492
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000493 skb_record_rx_queue(skb, ring->queue_index);
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000494 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800495 if (adapter->vlgrp && is_vlan && (tag != 0))
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800496 vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700497 else
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800498 napi_gro_receive(napi, skb);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700499 } else {
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000500 if (adapter->vlgrp && is_vlan && (tag != 0))
501 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
502 else
503 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700504 }
505}
506
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800507/**
508 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
509 * @adapter: address of board private structure
510 * @status_err: hardware indication of status of receive
511 * @skb: skb currently being received and modified
512 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700513static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700514 u32 status_err, struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700515{
516 skb->ip_summed = CHECKSUM_NONE;
517
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700518 /* Rx csum disabled */
519 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -0700520 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800521
522 /* if IP and error */
523 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
524 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700525 adapter->hw_csum_rx_error++;
526 return;
527 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800528
529 if (!(status_err & IXGBE_RXD_STAT_L4CS))
530 return;
531
532 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
533 adapter->hw_csum_rx_error++;
534 return;
535 }
536
Auke Kok9a799d72007-09-15 14:07:45 -0700537 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800538 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -0700539 adapter->hw_csum_rx_good++;
540}
541
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000542static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
543 struct ixgbe_ring *rx_ring, u32 val)
544{
545 /*
546 * Force memory writes to complete before letting h/w
547 * know there are new descriptors to fetch. (Only
548 * applicable for weak-ordered memory model archs,
549 * such as IA-64).
550 */
551 wmb();
552 IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
553}
554
Auke Kok9a799d72007-09-15 14:07:45 -0700555/**
556 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
557 * @adapter: address of board private structure
558 **/
559static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700560 struct ixgbe_ring *rx_ring,
561 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700562{
Auke Kok9a799d72007-09-15 14:07:45 -0700563 struct pci_dev *pdev = adapter->pdev;
564 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700565 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700566 unsigned int i;
Auke Kok9a799d72007-09-15 14:07:45 -0700567
568 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700569 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700570
571 while (cleaned_count--) {
572 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
573
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700574 if (!bi->page_dma &&
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700575 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700576 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700577 bi->page = alloc_page(GFP_ATOMIC);
578 if (!bi->page) {
579 adapter->alloc_rx_page_failed++;
580 goto no_buffers;
581 }
582 bi->page_offset = 0;
583 } else {
584 /* use a half page if we're re-using */
585 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700586 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700587
588 bi->page_dma = pci_map_page(pdev, bi->page,
589 bi->page_offset,
590 (PAGE_SIZE / 2),
591 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700592 }
593
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700594 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800595 struct sk_buff *skb;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000596 skb = netdev_alloc_skb(adapter->netdev,
597 (rx_ring->rx_buf_len +
598 NET_IP_ALIGN));
Auke Kok9a799d72007-09-15 14:07:45 -0700599
600 if (!skb) {
601 adapter->alloc_rx_buff_failed++;
602 goto no_buffers;
603 }
604
605 /*
606 * Make buffer alignment 2 beyond a 16 byte boundary
607 * this will result in a 16 byte aligned IP header after
608 * the 14 byte MAC header is removed
609 */
610 skb_reserve(skb, NET_IP_ALIGN);
611
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700612 bi->skb = skb;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000613 bi->dma = pci_map_single(pdev, skb->data,
614 rx_ring->rx_buf_len,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700615 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700616 }
617 /* Refresh the desc even if buffer_addrs didn't change because
618 * each write-back erases this info. */
619 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700620 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
621 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700622 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700623 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700624 }
625
626 i++;
627 if (i == rx_ring->count)
628 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700629 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700630 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700631
Auke Kok9a799d72007-09-15 14:07:45 -0700632no_buffers:
633 if (rx_ring->next_to_use != i) {
634 rx_ring->next_to_use = i;
635 if (i-- == 0)
636 i = (rx_ring->count - 1);
637
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000638 ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700639 }
640}
641
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700642static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
643{
644 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
645}
646
647static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
648{
649 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
650}
651
Alexander Duyckf8212f92009-04-27 22:42:37 +0000652static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
653{
654 return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
655 IXGBE_RXDADV_RSCCNT_MASK) >>
656 IXGBE_RXDADV_RSCCNT_SHIFT;
657}
658
659/**
660 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
661 * @skb: pointer to the last skb in the rsc queue
662 *
663 * This function changes a queue full of hw rsc buffers into a completed
664 * packet. It uses the ->prev pointers to find the first packet and then
665 * turns it into the frag list owner.
666 **/
667static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
668{
669 unsigned int frag_list_size = 0;
670
671 while (skb->prev) {
672 struct sk_buff *prev = skb->prev;
673 frag_list_size += skb->len;
674 skb->prev = NULL;
675 skb = prev;
676 }
677
678 skb_shinfo(skb)->frag_list = skb->next;
679 skb->next = NULL;
680 skb->len += frag_list_size;
681 skb->data_len += frag_list_size;
682 skb->truesize += frag_list_size;
683 return skb;
684}
685
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800686static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700687 struct ixgbe_ring *rx_ring,
688 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700689{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800690 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -0700691 struct pci_dev *pdev = adapter->pdev;
692 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
693 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
694 struct sk_buff *skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000695 unsigned int i, rsc_count = 0;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700696 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700697 u16 hdr_info;
698 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700699 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800700 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +0000701#ifdef IXGBE_FCOE
702 int ddp_bytes = 0;
703#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -0700704
705 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700706 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
707 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
708 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700709
710 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700711 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700712 if (*work_done >= work_to_do)
713 break;
714 (*work_done)++;
715
716 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700717 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
718 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700719 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700720 if (hdr_info & IXGBE_RXDADV_SPH)
721 adapter->rx_hdr_split++;
722 if (len > IXGBE_RX_HDR_SIZE)
723 len = IXGBE_RX_HDR_SIZE;
724 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700725 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700726 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700727 }
Auke Kok9a799d72007-09-15 14:07:45 -0700728
729 cleaned = true;
730 skb = rx_buffer_info->skb;
731 prefetch(skb->data - NET_IP_ALIGN);
732 rx_buffer_info->skb = NULL;
733
Alexander Duyck21fa4e62009-06-04 15:59:49 +0000734 if (rx_buffer_info->dma) {
Auke Kok9a799d72007-09-15 14:07:45 -0700735 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800736 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700737 PCI_DMA_FROMDEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000738 rx_buffer_info->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700739 skb_put(skb, len);
740 }
741
742 if (upper_len) {
743 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700744 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700745 rx_buffer_info->page_dma = 0;
746 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700747 rx_buffer_info->page,
748 rx_buffer_info->page_offset,
749 upper_len);
750
751 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
752 (page_count(rx_buffer_info->page) != 1))
753 rx_buffer_info->page = NULL;
754 else
755 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700756
757 skb->len += upper_len;
758 skb->data_len += upper_len;
759 skb->truesize += upper_len;
760 }
761
762 i++;
763 if (i == rx_ring->count)
764 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700765
766 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
767 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -0700768 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000769
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +0000770 if (adapter->flags & IXGBE_FLAG2_RSC_CAPABLE)
Alexander Duyckf8212f92009-04-27 22:42:37 +0000771 rsc_count = ixgbe_get_rsc_count(rx_desc);
772
773 if (rsc_count) {
774 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
775 IXGBE_RXDADV_NEXTP_SHIFT;
776 next_buffer = &rx_ring->rx_buffer_info[nextp];
777 rx_ring->rsc_count += (rsc_count - 1);
778 } else {
779 next_buffer = &rx_ring->rx_buffer_info[i];
780 }
781
Auke Kok9a799d72007-09-15 14:07:45 -0700782 if (staterr & IXGBE_RXD_STAT_EOP) {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000783 if (skb->prev)
784 skb = ixgbe_transform_rsc_queue(skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700785 rx_ring->stats.packets++;
786 rx_ring->stats.bytes += skb->len;
787 } else {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000788 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
789 rx_buffer_info->skb = next_buffer->skb;
790 rx_buffer_info->dma = next_buffer->dma;
791 next_buffer->skb = skb;
792 next_buffer->dma = 0;
793 } else {
794 skb->next = next_buffer->skb;
795 skb->next->prev = skb;
796 }
Auke Kok9a799d72007-09-15 14:07:45 -0700797 adapter->non_eop_descs++;
798 goto next_desc;
799 }
800
801 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
802 dev_kfree_skb_irq(skb);
803 goto next_desc;
804 }
805
806 ixgbe_rx_checksum(adapter, staterr, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800807
808 /* probably a little skewed due to removing CRC */
809 total_rx_bytes += skb->len;
810 total_rx_packets++;
811
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700812 skb->protocol = eth_type_trans(skb, adapter->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +0000813#ifdef IXGBE_FCOE
814 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +0000815 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
816 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
817 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +0000818 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +0000819 }
Yi Zou332d4a72009-05-13 13:11:53 +0000820#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000821 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700822
823next_desc:
824 rx_desc->wb.upper.status_error = 0;
825
826 /* return some buffers to hardware, one at a time is too slow */
827 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
828 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
829 cleaned_count = 0;
830 }
831
832 /* use prefetched values */
833 rx_desc = next_rxd;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000834 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700835
836 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700837 }
838
Auke Kok9a799d72007-09-15 14:07:45 -0700839 rx_ring->next_to_clean = i;
840 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
841
842 if (cleaned_count)
843 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
844
Yi Zou3d8fd382009-06-08 14:38:44 +0000845#ifdef IXGBE_FCOE
846 /* include DDPed FCoE data */
847 if (ddp_bytes > 0) {
848 unsigned int mss;
849
850 mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) -
851 sizeof(struct fc_frame_header) -
852 sizeof(struct fcoe_crc_eof);
853 if (mss > 512)
854 mss &= ~511;
855 total_rx_bytes += ddp_bytes;
856 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
857 }
858#endif /* IXGBE_FCOE */
859
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800860 rx_ring->total_packets += total_rx_packets;
861 rx_ring->total_bytes += total_rx_bytes;
862 adapter->net_stats.rx_bytes += total_rx_bytes;
863 adapter->net_stats.rx_packets += total_rx_packets;
864
Auke Kok9a799d72007-09-15 14:07:45 -0700865 return cleaned;
866}
867
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800868static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700869/**
870 * ixgbe_configure_msix - Configure MSI-X hardware
871 * @adapter: board private structure
872 *
873 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
874 * interrupts.
875 **/
876static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
877{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800878 struct ixgbe_q_vector *q_vector;
879 int i, j, q_vectors, v_idx, r_idx;
880 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700881
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800882 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
883
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000884 /*
885 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800886 * corresponding register.
887 */
888 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +0000889 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800890 /* XXX for_each_bit(...) */
891 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700892 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800893
894 for (i = 0; i < q_vector->rxr_count; i++) {
895 j = adapter->rx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000896 ixgbe_set_ivar(adapter, 0, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800897 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700898 adapter->num_rx_queues,
899 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800900 }
901 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700902 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800903
904 for (i = 0; i < q_vector->txr_count; i++) {
905 j = adapter->tx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000906 ixgbe_set_ivar(adapter, 1, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800907 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700908 adapter->num_tx_queues,
909 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800910 }
911
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700912 /* if this is a tx only vector halve the interrupt rate */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800913 if (q_vector->txr_count && !q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700914 q_vector->eitr = (adapter->eitr_param >> 1);
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000915 else if (q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700916 /* rx only */
917 q_vector->eitr = adapter->eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800918
Alexander Duyckfe49f042009-06-04 16:00:09 +0000919 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -0700920 }
921
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000922 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
923 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
924 v_idx);
925 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
926 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800927 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -0700928
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700929 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800930 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700931 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800932 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -0700933}
934
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800935enum latency_range {
936 lowest_latency = 0,
937 low_latency = 1,
938 bulk_latency = 2,
939 latency_invalid = 255
940};
941
942/**
943 * ixgbe_update_itr - update the dynamic ITR value based on statistics
944 * @adapter: pointer to adapter
945 * @eitr: eitr setting (ints per sec) to give last timeslice
946 * @itr_setting: current throttle rate in ints/second
947 * @packets: the number of packets during this measurement interval
948 * @bytes: the number of bytes during this measurement interval
949 *
950 * Stores a new ITR value based on packets and byte
951 * counts during the last interrupt. The advantage of per interrupt
952 * computation is faster updates and more accurate ITR for the current
953 * traffic pattern. Constants in this function were computed
954 * based on theoretical maximum wire speed and thresholds were set based
955 * on testing data as well as attempting to minimize response time
956 * while increasing bulk throughput.
957 * this functionality is controlled by the InterruptThrottleRate module
958 * parameter (see ixgbe_param.c)
959 **/
960static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700961 u32 eitr, u8 itr_setting,
962 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800963{
964 unsigned int retval = itr_setting;
965 u32 timepassed_us;
966 u64 bytes_perint;
967
968 if (packets == 0)
969 goto update_itr_done;
970
971
972 /* simple throttlerate management
973 * 0-20MB/s lowest (100000 ints/s)
974 * 20-100MB/s low (20000 ints/s)
975 * 100-1249MB/s bulk (8000 ints/s)
976 */
977 /* what was last interrupt timeslice? */
978 timepassed_us = 1000000/eitr;
979 bytes_perint = bytes / timepassed_us; /* bytes/usec */
980
981 switch (itr_setting) {
982 case lowest_latency:
983 if (bytes_perint > adapter->eitr_low)
984 retval = low_latency;
985 break;
986 case low_latency:
987 if (bytes_perint > adapter->eitr_high)
988 retval = bulk_latency;
989 else if (bytes_perint <= adapter->eitr_low)
990 retval = lowest_latency;
991 break;
992 case bulk_latency:
993 if (bytes_perint <= adapter->eitr_high)
994 retval = low_latency;
995 break;
996 }
997
998update_itr_done:
999 return retval;
1000}
1001
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001002/**
1003 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001004 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001005 *
1006 * This function is made to be called by ethtool and by the driver
1007 * when it needs to update EITR registers at runtime. Hardware
1008 * specific quirks/differences are taken care of here.
1009 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001010void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001011{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001012 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001013 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001014 int v_idx = q_vector->v_idx;
1015 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1016
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001017 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1018 /* must write high and low 16 bits to reset counter */
1019 itr_reg |= (itr_reg << 16);
1020 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1021 /*
1022 * set the WDIS bit to not clear the timer bits and cause an
1023 * immediate assertion of the interrupt
1024 */
1025 itr_reg |= IXGBE_EITR_CNT_WDIS;
1026 }
1027 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1028}
1029
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001030static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1031{
1032 struct ixgbe_adapter *adapter = q_vector->adapter;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001033 u32 new_itr;
1034 u8 current_itr, ret_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001035 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001036 struct ixgbe_ring *rx_ring, *tx_ring;
1037
1038 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1039 for (i = 0; i < q_vector->txr_count; i++) {
1040 tx_ring = &(adapter->tx_ring[r_idx]);
1041 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001042 q_vector->tx_itr,
1043 tx_ring->total_packets,
1044 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001045 /* if the result for this queue would decrease interrupt
1046 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001047 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001048 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001049 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001050 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001051 }
1052
1053 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1054 for (i = 0; i < q_vector->rxr_count; i++) {
1055 rx_ring = &(adapter->rx_ring[r_idx]);
1056 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001057 q_vector->rx_itr,
1058 rx_ring->total_packets,
1059 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001060 /* if the result for this queue would decrease interrupt
1061 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001062 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001063 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001064 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001065 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001066 }
1067
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001068 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001069
1070 switch (current_itr) {
1071 /* counts and packets in update_itr are dependent on these numbers */
1072 case lowest_latency:
1073 new_itr = 100000;
1074 break;
1075 case low_latency:
1076 new_itr = 20000; /* aka hwitr = ~200 */
1077 break;
1078 case bulk_latency:
1079 default:
1080 new_itr = 8000;
1081 break;
1082 }
1083
1084 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001085 /* do an exponential smoothing */
1086 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001087
1088 /* save the algorithm value here, not the smoothed one */
1089 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001090
1091 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001092 }
1093
1094 return;
1095}
1096
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001097static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1098{
1099 struct ixgbe_hw *hw = &adapter->hw;
1100
1101 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1102 (eicr & IXGBE_EICR_GPI_SDP1)) {
1103 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
1104 /* write to clear the interrupt */
1105 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1106 }
1107}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001108
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001109static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1110{
1111 struct ixgbe_hw *hw = &adapter->hw;
1112
1113 if (eicr & IXGBE_EICR_GPI_SDP1) {
1114 /* Clear the interrupt */
1115 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1116 schedule_work(&adapter->multispeed_fiber_task);
1117 } else if (eicr & IXGBE_EICR_GPI_SDP2) {
1118 /* Clear the interrupt */
1119 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1120 schedule_work(&adapter->sfp_config_module_task);
1121 } else {
1122 /* Interrupt isn't for us... */
1123 return;
1124 }
1125}
1126
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001127static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1128{
1129 struct ixgbe_hw *hw = &adapter->hw;
1130
1131 adapter->lsc_int++;
1132 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1133 adapter->link_check_timeout = jiffies;
1134 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1135 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1136 schedule_work(&adapter->watchdog_task);
1137 }
1138}
1139
Auke Kok9a799d72007-09-15 14:07:45 -07001140static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1141{
1142 struct net_device *netdev = data;
1143 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1144 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001145 u32 eicr;
1146
1147 /*
1148 * Workaround for Silicon errata. Use clear-by-write instead
1149 * of clear-by-read. Reading with EICS will return the
1150 * interrupt causes without clearing, which later be done
1151 * with the write to EICR.
1152 */
1153 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1154 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001155
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001156 if (eicr & IXGBE_EICR_LSC)
1157 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001158
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001159 if (hw->mac.type == ixgbe_mac_82598EB)
1160 ixgbe_check_fan_failure(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001161
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001162 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001163 ixgbe_check_sfp_event(adapter, eicr);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001164
1165 /* Handle Flow Director Full threshold interrupt */
1166 if (eicr & IXGBE_EICR_FLOW_DIR) {
1167 int i;
1168 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
1169 /* Disable transmits before FDIR Re-initialization */
1170 netif_tx_stop_all_queues(netdev);
1171 for (i = 0; i < adapter->num_tx_queues; i++) {
1172 struct ixgbe_ring *tx_ring =
1173 &adapter->tx_ring[i];
1174 if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE,
1175 &tx_ring->reinit_state))
1176 schedule_work(&adapter->fdir_reinit_task);
1177 }
1178 }
1179 }
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001180 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1181 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -07001182
1183 return IRQ_HANDLED;
1184}
1185
Alexander Duyckfe49f042009-06-04 16:00:09 +00001186static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1187 u64 qmask)
1188{
1189 u32 mask;
1190
1191 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1192 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1193 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1194 } else {
1195 mask = (qmask & 0xFFFFFFFF);
1196 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
1197 mask = (qmask >> 32);
1198 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
1199 }
1200 /* skip the flush */
1201}
1202
1203static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
1204 u64 qmask)
1205{
1206 u32 mask;
1207
1208 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1209 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1210 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
1211 } else {
1212 mask = (qmask & 0xFFFFFFFF);
1213 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
1214 mask = (qmask >> 32);
1215 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
1216 }
1217 /* skip the flush */
1218}
1219
Auke Kok9a799d72007-09-15 14:07:45 -07001220static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1221{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001222 struct ixgbe_q_vector *q_vector = data;
1223 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001224 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001225 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001226
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001227 if (!q_vector->txr_count)
1228 return IRQ_HANDLED;
1229
1230 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1231 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001232 tx_ring = &(adapter->tx_ring[r_idx]);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001233 tx_ring->total_bytes = 0;
1234 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001235 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001236 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001237 }
1238
Alexander Duyck91281fd2009-06-04 16:00:27 +00001239 /* disable interrupts on this vector only */
1240 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1241 napi_schedule(&q_vector->napi);
1242
Auke Kok9a799d72007-09-15 14:07:45 -07001243 return IRQ_HANDLED;
1244}
1245
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001246/**
1247 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1248 * @irq: unused
1249 * @data: pointer to our q_vector struct for this interrupt vector
1250 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001251static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1252{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001253 struct ixgbe_q_vector *q_vector = data;
1254 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001255 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001256 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001257 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001258
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001259 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001260 for (i = 0; i < q_vector->rxr_count; i++) {
1261 rx_ring = &(adapter->rx_ring[r_idx]);
1262 rx_ring->total_bytes = 0;
1263 rx_ring->total_packets = 0;
1264 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1265 r_idx + 1);
1266 }
1267
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001268 if (!q_vector->rxr_count)
1269 return IRQ_HANDLED;
1270
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001271 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001272 rx_ring = &(adapter->rx_ring[r_idx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001273 /* disable interrupts on this vector only */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001274 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
Ben Hutchings288379f2009-01-19 16:43:59 -08001275 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001276
Auke Kok9a799d72007-09-15 14:07:45 -07001277 return IRQ_HANDLED;
1278}
1279
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001280static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1281{
Alexander Duyck91281fd2009-06-04 16:00:27 +00001282 struct ixgbe_q_vector *q_vector = data;
1283 struct ixgbe_adapter *adapter = q_vector->adapter;
1284 struct ixgbe_ring *ring;
1285 int r_idx;
1286 int i;
1287
1288 if (!q_vector->txr_count && !q_vector->rxr_count)
1289 return IRQ_HANDLED;
1290
1291 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1292 for (i = 0; i < q_vector->txr_count; i++) {
1293 ring = &(adapter->tx_ring[r_idx]);
1294 ring->total_bytes = 0;
1295 ring->total_packets = 0;
1296 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1297 r_idx + 1);
1298 }
1299
1300 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1301 for (i = 0; i < q_vector->rxr_count; i++) {
1302 ring = &(adapter->rx_ring[r_idx]);
1303 ring->total_bytes = 0;
1304 ring->total_packets = 0;
1305 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1306 r_idx + 1);
1307 }
1308
1309 /* disable interrupts on this vector only */
1310 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1311 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001312
1313 return IRQ_HANDLED;
1314}
1315
1316/**
1317 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1318 * @napi: napi struct with our devices info in it
1319 * @budget: amount of work driver is allowed to do this pass, in packets
1320 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001321 * This function is optimized for cleaning one queue only on a single
1322 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001323 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001324static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1325{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001326 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001327 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001328 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001329 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001330 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001331 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001332
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001333 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001334 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001335#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001336 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001337 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001338#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001339
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001340 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001341
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001342 /* If all Rx work done, exit the polling mode */
1343 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001344 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001345 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001346 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001347 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001348 ixgbe_irq_enable_queues(adapter,
1349 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07001350 }
1351
1352 return work_done;
1353}
1354
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001355/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00001356 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001357 * @napi: napi struct with our devices info in it
1358 * @budget: amount of work driver is allowed to do this pass, in packets
1359 *
1360 * This function will clean more than one rx queue associated with a
1361 * q_vector.
1362 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00001363static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001364{
1365 struct ixgbe_q_vector *q_vector =
1366 container_of(napi, struct ixgbe_q_vector, napi);
1367 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001368 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001369 int work_done = 0, i;
1370 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001371 bool tx_clean_complete = true;
1372
1373 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1374 for (i = 0; i < q_vector->txr_count; i++) {
1375 ring = &(adapter->tx_ring[r_idx]);
1376#ifdef CONFIG_IXGBE_DCA
1377 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1378 ixgbe_update_tx_dca(adapter, ring);
1379#endif
1380 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
1381 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1382 r_idx + 1);
1383 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001384
1385 /* attempt to distribute budget to each queue fairly, but don't allow
1386 * the budget to go below 1 because we'll exit polling */
1387 budget /= (q_vector->rxr_count ?: 1);
1388 budget = max(budget, 1);
1389 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1390 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck91281fd2009-06-04 16:00:27 +00001391 ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001392#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001393 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck91281fd2009-06-04 16:00:27 +00001394 ixgbe_update_rx_dca(adapter, ring);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001395#endif
Alexander Duyck91281fd2009-06-04 16:00:27 +00001396 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001397 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1398 r_idx + 1);
1399 }
1400
1401 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck91281fd2009-06-04 16:00:27 +00001402 ring = &(adapter->rx_ring[r_idx]);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001403 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001404 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001405 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001406 if (adapter->itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001407 ixgbe_set_itr_msix(q_vector);
1408 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001409 ixgbe_irq_enable_queues(adapter,
1410 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001411 return 0;
1412 }
1413
1414 return work_done;
1415}
Alexander Duyck91281fd2009-06-04 16:00:27 +00001416
1417/**
1418 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
1419 * @napi: napi struct with our devices info in it
1420 * @budget: amount of work driver is allowed to do this pass, in packets
1421 *
1422 * This function is optimized for cleaning one queue only on a single
1423 * q_vector!!!
1424 **/
1425static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
1426{
1427 struct ixgbe_q_vector *q_vector =
1428 container_of(napi, struct ixgbe_q_vector, napi);
1429 struct ixgbe_adapter *adapter = q_vector->adapter;
1430 struct ixgbe_ring *tx_ring = NULL;
1431 int work_done = 0;
1432 long r_idx;
1433
1434 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1435 tx_ring = &(adapter->tx_ring[r_idx]);
1436#ifdef CONFIG_IXGBE_DCA
1437 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1438 ixgbe_update_tx_dca(adapter, tx_ring);
1439#endif
1440
1441 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
1442 work_done = budget;
1443
1444 /* If all Rx work done, exit the polling mode */
1445 if (work_done < budget) {
1446 napi_complete(napi);
1447 if (adapter->itr_setting & 1)
1448 ixgbe_set_itr_msix(q_vector);
1449 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1450 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
1451 }
1452
1453 return work_done;
1454}
1455
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001456static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001457 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001458{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001459 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1460
1461 set_bit(r_idx, q_vector->rxr_idx);
1462 q_vector->rxr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001463}
Auke Kok9a799d72007-09-15 14:07:45 -07001464
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001465static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001466 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001467{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001468 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1469
1470 set_bit(t_idx, q_vector->txr_idx);
1471 q_vector->txr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001472}
Auke Kok9a799d72007-09-15 14:07:45 -07001473
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001474/**
1475 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1476 * @adapter: board private structure to initialize
1477 * @vectors: allotted vector count for descriptor rings
1478 *
1479 * This function maps descriptor rings to the queue-specific vectors
1480 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1481 * one vector per ring/queue, but on a constrained vector budget, we
1482 * group the rings as "efficiently" as possible. You would add new
1483 * mapping configurations in here.
1484 **/
1485static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001486 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001487{
1488 int v_start = 0;
1489 int rxr_idx = 0, txr_idx = 0;
1490 int rxr_remaining = adapter->num_rx_queues;
1491 int txr_remaining = adapter->num_tx_queues;
1492 int i, j;
1493 int rqpv, tqpv;
1494 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001495
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001496 /* No mapping required if MSI-X is disabled. */
1497 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001498 goto out;
1499
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001500 /*
1501 * The ideal configuration...
1502 * We have enough vectors to map one per queue.
1503 */
1504 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1505 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1506 map_vector_to_rxq(adapter, v_start, rxr_idx);
1507
1508 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1509 map_vector_to_txq(adapter, v_start, txr_idx);
1510
1511 goto out;
1512 }
1513
1514 /*
1515 * If we don't have enough vectors for a 1-to-1
1516 * mapping, we'll have to group them so there are
1517 * multiple queues per vector.
1518 */
1519 /* Re-adjusting *qpv takes care of the remainder. */
1520 for (i = v_start; i < vectors; i++) {
1521 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1522 for (j = 0; j < rqpv; j++) {
1523 map_vector_to_rxq(adapter, i, rxr_idx);
1524 rxr_idx++;
1525 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001526 }
Auke Kok9a799d72007-09-15 14:07:45 -07001527 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001528 for (i = v_start; i < vectors; i++) {
1529 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1530 for (j = 0; j < tqpv; j++) {
1531 map_vector_to_txq(adapter, i, txr_idx);
1532 txr_idx++;
1533 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001534 }
Auke Kok9a799d72007-09-15 14:07:45 -07001535 }
1536
Auke Kok9a799d72007-09-15 14:07:45 -07001537out:
Auke Kok9a799d72007-09-15 14:07:45 -07001538 return err;
1539}
1540
1541/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001542 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1543 * @adapter: board private structure
1544 *
1545 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1546 * interrupts from the kernel.
1547 **/
1548static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1549{
1550 struct net_device *netdev = adapter->netdev;
1551 irqreturn_t (*handler)(int, void *);
1552 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001553 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001554
1555 /* Decrement for Other and TCP Timer vectors */
1556 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1557
1558 /* Map the Tx/Rx rings to the vectors we were allotted. */
1559 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1560 if (err)
1561 goto out;
1562
1563#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001564 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1565 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001566 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001567 handler = SET_HANDLER(adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001568
1569 if(handler == &ixgbe_msix_clean_rx) {
1570 sprintf(adapter->name[vector], "%s-%s-%d",
1571 netdev->name, "rx", ri++);
1572 }
1573 else if(handler == &ixgbe_msix_clean_tx) {
1574 sprintf(adapter->name[vector], "%s-%s-%d",
1575 netdev->name, "tx", ti++);
1576 }
1577 else
1578 sprintf(adapter->name[vector], "%s-%s-%d",
1579 netdev->name, "TxRx", vector);
1580
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001581 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001582 handler, 0, adapter->name[vector],
Alexander Duyck7a921c92009-05-06 10:43:28 +00001583 adapter->q_vector[vector]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001584 if (err) {
1585 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001586 "request_irq failed for MSIX interrupt "
1587 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001588 goto free_queue_irqs;
1589 }
1590 }
1591
1592 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1593 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001594 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001595 if (err) {
1596 DPRINTK(PROBE, ERR,
1597 "request_irq for msix_lsc failed: %d\n", err);
1598 goto free_queue_irqs;
1599 }
1600
1601 return 0;
1602
1603free_queue_irqs:
1604 for (i = vector - 1; i >= 0; i--)
1605 free_irq(adapter->msix_entries[--vector].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001606 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001607 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1608 pci_disable_msix(adapter->pdev);
1609 kfree(adapter->msix_entries);
1610 adapter->msix_entries = NULL;
1611out:
1612 return err;
1613}
1614
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001615static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1616{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001617 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001618 u8 current_itr;
1619 u32 new_itr = q_vector->eitr;
1620 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1621 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1622
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001623 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001624 q_vector->tx_itr,
1625 tx_ring->total_packets,
1626 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001627 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001628 q_vector->rx_itr,
1629 rx_ring->total_packets,
1630 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001631
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001632 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001633
1634 switch (current_itr) {
1635 /* counts and packets in update_itr are dependent on these numbers */
1636 case lowest_latency:
1637 new_itr = 100000;
1638 break;
1639 case low_latency:
1640 new_itr = 20000; /* aka hwitr = ~200 */
1641 break;
1642 case bulk_latency:
1643 new_itr = 8000;
1644 break;
1645 default:
1646 break;
1647 }
1648
1649 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001650 /* do an exponential smoothing */
1651 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001652
1653 /* save the algorithm value here, not the smoothed one */
1654 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001655
1656 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001657 }
1658
1659 return;
1660}
1661
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001662/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001663 * ixgbe_irq_enable - Enable default interrupt generation settings
1664 * @adapter: board private structure
1665 **/
1666static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1667{
1668 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00001669
1670 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
David S. Miller6ab33d52008-11-20 16:44:00 -08001671 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1672 mask |= IXGBE_EIMS_GPI_SDP1;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001673 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001674 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001675 mask |= IXGBE_EIMS_GPI_SDP1;
1676 mask |= IXGBE_EIMS_GPI_SDP2;
1677 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001678 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
1679 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
1680 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001681
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001682 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Nelson, Shannon835462f2009-04-27 22:42:54 +00001683 ixgbe_irq_enable_queues(adapter, ~0);
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001684 IXGBE_WRITE_FLUSH(&adapter->hw);
1685}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001686
1687/**
1688 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001689 * @irq: interrupt number
1690 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001691 **/
1692static irqreturn_t ixgbe_intr(int irq, void *data)
1693{
1694 struct net_device *netdev = data;
1695 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1696 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001697 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07001698 u32 eicr;
1699
Don Skidmore54037502009-02-21 15:42:56 -08001700 /*
1701 * Workaround for silicon errata. Mask the interrupts
1702 * before the read of EICR.
1703 */
1704 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1705
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001706 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1707 * therefore no explict interrupt disable is necessary */
1708 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001709 if (!eicr) {
1710 /* shared interrupt alert!
1711 * make sure interrupts are enabled because the read will
1712 * have disabled interrupts due to EIAM */
1713 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001714 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001715 }
Auke Kok9a799d72007-09-15 14:07:45 -07001716
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001717 if (eicr & IXGBE_EICR_LSC)
1718 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001719
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001720 if (hw->mac.type == ixgbe_mac_82599EB)
1721 ixgbe_check_sfp_event(adapter, eicr);
1722
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001723 ixgbe_check_fan_failure(adapter, eicr);
1724
Alexander Duyck7a921c92009-05-06 10:43:28 +00001725 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001726 adapter->tx_ring[0].total_packets = 0;
1727 adapter->tx_ring[0].total_bytes = 0;
1728 adapter->rx_ring[0].total_packets = 0;
1729 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001730 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00001731 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07001732 }
1733
1734 return IRQ_HANDLED;
1735}
1736
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001737static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1738{
1739 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1740
1741 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001742 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001743 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1744 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1745 q_vector->rxr_count = 0;
1746 q_vector->txr_count = 0;
1747 }
1748}
1749
Auke Kok9a799d72007-09-15 14:07:45 -07001750/**
1751 * ixgbe_request_irq - initialize interrupts
1752 * @adapter: board private structure
1753 *
1754 * Attempts to configure interrupts using the best available
1755 * capabilities of the hardware and kernel.
1756 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001757static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001758{
1759 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001760 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001761
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001762 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1763 err = ixgbe_request_msix_irqs(adapter);
1764 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1765 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001766 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001767 } else {
1768 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001769 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001770 }
1771
Auke Kok9a799d72007-09-15 14:07:45 -07001772 if (err)
1773 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1774
Auke Kok9a799d72007-09-15 14:07:45 -07001775 return err;
1776}
1777
1778static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1779{
1780 struct net_device *netdev = adapter->netdev;
1781
1782 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001783 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001784
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001785 q_vectors = adapter->num_msix_vectors;
1786
1787 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001788 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001789
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001790 i--;
1791 for (; i >= 0; i--) {
1792 free_irq(adapter->msix_entries[i].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001793 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001794 }
1795
1796 ixgbe_reset_q_vectors(adapter);
1797 } else {
1798 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001799 }
1800}
1801
1802/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001803 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1804 * @adapter: board private structure
1805 **/
1806static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1807{
Nelson, Shannon835462f2009-04-27 22:42:54 +00001808 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1809 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1810 } else {
1811 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
1812 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001813 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001814 }
1815 IXGBE_WRITE_FLUSH(&adapter->hw);
1816 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1817 int i;
1818 for (i = 0; i < adapter->num_msix_vectors; i++)
1819 synchronize_irq(adapter->msix_entries[i].vector);
1820 } else {
1821 synchronize_irq(adapter->pdev->irq);
1822 }
1823}
1824
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001825/**
Auke Kok9a799d72007-09-15 14:07:45 -07001826 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1827 *
1828 **/
1829static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1830{
Auke Kok9a799d72007-09-15 14:07:45 -07001831 struct ixgbe_hw *hw = &adapter->hw;
1832
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001833 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001834 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001835
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001836 ixgbe_set_ivar(adapter, 0, 0, 0);
1837 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001838
1839 map_vector_to_rxq(adapter, 0, 0);
1840 map_vector_to_txq(adapter, 0, 0);
1841
1842 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001843}
1844
1845/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001846 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001847 * @adapter: board private structure
1848 *
1849 * Configure the Tx unit of the MAC after a reset.
1850 **/
1851static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1852{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001853 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001854 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001855 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001856
1857 /* Setup the HW Tx Head and Tail descriptor pointers */
1858 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001859 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1860 j = ring->reg_idx;
1861 tdba = ring->dma;
1862 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001863 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Yang Hongyang284901a2009-04-06 19:01:15 -07001864 (tdba & DMA_BIT_MASK(32)));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001865 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1866 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1867 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1868 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1869 adapter->tx_ring[i].head = IXGBE_TDH(j);
1870 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1871 /* Disable Tx Head Writeback RO bit, since this hoses
1872 * bookkeeping if things aren't delivered in order.
1873 */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001874 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001875 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001876 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001877 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001878 if (hw->mac.type == ixgbe_mac_82599EB) {
1879 /* We enable 8 traffic classes, DCB only */
1880 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1881 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1882 IXGBE_MTQC_8TC_8TQ));
1883 }
Auke Kok9a799d72007-09-15 14:07:45 -07001884}
1885
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001886#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07001887
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001888static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1889{
1890 struct ixgbe_ring *rx_ring;
1891 u32 srrctl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001892 int queue0 = 0;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001893 unsigned long mask;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001894 struct ixgbe_ring_feature *feature = adapter->ring_feature;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001895
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001896 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Alexander Duyck163de422009-05-07 10:39:16 +00001897 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001898 int dcb_i = feature[RING_F_DCB].indices;
Alexander Duyck163de422009-05-07 10:39:16 +00001899 if (dcb_i == 8)
1900 queue0 = index >> 4;
1901 else if (dcb_i == 4)
1902 queue0 = index >> 5;
1903 else
1904 dev_err(&adapter->pdev->dev, "Invalid DCB "
1905 "configuration\n");
Yi Zou0331a832009-05-17 12:33:52 +00001906#ifdef IXGBE_FCOE
1907 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1908 struct ixgbe_ring_feature *f;
1909
1910 rx_ring = &adapter->rx_ring[queue0];
1911 f = &adapter->ring_feature[RING_F_FCOE];
1912 if ((queue0 == 0) && (index > rx_ring->reg_idx))
1913 queue0 = f->mask + index -
1914 rx_ring->reg_idx - 1;
1915 }
1916#endif /* IXGBE_FCOE */
Alexander Duyck163de422009-05-07 10:39:16 +00001917 } else {
1918 queue0 = index;
1919 }
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001920 } else {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001921 mask = (unsigned long) feature[RING_F_RSS].mask;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001922 queue0 = index & mask;
1923 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001924 }
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001925
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001926 rx_ring = &adapter->rx_ring[queue0];
1927
1928 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1929
1930 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1931 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1932
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001933 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1934 IXGBE_SRRCTL_BSIZEHDR_MASK;
1935
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001936 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001937#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
1938 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1939#else
1940 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1941#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001942 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001943 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001944 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
1945 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001946 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001947 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001948
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001949 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1950}
1951
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001952static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
1953{
1954 u32 mrqc = 0;
1955 int mask;
1956
1957 if (!(adapter->hw.mac.type == ixgbe_mac_82599EB))
1958 return mrqc;
1959
1960 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
1961#ifdef CONFIG_IXGBE_DCB
1962 | IXGBE_FLAG_DCB_ENABLED
1963#endif
1964 );
1965
1966 switch (mask) {
1967 case (IXGBE_FLAG_RSS_ENABLED):
1968 mrqc = IXGBE_MRQC_RSSEN;
1969 break;
1970#ifdef CONFIG_IXGBE_DCB
1971 case (IXGBE_FLAG_DCB_ENABLED):
1972 mrqc = IXGBE_MRQC_RT8TCEN;
1973 break;
1974#endif /* CONFIG_IXGBE_DCB */
1975 default:
1976 break;
1977 }
1978
1979 return mrqc;
1980}
1981
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001982/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001983 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001984 * @adapter: board private structure
1985 *
1986 * Configure the Rx unit of the MAC after a reset.
1987 **/
1988static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1989{
1990 u64 rdba;
1991 struct ixgbe_hw *hw = &adapter->hw;
1992 struct net_device *netdev = adapter->netdev;
1993 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001994 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001995 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001996 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1997 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1998 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001999 u32 fctrl, hlreg0;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002000 u32 reta = 0, mrqc = 0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002001 u32 rdrxctl;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002002 u32 rscctrl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002003 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07002004
2005 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002006 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07002007
Yi Zoueacd73f2009-05-13 13:11:06 +00002008#ifdef IXGBE_FCOE
2009 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2010 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
2011#endif /* IXGBE_FCOE */
2012
Auke Kok9a799d72007-09-15 14:07:45 -07002013 /* Set the RX buffer length according to the mode */
2014 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002015 rx_buf_len = IXGBE_RX_HDR_SIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002016 if (hw->mac.type == ixgbe_mac_82599EB) {
2017 /* PSRTYPE must be initialized in 82599 */
2018 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
2019 IXGBE_PSRTYPE_UDPHDR |
2020 IXGBE_PSRTYPE_IPV4HDR |
Yi Zoudfa12f02009-05-07 10:39:35 +00002021 IXGBE_PSRTYPE_IPV6HDR |
2022 IXGBE_PSRTYPE_L2HDR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002023 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
2024 }
Auke Kok9a799d72007-09-15 14:07:45 -07002025 } else {
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00002026 if (!(adapter->flags & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00002027 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002028 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07002029 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002030 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07002031 }
2032
2033 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
2034 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002035 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002036 fctrl |= IXGBE_FCTRL_PMCF;
Auke Kok9a799d72007-09-15 14:07:45 -07002037 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
2038
2039 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2040 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2041 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
2042 else
2043 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Yi Zou63f39bd2009-05-17 12:34:35 +00002044#ifdef IXGBE_FCOE
2045 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2046 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2047#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002048 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2049
Auke Kok9a799d72007-09-15 14:07:45 -07002050 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
2051 /* disable receives while setting up the descriptors */
2052 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2053 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
2054
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002055 /*
2056 * Setup the HW Rx Head and Tail Descriptor Pointers and
2057 * the Base and Length of the Rx Descriptor Ring
2058 */
Auke Kok9a799d72007-09-15 14:07:45 -07002059 for (i = 0; i < adapter->num_rx_queues; i++) {
2060 rdba = adapter->rx_ring[i].dma;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002061 j = adapter->rx_ring[i].reg_idx;
Yang Hongyang284901a2009-04-06 19:01:15 -07002062 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32)));
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002063 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
2064 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
2065 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
2066 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
2067 adapter->rx_ring[i].head = IXGBE_RDH(j);
2068 adapter->rx_ring[i].tail = IXGBE_RDT(j);
2069 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002070
Yi Zou63f39bd2009-05-17 12:34:35 +00002071#ifdef IXGBE_FCOE
2072 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
2073 struct ixgbe_ring_feature *f;
2074 f = &adapter->ring_feature[RING_F_FCOE];
2075 if ((rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
2076 (i >= f->mask) && (i < f->mask + f->indices))
2077 adapter->rx_ring[i].rx_buf_len =
2078 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2079 }
2080
2081#endif /* IXGBE_FCOE */
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002082 ixgbe_configure_srrctl(adapter, j);
Auke Kok9a799d72007-09-15 14:07:45 -07002083 }
2084
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002085 if (hw->mac.type == ixgbe_mac_82598EB) {
2086 /*
2087 * For VMDq support of different descriptor types or
2088 * buffer sizes through the use of multiple SRRCTL
2089 * registers, RDRXCTL.MVMEN must be set to 1
2090 *
2091 * also, the manual doesn't mention it clearly but DCA hints
2092 * will only use queue 0's tags unless this bit is set. Side
2093 * effects of setting this bit are only that SRRCTL must be
2094 * fully programmed [0..15]
2095 */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002096 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2097 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
2098 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
Alexander Duyck2f90b862008-11-20 20:52:10 -08002099 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002100
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002101 /* Program MRQC for the distribution of queues */
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002102 mrqc = ixgbe_setup_mrqc(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002103
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002104 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07002105 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002106 for (i = 0, j = 0; i < 128; i++, j++) {
2107 if (j == adapter->ring_feature[RING_F_RSS].indices)
2108 j = 0;
2109 /* reta = 4-byte sliding window of
2110 * 0x00..(indices-1)(indices-1)00..etc. */
2111 reta = (reta << 8) | (j * 0x11);
2112 if ((i & 3) == 3)
2113 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07002114 }
2115
2116 /* Fill out hash function seeds */
2117 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002118 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002119
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002120 if (hw->mac.type == ixgbe_mac_82598EB)
2121 mrqc |= IXGBE_MRQC_RSSEN;
Auke Kok9a799d72007-09-15 14:07:45 -07002122 /* Perform hash on these packet types */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002123 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2124 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2125 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
2126 | IXGBE_MRQC_RSS_FIELD_IPV6
2127 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
2128 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07002129 }
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002130 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002131
2132 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2133
2134 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
2135 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
2136 /* Disable indicating checksum in descriptor, enables
2137 * RSS hash */
2138 rxcsum |= IXGBE_RXCSUM_PCSD;
2139 }
2140 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
2141 /* Enable IPv4 payload checksum for UDP fragments
2142 * if PCSD is not set */
2143 rxcsum |= IXGBE_RXCSUM_IPPCSE;
2144 }
2145
2146 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002147
2148 if (hw->mac.type == ixgbe_mac_82599EB) {
2149 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2150 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002151 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002152 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
2153 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002154
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00002155 if (adapter->flags & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002156 /* Enable 82599 HW-RSC */
2157 for (i = 0; i < adapter->num_rx_queues; i++) {
2158 j = adapter->rx_ring[i].reg_idx;
2159 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j));
2160 rscctrl |= IXGBE_RSCCTL_RSCEN;
2161 /*
Alexander Duycke76678d2009-05-17 20:57:47 +00002162 * we must limit the number of descriptors so that the
2163 * total size of max desc * buf_len is not greater
2164 * than 65535
Alexander Duyckf8212f92009-04-27 22:42:37 +00002165 */
Alexander Duycke76678d2009-05-17 20:57:47 +00002166 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
2167#if (MAX_SKB_FRAGS > 16)
2168 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2169#elif (MAX_SKB_FRAGS > 8)
Alexander Duyckf8212f92009-04-27 22:42:37 +00002170 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Alexander Duycke76678d2009-05-17 20:57:47 +00002171#elif (MAX_SKB_FRAGS > 4)
2172 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002173#else
Alexander Duycke76678d2009-05-17 20:57:47 +00002174 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002175#endif
Alexander Duycke76678d2009-05-17 20:57:47 +00002176 } else {
2177 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2178 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2179 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2180 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2181 else
2182 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2183 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002184 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl);
2185 }
2186 /* Disable RSC for ACK packets */
2187 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
2188 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
2189 }
Auke Kok9a799d72007-09-15 14:07:45 -07002190}
2191
Auke Kok9a799d72007-09-15 14:07:45 -07002192static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2193{
2194 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002195 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002196
2197 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002198 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002199}
2200
2201static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2202{
2203 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002204 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002205
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002206 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2207 ixgbe_irq_disable(adapter);
2208
Auke Kok9a799d72007-09-15 14:07:45 -07002209 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002210
2211 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2212 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002213
2214 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002215 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07002216}
2217
Don Skidmore068c89b2009-01-19 16:54:36 -08002218static void ixgbe_vlan_rx_register(struct net_device *netdev,
2219 struct vlan_group *grp)
2220{
2221 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2222 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002223 int i, j;
Don Skidmore068c89b2009-01-19 16:54:36 -08002224
2225 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2226 ixgbe_irq_disable(adapter);
2227 adapter->vlgrp = grp;
2228
2229 /*
2230 * For a DCB driver, always enable VLAN tag stripping so we can
2231 * still receive traffic from a DCB-enabled host even if we're
2232 * not in DCB mode.
2233 */
2234 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002235 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
2236 ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
Don Skidmore068c89b2009-01-19 16:54:36 -08002237 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2238 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002239 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
2240 ctrl |= IXGBE_VLNCTRL_VFE;
2241 /* enable VLAN tag insert/strip */
2242 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
2243 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2244 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
2245 for (i = 0; i < adapter->num_rx_queues; i++) {
2246 j = adapter->rx_ring[i].reg_idx;
2247 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
2248 ctrl |= IXGBE_RXDCTL_VME;
2249 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
2250 }
Don Skidmore068c89b2009-01-19 16:54:36 -08002251 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002252 ixgbe_vlan_rx_add_vid(netdev, 0);
Don Skidmore068c89b2009-01-19 16:54:36 -08002253
2254 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2255 ixgbe_irq_enable(adapter);
2256}
2257
Auke Kok9a799d72007-09-15 14:07:45 -07002258static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
2259{
2260 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2261
2262 if (adapter->vlgrp) {
2263 u16 vid;
2264 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2265 if (!vlan_group_get_device(adapter->vlgrp, vid))
2266 continue;
2267 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
2268 }
2269 }
2270}
2271
Christopher Leech2c5645c2008-08-26 04:27:02 -07002272static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
2273{
2274 struct dev_mc_list *mc_ptr;
2275 u8 *addr = *mc_addr_ptr;
2276 *vmdq = 0;
2277
2278 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
2279 if (mc_ptr->next)
2280 *mc_addr_ptr = mc_ptr->next->dmi_addr;
2281 else
2282 *mc_addr_ptr = NULL;
2283
2284 return addr;
2285}
2286
Auke Kok9a799d72007-09-15 14:07:45 -07002287/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07002288 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07002289 * @netdev: network interface device structure
2290 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07002291 * The set_rx_method entry point is called whenever the unicast/multicast
2292 * address list or the network interface flags are updated. This routine is
2293 * responsible for configuring the hardware for proper unicast, multicast and
2294 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07002295 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07002296static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07002297{
2298 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2299 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07002300 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002301 u8 *addr_list = NULL;
2302 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002303
2304 /* Check for Promiscuous and All Multicast modes */
2305
2306 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07002307 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07002308
2309 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07002310 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002311 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07002312 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07002313 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002314 if (netdev->flags & IFF_ALLMULTI) {
2315 fctrl |= IXGBE_FCTRL_MPE;
2316 fctrl &= ~IXGBE_FCTRL_UPE;
2317 } else {
2318 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2319 }
Alexander Duyck3d016252008-08-26 18:30:04 -07002320 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002321 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002322 }
2323
2324 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07002325 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07002326
Christopher Leech2c5645c2008-08-26 04:27:02 -07002327 /* reprogram secondary unicast list */
Jiri Pirko31278e72009-06-17 01:12:19 +00002328 hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list);
Auke Kok9a799d72007-09-15 14:07:45 -07002329
Christopher Leech2c5645c2008-08-26 04:27:02 -07002330 /* reprogram multicast list */
2331 addr_count = netdev->mc_count;
2332 if (addr_count)
2333 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002334 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2335 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002336}
2337
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002338static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2339{
2340 int q_idx;
2341 struct ixgbe_q_vector *q_vector;
2342 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2343
2344 /* legacy and MSI only use one vector */
2345 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2346 q_vectors = 1;
2347
2348 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002349 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002350 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002351 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002352 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2353 if (!q_vector->rxr_count || !q_vector->txr_count) {
2354 if (q_vector->txr_count == 1)
2355 napi->poll = &ixgbe_clean_txonly;
2356 else if (q_vector->rxr_count == 1)
2357 napi->poll = &ixgbe_clean_rxonly;
2358 }
2359 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002360
2361 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002362 }
2363}
2364
2365static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2366{
2367 int q_idx;
2368 struct ixgbe_q_vector *q_vector;
2369 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2370
2371 /* legacy and MSI only use one vector */
2372 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2373 q_vectors = 1;
2374
2375 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002376 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002377 napi_disable(&q_vector->napi);
2378 }
2379}
2380
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002381#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002382/*
2383 * ixgbe_configure_dcb - Configure DCB hardware
2384 * @adapter: ixgbe adapter struct
2385 *
2386 * This is called by the driver on open to configure the DCB hardware.
2387 * This is also called by the gennetlink interface when reconfiguring
2388 * the DCB state.
2389 */
2390static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2391{
2392 struct ixgbe_hw *hw = &adapter->hw;
2393 u32 txdctl, vlnctrl;
2394 int i, j;
2395
2396 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2397 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2398 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2399
2400 /* reconfigure the hardware */
2401 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2402
2403 for (i = 0; i < adapter->num_tx_queues; i++) {
2404 j = adapter->tx_ring[i].reg_idx;
2405 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2406 /* PThresh workaround for Tx hang with DFP enabled. */
2407 txdctl |= 32;
2408 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2409 }
2410 /* Enable VLAN tag insert/strip */
2411 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002412 if (hw->mac.type == ixgbe_mac_82598EB) {
2413 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2414 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2415 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2416 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2417 vlnctrl |= IXGBE_VLNCTRL_VFE;
2418 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2419 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2420 for (i = 0; i < adapter->num_rx_queues; i++) {
2421 j = adapter->rx_ring[i].reg_idx;
2422 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2423 vlnctrl |= IXGBE_RXDCTL_VME;
2424 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2425 }
2426 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08002427 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2428}
2429
2430#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002431static void ixgbe_configure(struct ixgbe_adapter *adapter)
2432{
2433 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002434 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002435 int i;
2436
Christopher Leech2c5645c2008-08-26 04:27:02 -07002437 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002438
2439 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002440#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002441 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2442 netif_set_gso_max_size(netdev, 32768);
2443 ixgbe_configure_dcb(adapter);
2444 } else {
2445 netif_set_gso_max_size(netdev, 65536);
2446 }
2447#else
2448 netif_set_gso_max_size(netdev, 65536);
2449#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002450
Yi Zoueacd73f2009-05-13 13:11:06 +00002451#ifdef IXGBE_FCOE
2452 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2453 ixgbe_configure_fcoe(adapter);
2454
2455#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002456 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2457 for (i = 0; i < adapter->num_tx_queues; i++)
2458 adapter->tx_ring[i].atr_sample_rate =
2459 adapter->atr_sample_rate;
2460 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
2461 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
2462 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
2463 }
2464
Auke Kok9a799d72007-09-15 14:07:45 -07002465 ixgbe_configure_tx(adapter);
2466 ixgbe_configure_rx(adapter);
2467 for (i = 0; i < adapter->num_rx_queues; i++)
2468 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002469 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07002470}
2471
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002472static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2473{
2474 switch (hw->phy.type) {
2475 case ixgbe_phy_sfp_avago:
2476 case ixgbe_phy_sfp_ftl:
2477 case ixgbe_phy_sfp_intel:
2478 case ixgbe_phy_sfp_unknown:
2479 case ixgbe_phy_tw_tyco:
2480 case ixgbe_phy_tw_unknown:
2481 return true;
2482 default:
2483 return false;
2484 }
2485}
2486
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002487/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002488 * ixgbe_sfp_link_config - set up SFP+ link
2489 * @adapter: pointer to private adapter struct
2490 **/
2491static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2492{
2493 struct ixgbe_hw *hw = &adapter->hw;
2494
2495 if (hw->phy.multispeed_fiber) {
2496 /*
2497 * In multispeed fiber setups, the device may not have
2498 * had a physical connection when the driver loaded.
2499 * If that's the case, the initial link configuration
2500 * couldn't get the MAC into 10G or 1G mode, so we'll
2501 * never have a link status change interrupt fire.
2502 * We need to try and force an autonegotiation
2503 * session, then bring up link.
2504 */
2505 hw->mac.ops.setup_sfp(hw);
2506 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2507 schedule_work(&adapter->multispeed_fiber_task);
2508 } else {
2509 /*
2510 * Direct Attach Cu and non-multispeed fiber modules
2511 * still need to be configured properly prior to
2512 * attempting link.
2513 */
2514 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2515 schedule_work(&adapter->sfp_config_module_task);
2516 }
2517}
2518
2519/**
2520 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002521 * @hw: pointer to private hardware struct
2522 *
2523 * Returns 0 on success, negative on failure
2524 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002525static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002526{
2527 u32 autoneg;
2528 bool link_up = false;
2529 u32 ret = IXGBE_ERR_LINK_SETUP;
2530
2531 if (hw->mac.ops.check_link)
2532 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2533
2534 if (ret)
2535 goto link_cfg_out;
2536
2537 if (hw->mac.ops.get_link_capabilities)
2538 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
2539 &hw->mac.autoneg);
2540 if (ret)
2541 goto link_cfg_out;
2542
2543 if (hw->mac.ops.setup_link_speed)
2544 ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002545link_cfg_out:
2546 return ret;
2547}
2548
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002549#define IXGBE_MAX_RX_DESC_POLL 10
2550static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2551 int rxr)
2552{
2553 int j = adapter->rx_ring[rxr].reg_idx;
2554 int k;
2555
2556 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2557 if (IXGBE_READ_REG(&adapter->hw,
2558 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2559 break;
2560 else
2561 msleep(1);
2562 }
2563 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2564 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2565 "not set within the polling period\n", rxr);
2566 }
2567 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2568 (adapter->rx_ring[rxr].count - 1));
2569}
2570
Auke Kok9a799d72007-09-15 14:07:45 -07002571static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2572{
2573 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07002574 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002575 int i, j = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002576 int num_rx_rings = adapter->num_rx_queues;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002577 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002578 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002579 u32 txdctl, rxdctl, mhadd;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002580 u32 dmatxctl;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002581 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002582
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002583 ixgbe_get_hw_control(adapter);
2584
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002585 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2586 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002587 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2588 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002589 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002590 } else {
2591 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002592 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002593 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002594 /* XXX: to interrupt immediately for EICS writes, enable this */
2595 /* gpie |= IXGBE_GPIE_EIMEN; */
2596 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2597 }
2598
2599 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2600 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2601 * specifically only auto mask tx and rx interrupts */
2602 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002603 }
2604
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002605 /* Enable fan failure interrupt if media type is copper */
2606 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2607 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2608 gpie |= IXGBE_SDP1_GPIEN;
2609 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2610 }
2611
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002612 if (hw->mac.type == ixgbe_mac_82599EB) {
2613 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2614 gpie |= IXGBE_SDP1_GPIEN;
2615 gpie |= IXGBE_SDP2_GPIEN;
2616 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2617 }
2618
Yi Zou63f39bd2009-05-17 12:34:35 +00002619#ifdef IXGBE_FCOE
2620 /* adjust max frame to be able to do baby jumbo for FCoE */
2621 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
2622 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
2623 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
2624
2625#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07002626 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002627 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2628 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2629 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2630
2631 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2632 }
2633
2634 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002635 j = adapter->tx_ring[i].reg_idx;
2636 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002637 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2638 txdctl |= (8 << 16);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002639 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2640 }
2641
2642 if (hw->mac.type == ixgbe_mac_82599EB) {
2643 /* DMATXCTL.EN must be set after all Tx queue config is done */
2644 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2645 dmatxctl |= IXGBE_DMATXCTL_TE;
2646 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2647 }
2648 for (i = 0; i < adapter->num_tx_queues; i++) {
2649 j = adapter->tx_ring[i].reg_idx;
2650 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Auke Kok9a799d72007-09-15 14:07:45 -07002651 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002652 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002653 }
2654
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002655 for (i = 0; i < num_rx_rings; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002656 j = adapter->rx_ring[i].reg_idx;
2657 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2658 /* enable PTHRESH=32 descriptors (half the internal cache)
2659 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2660 * this also removes a pesky rx_no_buffer_count increment */
2661 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002662 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002663 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002664 if (hw->mac.type == ixgbe_mac_82599EB)
2665 ixgbe_rx_desc_queue_enable(adapter, i);
Auke Kok9a799d72007-09-15 14:07:45 -07002666 }
2667 /* enable all receives */
2668 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002669 if (hw->mac.type == ixgbe_mac_82598EB)
2670 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2671 else
2672 rxdctl |= IXGBE_RXCTRL_RXEN;
2673 hw->mac.ops.enable_rx_dma(hw, rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002674
2675 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2676 ixgbe_configure_msix(adapter);
2677 else
2678 ixgbe_configure_msi_and_legacy(adapter);
2679
2680 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002681 ixgbe_napi_enable_all(adapter);
2682
2683 /* clear any pending interrupts, may auto mask */
2684 IXGBE_READ_REG(hw, IXGBE_EICR);
2685
Auke Kok9a799d72007-09-15 14:07:45 -07002686 ixgbe_irq_enable(adapter);
2687
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002688 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00002689 * If this adapter has a fan, check to see if we had a failure
2690 * before we enabled the interrupt.
2691 */
2692 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2693 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2694 if (esdp & IXGBE_ESDP_SDP1)
2695 DPRINTK(DRV, CRIT,
2696 "Fan has stopped, replace the adapter\n");
2697 }
2698
2699 /*
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002700 * For hot-pluggable SFP+ devices, a new SFP+ module may have
Don Skidmore19343de2009-07-02 12:50:31 +00002701 * arrived before interrupts were enabled but after probe. Such
2702 * devices wouldn't have their type identified yet. We need to
2703 * kick off the SFP+ module setup first, then try to bring up link.
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002704 * If we're not hot-pluggable SFP+, we just need to configure link
2705 * and bring it up.
2706 */
Don Skidmore19343de2009-07-02 12:50:31 +00002707 if (hw->phy.type == ixgbe_phy_unknown) {
2708 err = hw->phy.ops.identify(hw);
2709 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore5da43c12009-07-02 12:50:52 +00002710 /*
2711 * Take the device down and schedule the sfp tasklet
2712 * which will unregister_netdev and log it.
2713 */
Don Skidmore19343de2009-07-02 12:50:31 +00002714 ixgbe_down(adapter);
Don Skidmore5da43c12009-07-02 12:50:52 +00002715 schedule_work(&adapter->sfp_config_module_task);
Don Skidmore19343de2009-07-02 12:50:31 +00002716 return err;
2717 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002718 }
2719
2720 if (ixgbe_is_sfp(hw)) {
2721 ixgbe_sfp_link_config(adapter);
2722 } else {
2723 err = ixgbe_non_sfp_link_config(hw);
2724 if (err)
2725 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2726 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002727
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002728 for (i = 0; i < adapter->num_tx_queues; i++)
2729 set_bit(__IXGBE_FDIR_INIT_DONE,
2730 &(adapter->tx_ring[i].reinit_state));
2731
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002732 /* enable transmits */
2733 netif_tx_start_all_queues(netdev);
2734
Auke Kok9a799d72007-09-15 14:07:45 -07002735 /* bring the link up in the watchdog, this could race with our first
2736 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002737 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2738 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002739 mod_timer(&adapter->watchdog_timer, jiffies);
2740 return 0;
2741}
2742
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002743void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2744{
2745 WARN_ON(in_interrupt());
2746 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2747 msleep(1);
2748 ixgbe_down(adapter);
2749 ixgbe_up(adapter);
2750 clear_bit(__IXGBE_RESETTING, &adapter->state);
2751}
2752
Auke Kok9a799d72007-09-15 14:07:45 -07002753int ixgbe_up(struct ixgbe_adapter *adapter)
2754{
2755 /* hardware has been reset, we need to reload some things */
2756 ixgbe_configure(adapter);
2757
2758 return ixgbe_up_complete(adapter);
2759}
2760
2761void ixgbe_reset(struct ixgbe_adapter *adapter)
2762{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002763 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07002764 int err;
2765
2766 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002767 switch (err) {
2768 case 0:
2769 case IXGBE_ERR_SFP_NOT_PRESENT:
2770 break;
2771 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
2772 dev_err(&adapter->pdev->dev, "master disable timed out\n");
2773 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00002774 case IXGBE_ERR_EEPROM_VERSION:
2775 /* We are running on a pre-production device, log a warning */
2776 dev_warn(&adapter->pdev->dev, "This device is a pre-production "
2777 "adapter/LOM. Please be aware there may be issues "
2778 "associated with your hardware. If you are "
2779 "experiencing problems please contact your Intel or "
2780 "hardware representative who provided you with this "
2781 "hardware.\n");
2782 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002783 default:
2784 dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err);
2785 }
Auke Kok9a799d72007-09-15 14:07:45 -07002786
2787 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002788 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002789}
2790
Auke Kok9a799d72007-09-15 14:07:45 -07002791/**
2792 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2793 * @adapter: board private structure
2794 * @rx_ring: ring to free buffers from
2795 **/
2796static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002797 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002798{
2799 struct pci_dev *pdev = adapter->pdev;
2800 unsigned long size;
2801 unsigned int i;
2802
2803 /* Free all the Rx ring sk_buffs */
2804
2805 for (i = 0; i < rx_ring->count; i++) {
2806 struct ixgbe_rx_buffer *rx_buffer_info;
2807
2808 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2809 if (rx_buffer_info->dma) {
2810 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002811 rx_ring->rx_buf_len,
2812 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002813 rx_buffer_info->dma = 0;
2814 }
2815 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002816 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002817 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002818 do {
2819 struct sk_buff *this = skb;
2820 skb = skb->prev;
2821 dev_kfree_skb(this);
2822 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002823 }
2824 if (!rx_buffer_info->page)
2825 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00002826 if (rx_buffer_info->page_dma) {
2827 pci_unmap_page(pdev, rx_buffer_info->page_dma,
2828 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
2829 rx_buffer_info->page_dma = 0;
2830 }
Auke Kok9a799d72007-09-15 14:07:45 -07002831 put_page(rx_buffer_info->page);
2832 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002833 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002834 }
2835
2836 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2837 memset(rx_ring->rx_buffer_info, 0, size);
2838
2839 /* Zero out the descriptor ring */
2840 memset(rx_ring->desc, 0, rx_ring->size);
2841
2842 rx_ring->next_to_clean = 0;
2843 rx_ring->next_to_use = 0;
2844
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002845 if (rx_ring->head)
2846 writel(0, adapter->hw.hw_addr + rx_ring->head);
2847 if (rx_ring->tail)
2848 writel(0, adapter->hw.hw_addr + rx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002849}
2850
2851/**
2852 * ixgbe_clean_tx_ring - Free Tx Buffers
2853 * @adapter: board private structure
2854 * @tx_ring: ring to be cleaned
2855 **/
2856static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002857 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002858{
2859 struct ixgbe_tx_buffer *tx_buffer_info;
2860 unsigned long size;
2861 unsigned int i;
2862
2863 /* Free all the Tx ring sk_buffs */
2864
2865 for (i = 0; i < tx_ring->count; i++) {
2866 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2867 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2868 }
2869
2870 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2871 memset(tx_ring->tx_buffer_info, 0, size);
2872
2873 /* Zero out the descriptor ring */
2874 memset(tx_ring->desc, 0, tx_ring->size);
2875
2876 tx_ring->next_to_use = 0;
2877 tx_ring->next_to_clean = 0;
2878
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002879 if (tx_ring->head)
2880 writel(0, adapter->hw.hw_addr + tx_ring->head);
2881 if (tx_ring->tail)
2882 writel(0, adapter->hw.hw_addr + tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002883}
2884
2885/**
Auke Kok9a799d72007-09-15 14:07:45 -07002886 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2887 * @adapter: board private structure
2888 **/
2889static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2890{
2891 int i;
2892
2893 for (i = 0; i < adapter->num_rx_queues; i++)
2894 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2895}
2896
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002897/**
2898 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2899 * @adapter: board private structure
2900 **/
2901static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2902{
2903 int i;
2904
2905 for (i = 0; i < adapter->num_tx_queues; i++)
2906 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2907}
2908
Auke Kok9a799d72007-09-15 14:07:45 -07002909void ixgbe_down(struct ixgbe_adapter *adapter)
2910{
2911 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002912 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002913 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002914 u32 txdctl;
2915 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002916
2917 /* signal that we are down to the interrupt handler */
2918 set_bit(__IXGBE_DOWN, &adapter->state);
2919
2920 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002921 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2922 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002923
2924 netif_tx_disable(netdev);
2925
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002926 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002927 msleep(10);
2928
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002929 netif_tx_stop_all_queues(netdev);
2930
Auke Kok9a799d72007-09-15 14:07:45 -07002931 ixgbe_irq_disable(adapter);
2932
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002933 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002934
Auke Kok9a799d72007-09-15 14:07:45 -07002935 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002936 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002937
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002938 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
2939 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2940 cancel_work_sync(&adapter->fdir_reinit_task);
2941
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002942 /* disable transmits in the hardware now that interrupts are off */
2943 for (i = 0; i < adapter->num_tx_queues; i++) {
2944 j = adapter->tx_ring[i].reg_idx;
2945 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2946 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2947 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2948 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00002949 /* Disable the Tx DMA engine on 82599 */
2950 if (hw->mac.type == ixgbe_mac_82599EB)
2951 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
2952 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
2953 ~IXGBE_DMATXCTL_TE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002954
Auke Kok9a799d72007-09-15 14:07:45 -07002955 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002956
Paul Larson6f4a0e42008-06-24 17:00:56 -07002957 if (!pci_channel_offline(adapter->pdev))
2958 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002959 ixgbe_clean_all_tx_rings(adapter);
2960 ixgbe_clean_all_rx_rings(adapter);
2961
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002962#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002963 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00002964 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002965#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002966}
2967
Auke Kok9a799d72007-09-15 14:07:45 -07002968/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002969 * ixgbe_poll - NAPI Rx polling callback
2970 * @napi: structure for representing this polling device
2971 * @budget: how many packets driver is allowed to clean
2972 *
2973 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002974 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002975static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002976{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002977 struct ixgbe_q_vector *q_vector =
2978 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002979 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002980 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002981
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002982#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002983 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2984 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2985 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2986 }
2987#endif
2988
Alexander Duyckfe49f042009-06-04 16:00:09 +00002989 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002990 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002991
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002992 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002993 work_done = budget;
2994
David S. Miller53e52c72008-01-07 21:06:12 -08002995 /* If budget not fully consumed, exit the polling mode */
2996 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002997 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002998 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002999 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003000 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00003001 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003002 }
Auke Kok9a799d72007-09-15 14:07:45 -07003003 return work_done;
3004}
3005
3006/**
3007 * ixgbe_tx_timeout - Respond to a Tx Hang
3008 * @netdev: network interface device structure
3009 **/
3010static void ixgbe_tx_timeout(struct net_device *netdev)
3011{
3012 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3013
3014 /* Do the reset outside of interrupt context */
3015 schedule_work(&adapter->reset_task);
3016}
3017
3018static void ixgbe_reset_task(struct work_struct *work)
3019{
3020 struct ixgbe_adapter *adapter;
3021 adapter = container_of(work, struct ixgbe_adapter, reset_task);
3022
Alexander Duyck2f90b862008-11-20 20:52:10 -08003023 /* If we're already down or resetting, just bail */
3024 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
3025 test_bit(__IXGBE_RESETTING, &adapter->state))
3026 return;
3027
Auke Kok9a799d72007-09-15 14:07:45 -07003028 adapter->tx_timeout_count++;
3029
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003030 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003031}
3032
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003033#ifdef CONFIG_IXGBE_DCB
3034static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003035{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003036 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003037 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003038
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003039 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
3040 return ret;
3041
3042 f->mask = 0x7 << 3;
3043 adapter->num_rx_queues = f->indices;
3044 adapter->num_tx_queues = f->indices;
3045 ret = true;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003046
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003047 return ret;
3048}
3049#endif
3050
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003051/**
3052 * ixgbe_set_rss_queues: Allocate queues for RSS
3053 * @adapter: board private structure to initialize
3054 *
3055 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
3056 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
3057 *
3058 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003059static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
3060{
3061 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003062 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003063
3064 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003065 f->mask = 0xF;
3066 adapter->num_rx_queues = f->indices;
3067 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003068 ret = true;
3069 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003070 ret = false;
3071 }
3072
3073 return ret;
3074}
3075
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003076/**
3077 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
3078 * @adapter: board private structure to initialize
3079 *
3080 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
3081 * to the original CPU that initiated the Tx session. This runs in addition
3082 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
3083 * Rx load across CPUs using RSS.
3084 *
3085 **/
3086static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
3087{
3088 bool ret = false;
3089 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
3090
3091 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
3092 f_fdir->mask = 0;
3093
3094 /* Flow Director must have RSS enabled */
3095 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3096 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3097 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
3098 adapter->num_tx_queues = f_fdir->indices;
3099 adapter->num_rx_queues = f_fdir->indices;
3100 ret = true;
3101 } else {
3102 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3103 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3104 }
3105 return ret;
3106}
3107
Yi Zou0331a832009-05-17 12:33:52 +00003108#ifdef IXGBE_FCOE
3109/**
3110 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
3111 * @adapter: board private structure to initialize
3112 *
3113 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
3114 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
3115 * rx queues out of the max number of rx queues, instead, it is used as the
3116 * index of the first rx queue used by FCoE.
3117 *
3118 **/
3119static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
3120{
3121 bool ret = false;
3122 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3123
3124 f->indices = min((int)num_online_cpus(), f->indices);
3125 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3126#ifdef CONFIG_IXGBE_DCB
3127 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3128 DPRINTK(PROBE, INFO, "FCOE enabled with DCB \n");
3129 ixgbe_set_dcb_queues(adapter);
3130 }
3131#endif
3132 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3133 DPRINTK(PROBE, INFO, "FCOE enabled with RSS \n");
Yi Zou8faa2a72009-07-09 02:29:50 +00003134 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3135 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
3136 ixgbe_set_fdir_queues(adapter);
3137 else
3138 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00003139 }
3140 /* adding FCoE rx rings to the end */
3141 f->mask = adapter->num_rx_queues;
3142 adapter->num_rx_queues += f->indices;
3143 if (adapter->num_tx_queues == 0)
3144 adapter->num_tx_queues = f->indices;
3145
3146 ret = true;
3147 }
3148
3149 return ret;
3150}
3151
3152#endif /* IXGBE_FCOE */
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003153/*
3154 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
3155 * @adapter: board private structure to initialize
3156 *
3157 * This is the top level queue allocation routine. The order here is very
3158 * important, starting with the "most" number of features turned on at once,
3159 * and ending with the smallest set of features. This way large combinations
3160 * can be allocated if they're turned on, and smaller combinations are the
3161 * fallthrough conditions.
3162 *
3163 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003164static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
3165{
Yi Zou0331a832009-05-17 12:33:52 +00003166#ifdef IXGBE_FCOE
3167 if (ixgbe_set_fcoe_queues(adapter))
3168 goto done;
3169
3170#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003171#ifdef CONFIG_IXGBE_DCB
3172 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003173 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003174
3175#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003176 if (ixgbe_set_fdir_queues(adapter))
3177 goto done;
3178
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003179 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003180 goto done;
3181
3182 /* fallback to base case */
3183 adapter->num_rx_queues = 1;
3184 adapter->num_tx_queues = 1;
3185
3186done:
3187 /* Notify the stack of the (possibly) reduced Tx Queue count. */
3188 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003189}
3190
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003191static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003192 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003193{
3194 int err, vector_threshold;
3195
3196 /* We'll want at least 3 (vector_threshold):
3197 * 1) TxQ[0] Cleanup
3198 * 2) RxQ[0] Cleanup
3199 * 3) Other (Link Status Change, etc.)
3200 * 4) TCP Timer (optional)
3201 */
3202 vector_threshold = MIN_MSIX_COUNT;
3203
3204 /* The more we get, the more we will assign to Tx/Rx Cleanup
3205 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
3206 * Right now, we simply care about how many we'll get; we'll
3207 * set them up later while requesting irq's.
3208 */
3209 while (vectors >= vector_threshold) {
3210 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003211 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003212 if (!err) /* Success in acquiring all requested vectors. */
3213 break;
3214 else if (err < 0)
3215 vectors = 0; /* Nasty failure, quit now */
3216 else /* err == number of vectors we should try again with */
3217 vectors = err;
3218 }
3219
3220 if (vectors < vector_threshold) {
3221 /* Can't allocate enough MSI-X interrupts? Oh well.
3222 * This just means we'll go with either a single MSI
3223 * vector or fall back to legacy interrupts.
3224 */
3225 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
3226 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3227 kfree(adapter->msix_entries);
3228 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003229 } else {
3230 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08003231 /*
3232 * Adjust for only the vectors we'll use, which is minimum
3233 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
3234 * vectors we were allocated.
3235 */
3236 adapter->num_msix_vectors = min(vectors,
3237 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003238 }
3239}
3240
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003241/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003242 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003243 * @adapter: board private structure to initialize
3244 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003245 * Cache the descriptor ring offsets for RSS to the assigned rings.
3246 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003247 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003248static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003249{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003250 int i;
3251 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003252
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003253 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3254 for (i = 0; i < adapter->num_rx_queues; i++)
3255 adapter->rx_ring[i].reg_idx = i;
3256 for (i = 0; i < adapter->num_tx_queues; i++)
3257 adapter->tx_ring[i].reg_idx = i;
3258 ret = true;
3259 } else {
3260 ret = false;
3261 }
3262
3263 return ret;
3264}
3265
3266#ifdef CONFIG_IXGBE_DCB
3267/**
3268 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
3269 * @adapter: board private structure to initialize
3270 *
3271 * Cache the descriptor ring offsets for DCB to the assigned rings.
3272 *
3273 **/
3274static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
3275{
3276 int i;
3277 bool ret = false;
3278 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
3279
3280 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3281 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08003282 /* the number of queues is assumed to be symmetric */
3283 for (i = 0; i < dcb_i; i++) {
3284 adapter->rx_ring[i].reg_idx = i << 3;
3285 adapter->tx_ring[i].reg_idx = i << 2;
3286 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003287 ret = true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003288 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
PJ Waskiewiczf92ef202009-04-16 15:00:20 +00003289 if (dcb_i == 8) {
3290 /*
3291 * Tx TC0 starts at: descriptor queue 0
3292 * Tx TC1 starts at: descriptor queue 32
3293 * Tx TC2 starts at: descriptor queue 64
3294 * Tx TC3 starts at: descriptor queue 80
3295 * Tx TC4 starts at: descriptor queue 96
3296 * Tx TC5 starts at: descriptor queue 104
3297 * Tx TC6 starts at: descriptor queue 112
3298 * Tx TC7 starts at: descriptor queue 120
3299 *
3300 * Rx TC0-TC7 are offset by 16 queues each
3301 */
3302 for (i = 0; i < 3; i++) {
3303 adapter->tx_ring[i].reg_idx = i << 5;
3304 adapter->rx_ring[i].reg_idx = i << 4;
3305 }
3306 for ( ; i < 5; i++) {
3307 adapter->tx_ring[i].reg_idx =
3308 ((i + 2) << 4);
3309 adapter->rx_ring[i].reg_idx = i << 4;
3310 }
3311 for ( ; i < dcb_i; i++) {
3312 adapter->tx_ring[i].reg_idx =
3313 ((i + 8) << 3);
3314 adapter->rx_ring[i].reg_idx = i << 4;
3315 }
3316
3317 ret = true;
3318 } else if (dcb_i == 4) {
3319 /*
3320 * Tx TC0 starts at: descriptor queue 0
3321 * Tx TC1 starts at: descriptor queue 64
3322 * Tx TC2 starts at: descriptor queue 96
3323 * Tx TC3 starts at: descriptor queue 112
3324 *
3325 * Rx TC0-TC3 are offset by 32 queues each
3326 */
3327 adapter->tx_ring[0].reg_idx = 0;
3328 adapter->tx_ring[1].reg_idx = 64;
3329 adapter->tx_ring[2].reg_idx = 96;
3330 adapter->tx_ring[3].reg_idx = 112;
3331 for (i = 0 ; i < dcb_i; i++)
3332 adapter->rx_ring[i].reg_idx = i << 5;
3333
3334 ret = true;
3335 } else {
3336 ret = false;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003337 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003338 } else {
3339 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003340 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003341 } else {
3342 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003343 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003344
3345 return ret;
3346}
3347#endif
3348
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003349/**
3350 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
3351 * @adapter: board private structure to initialize
3352 *
3353 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
3354 *
3355 **/
3356static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
3357{
3358 int i;
3359 bool ret = false;
3360
3361 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3362 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3363 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
3364 for (i = 0; i < adapter->num_rx_queues; i++)
3365 adapter->rx_ring[i].reg_idx = i;
3366 for (i = 0; i < adapter->num_tx_queues; i++)
3367 adapter->tx_ring[i].reg_idx = i;
3368 ret = true;
3369 }
3370
3371 return ret;
3372}
3373
Yi Zou0331a832009-05-17 12:33:52 +00003374#ifdef IXGBE_FCOE
3375/**
3376 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
3377 * @adapter: board private structure to initialize
3378 *
3379 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
3380 *
3381 */
3382static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
3383{
3384 int i, fcoe_i = 0;
3385 bool ret = false;
3386 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3387
3388 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3389#ifdef CONFIG_IXGBE_DCB
3390 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3391 ixgbe_cache_ring_dcb(adapter);
3392 fcoe_i = adapter->rx_ring[0].reg_idx + 1;
3393 }
3394#endif /* CONFIG_IXGBE_DCB */
3395 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Yi Zou8faa2a72009-07-09 02:29:50 +00003396 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3397 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
3398 ixgbe_cache_ring_fdir(adapter);
3399 else
3400 ixgbe_cache_ring_rss(adapter);
3401
Yi Zou0331a832009-05-17 12:33:52 +00003402 fcoe_i = f->mask;
3403 }
3404 for (i = 0; i < f->indices; i++, fcoe_i++)
3405 adapter->rx_ring[f->mask + i].reg_idx = fcoe_i;
3406 ret = true;
3407 }
3408 return ret;
3409}
3410
3411#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003412/**
3413 * ixgbe_cache_ring_register - Descriptor ring to register mapping
3414 * @adapter: board private structure to initialize
3415 *
3416 * Once we know the feature-set enabled for the device, we'll cache
3417 * the register offset the descriptor ring is assigned to.
3418 *
3419 * Note, the order the various feature calls is important. It must start with
3420 * the "most" features enabled at the same time, then trickle down to the
3421 * least amount of features turned on at once.
3422 **/
3423static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
3424{
3425 /* start with default case */
3426 adapter->rx_ring[0].reg_idx = 0;
3427 adapter->tx_ring[0].reg_idx = 0;
3428
Yi Zou0331a832009-05-17 12:33:52 +00003429#ifdef IXGBE_FCOE
3430 if (ixgbe_cache_ring_fcoe(adapter))
3431 return;
3432
3433#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003434#ifdef CONFIG_IXGBE_DCB
3435 if (ixgbe_cache_ring_dcb(adapter))
3436 return;
3437
3438#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003439 if (ixgbe_cache_ring_fdir(adapter))
3440 return;
3441
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003442 if (ixgbe_cache_ring_rss(adapter))
3443 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003444}
3445
Auke Kok9a799d72007-09-15 14:07:45 -07003446/**
3447 * ixgbe_alloc_queues - Allocate memory for all rings
3448 * @adapter: board private structure to initialize
3449 *
3450 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003451 * number of queues at compile-time. The polling_netdev array is
3452 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07003453 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003454static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003455{
3456 int i;
3457
3458 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003459 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07003460 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003461 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07003462
3463 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003464 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003465 if (!adapter->rx_ring)
3466 goto err_rx_ring_allocation;
3467
3468 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003469 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003470 adapter->tx_ring[i].queue_index = i;
3471 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003472
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003473 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003474 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003475 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07003476 }
3477
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003478 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003479
3480 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003481
3482err_rx_ring_allocation:
3483 kfree(adapter->tx_ring);
3484err_tx_ring_allocation:
3485 return -ENOMEM;
3486}
3487
3488/**
3489 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3490 * @adapter: board private structure to initialize
3491 *
3492 * Attempt to configure the interrupts using the best available
3493 * capabilities of the hardware and the kernel.
3494 **/
Al Virofeea6a52008-11-27 15:34:07 -08003495static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003496{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003497 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003498 int err = 0;
3499 int vector, v_budget;
3500
3501 /*
3502 * It's easy to be greedy for MSI-X vectors, but it really
3503 * doesn't do us much good if we have a lot more vectors
3504 * than CPU's. So let's be conservative and only ask for
3505 * (roughly) twice the number of vectors as there are CPU's.
3506 */
3507 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003508 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003509
3510 /*
3511 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003512 * hw.mac->max_msix_vectors vectors. With features
3513 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3514 * descriptor queues supported by our device. Thus, we cap it off in
3515 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003516 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003517 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003518
3519 /* A failure in MSI-X entry allocation isn't fatal, but it does
3520 * mean we disable MSI-X capabilities of the adapter. */
3521 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003522 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003523 if (adapter->msix_entries) {
3524 for (vector = 0; vector < v_budget; vector++)
3525 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003526
Alexander Duyck7a921c92009-05-06 10:43:28 +00003527 ixgbe_acquire_msix_vectors(adapter, v_budget);
3528
3529 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3530 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003531 }
3532
Alexander Duyck7a921c92009-05-06 10:43:28 +00003533 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
3534 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003535 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3536 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3537 adapter->atr_sample_rate = 0;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003538 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003539
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003540 err = pci_enable_msi(adapter->pdev);
3541 if (!err) {
3542 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
3543 } else {
3544 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003545 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003546 /* reset err */
3547 err = 0;
3548 }
3549
3550out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003551 return err;
3552}
3553
Alexander Duyck7a921c92009-05-06 10:43:28 +00003554/**
3555 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
3556 * @adapter: board private structure to initialize
3557 *
3558 * We allocate one q_vector per queue interrupt. If allocation fails we
3559 * return -ENOMEM.
3560 **/
3561static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
3562{
3563 int q_idx, num_q_vectors;
3564 struct ixgbe_q_vector *q_vector;
3565 int napi_vectors;
3566 int (*poll)(struct napi_struct *, int);
3567
3568 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3569 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3570 napi_vectors = adapter->num_rx_queues;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003571 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003572 } else {
3573 num_q_vectors = 1;
3574 napi_vectors = 1;
3575 poll = &ixgbe_poll;
3576 }
3577
3578 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3579 q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL);
3580 if (!q_vector)
3581 goto err_out;
3582 q_vector->adapter = adapter;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003583 q_vector->eitr = adapter->eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00003584 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003585 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003586 adapter->q_vector[q_idx] = q_vector;
3587 }
3588
3589 return 0;
3590
3591err_out:
3592 while (q_idx) {
3593 q_idx--;
3594 q_vector = adapter->q_vector[q_idx];
3595 netif_napi_del(&q_vector->napi);
3596 kfree(q_vector);
3597 adapter->q_vector[q_idx] = NULL;
3598 }
3599 return -ENOMEM;
3600}
3601
3602/**
3603 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
3604 * @adapter: board private structure to initialize
3605 *
3606 * This function frees the memory allocated to the q_vectors. In addition if
3607 * NAPI is enabled it will delete any references to the NAPI struct prior
3608 * to freeing the q_vector.
3609 **/
3610static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
3611{
3612 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003613
Alexander Duyck91281fd2009-06-04 16:00:27 +00003614 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00003615 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003616 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00003617 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003618
3619 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3620 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00003621 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003622 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003623 kfree(q_vector);
3624 }
3625}
3626
Alexander Duyck2f90b862008-11-20 20:52:10 -08003627void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003628{
3629 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3630 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3631 pci_disable_msix(adapter->pdev);
3632 kfree(adapter->msix_entries);
3633 adapter->msix_entries = NULL;
3634 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
3635 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
3636 pci_disable_msi(adapter->pdev);
3637 }
3638 return;
3639}
3640
3641/**
3642 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3643 * @adapter: board private structure to initialize
3644 *
3645 * We determine which interrupt scheme to use based on...
3646 * - Kernel support (MSI, MSI-X)
3647 * - which can be user-defined (via MODULE_PARAM)
3648 * - Hardware queue count (num_*_queues)
3649 * - defined by miscellaneous hardware support/features (RSS, etc.)
3650 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003651int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003652{
3653 int err;
3654
3655 /* Number of supported queues */
3656 ixgbe_set_num_queues(adapter);
3657
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003658 err = ixgbe_set_interrupt_capability(adapter);
3659 if (err) {
3660 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3661 goto err_set_interrupt;
3662 }
3663
Alexander Duyck7a921c92009-05-06 10:43:28 +00003664 err = ixgbe_alloc_q_vectors(adapter);
3665 if (err) {
3666 DPRINTK(PROBE, ERR, "Unable to allocate memory for queue "
3667 "vectors\n");
3668 goto err_alloc_q_vectors;
3669 }
3670
3671 err = ixgbe_alloc_queues(adapter);
3672 if (err) {
3673 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3674 goto err_alloc_queues;
3675 }
3676
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003677 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003678 "Tx Queue count = %u\n",
3679 (adapter->num_rx_queues > 1) ? "Enabled" :
3680 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003681
3682 set_bit(__IXGBE_DOWN, &adapter->state);
3683
3684 return 0;
3685
Alexander Duyck7a921c92009-05-06 10:43:28 +00003686err_alloc_queues:
3687 ixgbe_free_q_vectors(adapter);
3688err_alloc_q_vectors:
3689 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003690err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00003691 return err;
3692}
3693
3694/**
3695 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
3696 * @adapter: board private structure to clear interrupt scheme on
3697 *
3698 * We go through and clear interrupt specific resources and reset the structure
3699 * to pre-load conditions
3700 **/
3701void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
3702{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003703 kfree(adapter->tx_ring);
3704 kfree(adapter->rx_ring);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003705 adapter->tx_ring = NULL;
3706 adapter->rx_ring = NULL;
3707
3708 ixgbe_free_q_vectors(adapter);
3709 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003710}
3711
3712/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08003713 * ixgbe_sfp_timer - worker thread to find a missing module
3714 * @data: pointer to our adapter struct
3715 **/
3716static void ixgbe_sfp_timer(unsigned long data)
3717{
3718 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3719
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003720 /*
3721 * Do the sfp_timer outside of interrupt context due to the
Donald Skidmorec4900be2008-11-20 21:11:42 -08003722 * delays that sfp+ detection requires
3723 */
3724 schedule_work(&adapter->sfp_task);
3725}
3726
3727/**
3728 * ixgbe_sfp_task - worker thread to find a missing module
3729 * @work: pointer to work_struct containing our data
3730 **/
3731static void ixgbe_sfp_task(struct work_struct *work)
3732{
3733 struct ixgbe_adapter *adapter = container_of(work,
3734 struct ixgbe_adapter,
3735 sfp_task);
3736 struct ixgbe_hw *hw = &adapter->hw;
3737
3738 if ((hw->phy.type == ixgbe_phy_nl) &&
3739 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3740 s32 ret = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00003741 if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
Donald Skidmorec4900be2008-11-20 21:11:42 -08003742 goto reschedule;
3743 ret = hw->phy.ops.reset(hw);
3744 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00003745 dev_err(&adapter->pdev->dev, "failed to initialize "
3746 "because an unsupported SFP+ module type "
3747 "was detected.\n"
3748 "Reload the driver after installing a "
3749 "supported module.\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08003750 unregister_netdev(adapter->netdev);
3751 } else {
3752 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3753 hw->phy.sfp_type);
3754 }
3755 /* don't need this routine any more */
3756 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3757 }
3758 return;
3759reschedule:
3760 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3761 mod_timer(&adapter->sfp_timer,
3762 round_jiffies(jiffies + (2 * HZ)));
3763}
3764
3765/**
Auke Kok9a799d72007-09-15 14:07:45 -07003766 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3767 * @adapter: board private structure to initialize
3768 *
3769 * ixgbe_sw_init initializes the Adapter private data structure.
3770 * Fields are initialized based on PCI device information and
3771 * OS network device settings (MTU size).
3772 **/
3773static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3774{
3775 struct ixgbe_hw *hw = &adapter->hw;
3776 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003777 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003778#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003779 int j;
3780 struct tc_configuration *tc;
3781#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003782
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003783 /* PCI config space info */
3784
3785 hw->vendor_id = pdev->vendor;
3786 hw->device_id = pdev->device;
3787 hw->revision_id = pdev->revision;
3788 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3789 hw->subsystem_device_id = pdev->subsystem_device;
3790
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003791 /* Set capability flags */
3792 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3793 adapter->ring_feature[RING_F_RSS].indices = rss;
3794 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003795 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Don Skidmorebf069c92009-05-07 10:39:54 +00003796 if (hw->mac.type == ixgbe_mac_82598EB) {
3797 if (hw->device_id == IXGBE_DEV_ID_82598AT)
3798 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003799 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Don Skidmorebf069c92009-05-07 10:39:54 +00003800 } else if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003801 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00003802 adapter->flags |= IXGBE_FLAG2_RSC_CAPABLE;
3803 adapter->flags |= IXGBE_FLAG2_RSC_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003804 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
3805 adapter->ring_feature[RING_F_FDIR].indices =
3806 IXGBE_MAX_FDIR_INDICES;
3807 adapter->atr_sample_rate = 20;
3808 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00003809#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00003810 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
3811 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
3812 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00003813#endif /* IXGBE_FCOE */
Alexander Duyckf8212f92009-04-27 22:42:37 +00003814 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003815
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003816#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003817 /* Configure DCB traffic classes */
3818 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3819 tc = &adapter->dcb_cfg.tc_config[j];
3820 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3821 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3822 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3823 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3824 tc->dcb_pfc = pfc_disabled;
3825 }
3826 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3827 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3828 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003829 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003830 adapter->dcb_cfg.round_robin_enable = false;
3831 adapter->dcb_set_bitmap = 0x00;
3832 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3833 adapter->ring_feature[RING_F_DCB].indices);
3834
3835#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003836
3837 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00003838 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00003839 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003840#ifdef CONFIG_DCB
3841 adapter->last_lfc_mode = hw->fc.current_mode;
3842#endif
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07003843 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3844 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3845 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3846 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00003847 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07003848
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07003849 /* enable itr by default in dynamic mode */
3850 adapter->itr_setting = 1;
3851 adapter->eitr_param = 20000;
3852
3853 /* set defaults for eitr in MegaBytes */
3854 adapter->eitr_low = 10;
3855 adapter->eitr_high = 20;
3856
3857 /* set default ring sizes */
3858 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
3859 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
3860
Auke Kok9a799d72007-09-15 14:07:45 -07003861 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003862 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003863 dev_err(&pdev->dev, "EEPROM initialization failed\n");
3864 return -EIO;
3865 }
3866
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003867 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07003868 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
3869
Auke Kok9a799d72007-09-15 14:07:45 -07003870 set_bit(__IXGBE_DOWN, &adapter->state);
3871
3872 return 0;
3873}
3874
3875/**
3876 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3877 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003878 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003879 *
3880 * Return 0 on success, negative on failure
3881 **/
3882int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003883 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003884{
3885 struct pci_dev *pdev = adapter->pdev;
3886 int size;
3887
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003888 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3889 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003890 if (!tx_ring->tx_buffer_info)
3891 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003892 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003893
3894 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08003895 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003896 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003897
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003898 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
3899 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003900 if (!tx_ring->desc)
3901 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07003902
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003903 tx_ring->next_to_use = 0;
3904 tx_ring->next_to_clean = 0;
3905 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07003906 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003907
3908err:
3909 vfree(tx_ring->tx_buffer_info);
3910 tx_ring->tx_buffer_info = NULL;
3911 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
3912 "descriptor ring\n");
3913 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003914}
3915
3916/**
Alexander Duyck69888672008-09-11 20:05:39 -07003917 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
3918 * @adapter: board private structure
3919 *
3920 * If this function returns with an error, then it's possible one or
3921 * more of the rings is populated (while the rest are not). It is the
3922 * callers duty to clean those orphaned rings.
3923 *
3924 * Return 0 on success, negative on failure
3925 **/
3926static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
3927{
3928 int i, err = 0;
3929
3930 for (i = 0; i < adapter->num_tx_queues; i++) {
3931 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
3932 if (!err)
3933 continue;
3934 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
3935 break;
3936 }
3937
3938 return err;
3939}
3940
3941/**
Auke Kok9a799d72007-09-15 14:07:45 -07003942 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
3943 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003944 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003945 *
3946 * Returns 0 on success, negative on failure
3947 **/
3948int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003949 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003950{
3951 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003952 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07003953
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003954 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
3955 rx_ring->rx_buffer_info = vmalloc(size);
3956 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07003957 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003958 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003959 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003960 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003961 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003962
Auke Kok9a799d72007-09-15 14:07:45 -07003963 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003964 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
3965 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003966
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003967 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07003968
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003969 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07003970 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003971 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003972 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003973 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003974 }
3975
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003976 rx_ring->next_to_clean = 0;
3977 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003978
3979 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003980
3981alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003982 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003983}
3984
3985/**
Alexander Duyck69888672008-09-11 20:05:39 -07003986 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
3987 * @adapter: board private structure
3988 *
3989 * If this function returns with an error, then it's possible one or
3990 * more of the rings is populated (while the rest are not). It is the
3991 * callers duty to clean those orphaned rings.
3992 *
3993 * Return 0 on success, negative on failure
3994 **/
3995
3996static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
3997{
3998 int i, err = 0;
3999
4000 for (i = 0; i < adapter->num_rx_queues; i++) {
4001 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
4002 if (!err)
4003 continue;
4004 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
4005 break;
4006 }
4007
4008 return err;
4009}
4010
4011/**
Auke Kok9a799d72007-09-15 14:07:45 -07004012 * ixgbe_free_tx_resources - Free Tx Resources per Queue
4013 * @adapter: board private structure
4014 * @tx_ring: Tx descriptor ring for a specific queue
4015 *
4016 * Free all transmit software resources
4017 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07004018void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
4019 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004020{
4021 struct pci_dev *pdev = adapter->pdev;
4022
4023 ixgbe_clean_tx_ring(adapter, tx_ring);
4024
4025 vfree(tx_ring->tx_buffer_info);
4026 tx_ring->tx_buffer_info = NULL;
4027
4028 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
4029
4030 tx_ring->desc = NULL;
4031}
4032
4033/**
4034 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4035 * @adapter: board private structure
4036 *
4037 * Free all transmit software resources
4038 **/
4039static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4040{
4041 int i;
4042
4043 for (i = 0; i < adapter->num_tx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004044 if (adapter->tx_ring[i].desc)
4045 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004046}
4047
4048/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004049 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004050 * @adapter: board private structure
4051 * @rx_ring: ring to clean the resources from
4052 *
4053 * Free all receive software resources
4054 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07004055void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
4056 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004057{
4058 struct pci_dev *pdev = adapter->pdev;
4059
4060 ixgbe_clean_rx_ring(adapter, rx_ring);
4061
4062 vfree(rx_ring->rx_buffer_info);
4063 rx_ring->rx_buffer_info = NULL;
4064
4065 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
4066
4067 rx_ring->desc = NULL;
4068}
4069
4070/**
4071 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4072 * @adapter: board private structure
4073 *
4074 * Free all receive software resources
4075 **/
4076static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4077{
4078 int i;
4079
4080 for (i = 0; i < adapter->num_rx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004081 if (adapter->rx_ring[i].desc)
4082 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004083}
4084
4085/**
Auke Kok9a799d72007-09-15 14:07:45 -07004086 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4087 * @netdev: network interface device structure
4088 * @new_mtu: new value for maximum frame size
4089 *
4090 * Returns 0 on success, negative on failure
4091 **/
4092static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4093{
4094 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4095 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4096
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004097 /* MTU < 68 is an error and causes problems on some kernels */
4098 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07004099 return -EINVAL;
4100
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004101 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004102 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004103 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004104 netdev->mtu = new_mtu;
4105
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004106 if (netif_running(netdev))
4107 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004108
4109 return 0;
4110}
4111
4112/**
4113 * ixgbe_open - Called when a network interface is made active
4114 * @netdev: network interface device structure
4115 *
4116 * Returns 0 on success, negative value on failure
4117 *
4118 * The open entry point is called when a network interface is made
4119 * active by the system (IFF_UP). At this point all resources needed
4120 * for transmit and receive operations are allocated, the interrupt
4121 * handler is registered with the OS, the watchdog timer is started,
4122 * and the stack is notified that the interface is ready.
4123 **/
4124static int ixgbe_open(struct net_device *netdev)
4125{
4126 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4127 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004128
Auke Kok4bebfaa2008-02-11 09:26:01 -08004129 /* disallow open during test */
4130 if (test_bit(__IXGBE_TESTING, &adapter->state))
4131 return -EBUSY;
4132
Jesse Brandeburg54386462009-04-17 20:44:27 +00004133 netif_carrier_off(netdev);
4134
Auke Kok9a799d72007-09-15 14:07:45 -07004135 /* allocate transmit descriptors */
4136 err = ixgbe_setup_all_tx_resources(adapter);
4137 if (err)
4138 goto err_setup_tx;
4139
Auke Kok9a799d72007-09-15 14:07:45 -07004140 /* allocate receive descriptors */
4141 err = ixgbe_setup_all_rx_resources(adapter);
4142 if (err)
4143 goto err_setup_rx;
4144
4145 ixgbe_configure(adapter);
4146
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004147 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004148 if (err)
4149 goto err_req_irq;
4150
Auke Kok9a799d72007-09-15 14:07:45 -07004151 err = ixgbe_up_complete(adapter);
4152 if (err)
4153 goto err_up;
4154
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004155 netif_tx_start_all_queues(netdev);
4156
Auke Kok9a799d72007-09-15 14:07:45 -07004157 return 0;
4158
4159err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004160 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004161 ixgbe_free_irq(adapter);
4162err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07004163err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004164 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004165err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004166 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004167 ixgbe_reset(adapter);
4168
4169 return err;
4170}
4171
4172/**
4173 * ixgbe_close - Disables a network interface
4174 * @netdev: network interface device structure
4175 *
4176 * Returns 0, this is not allowed to fail
4177 *
4178 * The close entry point is called when an interface is de-activated
4179 * by the OS. The hardware is still under the drivers control, but
4180 * needs to be disabled. A global MAC reset is issued to stop the
4181 * hardware, and all transmit and receive resources are freed.
4182 **/
4183static int ixgbe_close(struct net_device *netdev)
4184{
4185 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004186
4187 ixgbe_down(adapter);
4188 ixgbe_free_irq(adapter);
4189
4190 ixgbe_free_all_tx_resources(adapter);
4191 ixgbe_free_all_rx_resources(adapter);
4192
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004193 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004194
4195 return 0;
4196}
4197
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004198#ifdef CONFIG_PM
4199static int ixgbe_resume(struct pci_dev *pdev)
4200{
4201 struct net_device *netdev = pci_get_drvdata(pdev);
4202 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4203 u32 err;
4204
4205 pci_set_power_state(pdev, PCI_D0);
4206 pci_restore_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004207
4208 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004209 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07004210 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004211 "suspend\n");
4212 return err;
4213 }
4214 pci_set_master(pdev);
4215
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004216 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004217
4218 err = ixgbe_init_interrupt_scheme(adapter);
4219 if (err) {
4220 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
4221 "device\n");
4222 return err;
4223 }
4224
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004225 ixgbe_reset(adapter);
4226
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00004227 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4228
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004229 if (netif_running(netdev)) {
4230 err = ixgbe_open(adapter->netdev);
4231 if (err)
4232 return err;
4233 }
4234
4235 netif_device_attach(netdev);
4236
4237 return 0;
4238}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004239#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004240
4241static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004242{
4243 struct net_device *netdev = pci_get_drvdata(pdev);
4244 struct ixgbe_adapter *adapter = netdev_priv(netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004245 struct ixgbe_hw *hw = &adapter->hw;
4246 u32 ctrl, fctrl;
4247 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004248#ifdef CONFIG_PM
4249 int retval = 0;
4250#endif
4251
4252 netif_device_detach(netdev);
4253
4254 if (netif_running(netdev)) {
4255 ixgbe_down(adapter);
4256 ixgbe_free_irq(adapter);
4257 ixgbe_free_all_tx_resources(adapter);
4258 ixgbe_free_all_rx_resources(adapter);
4259 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00004260 ixgbe_clear_interrupt_scheme(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004261
4262#ifdef CONFIG_PM
4263 retval = pci_save_state(pdev);
4264 if (retval)
4265 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004266
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004267#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004268 if (wufc) {
4269 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004270
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004271 /* turn on all-multi mode if wake on multicast is enabled */
4272 if (wufc & IXGBE_WUFC_MC) {
4273 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4274 fctrl |= IXGBE_FCTRL_MPE;
4275 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4276 }
4277
4278 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4279 ctrl |= IXGBE_CTRL_GIO_DIS;
4280 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4281
4282 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4283 } else {
4284 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4285 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4286 }
4287
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004288 if (wufc && hw->mac.type == ixgbe_mac_82599EB)
4289 pci_wake_from_d3(pdev, true);
4290 else
4291 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004292
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004293 *enable_wake = !!wufc;
4294
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004295 ixgbe_release_hw_control(adapter);
4296
4297 pci_disable_device(pdev);
4298
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004299 return 0;
4300}
4301
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004302#ifdef CONFIG_PM
4303static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4304{
4305 int retval;
4306 bool wake;
4307
4308 retval = __ixgbe_shutdown(pdev, &wake);
4309 if (retval)
4310 return retval;
4311
4312 if (wake) {
4313 pci_prepare_to_sleep(pdev);
4314 } else {
4315 pci_wake_from_d3(pdev, false);
4316 pci_set_power_state(pdev, PCI_D3hot);
4317 }
4318
4319 return 0;
4320}
4321#endif /* CONFIG_PM */
4322
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004323static void ixgbe_shutdown(struct pci_dev *pdev)
4324{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004325 bool wake;
4326
4327 __ixgbe_shutdown(pdev, &wake);
4328
4329 if (system_state == SYSTEM_POWER_OFF) {
4330 pci_wake_from_d3(pdev, wake);
4331 pci_set_power_state(pdev, PCI_D3hot);
4332 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004333}
4334
4335/**
Auke Kok9a799d72007-09-15 14:07:45 -07004336 * ixgbe_update_stats - Update the board statistics counters.
4337 * @adapter: board private structure
4338 **/
4339void ixgbe_update_stats(struct ixgbe_adapter *adapter)
4340{
4341 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004342 u64 total_mpc = 0;
4343 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004344
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004345 if (hw->mac.type == ixgbe_mac_82599EB) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004346 u64 rsc_count = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004347 for (i = 0; i < 16; i++)
4348 adapter->hw_rx_no_dma_resources +=
4349 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Alexander Duyckf8212f92009-04-27 22:42:37 +00004350 for (i = 0; i < adapter->num_rx_queues; i++)
4351 rsc_count += adapter->rx_ring[i].rsc_count;
4352 adapter->rsc_count = rsc_count;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004353 }
4354
Auke Kok9a799d72007-09-15 14:07:45 -07004355 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004356 for (i = 0; i < 8; i++) {
4357 /* for packet buffers not used, the register should read 0 */
4358 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
4359 missed_rx += mpc;
4360 adapter->stats.mpc[i] += mpc;
4361 total_mpc += adapter->stats.mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004362 if (hw->mac.type == ixgbe_mac_82598EB)
4363 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004364 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
4365 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
4366 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
4367 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004368 if (hw->mac.type == ixgbe_mac_82599EB) {
4369 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4370 IXGBE_PXONRXCNT(i));
4371 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4372 IXGBE_PXOFFRXCNT(i));
4373 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004374 } else {
4375 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4376 IXGBE_PXONRXC(i));
4377 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4378 IXGBE_PXOFFRXC(i));
4379 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004380 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
4381 IXGBE_PXONTXC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004382 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004383 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004384 }
4385 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
4386 /* work around hardware counting issue */
4387 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07004388
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004389 /* 82598 hardware only has a 32 bit counter in the high register */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004390 if (hw->mac.type == ixgbe_mac_82599EB) {
4391 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
4392 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
4393 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
4394 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
4395 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
4396 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
4397 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
4398 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004399 adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
4400 adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00004401#ifdef IXGBE_FCOE
4402 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
4403 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
4404 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
4405 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
4406 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
4407 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
4408#endif /* IXGBE_FCOE */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004409 } else {
4410 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
4411 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
4412 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
4413 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
4414 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
4415 }
Auke Kok9a799d72007-09-15 14:07:45 -07004416 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
4417 adapter->stats.bprc += bprc;
4418 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004419 if (hw->mac.type == ixgbe_mac_82598EB)
4420 adapter->stats.mprc -= bprc;
Auke Kok9a799d72007-09-15 14:07:45 -07004421 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
4422 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
4423 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
4424 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
4425 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
4426 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
4427 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004428 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004429 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
4430 adapter->stats.lxontxc += lxon;
4431 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
4432 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07004433 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4434 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004435 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
4436 /*
4437 * 82598 errata - tx of flow control packets is included in tx counters
4438 */
4439 xon_off_tot = lxon + lxoff;
4440 adapter->stats.gptc -= xon_off_tot;
4441 adapter->stats.mptc -= xon_off_tot;
4442 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07004443 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4444 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
4445 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07004446 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
4447 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004448 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004449 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
4450 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
4451 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
4452 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
4453 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004454 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
4455
4456 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07004457 adapter->net_stats.multicast = adapter->stats.mprc;
4458
4459 /* Rx Errors */
4460 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004461 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07004462 adapter->net_stats.rx_dropped = 0;
4463 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
4464 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004465 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07004466}
4467
4468/**
4469 * ixgbe_watchdog - Timer Call-back
4470 * @data: pointer to adapter cast into an unsigned long
4471 **/
4472static void ixgbe_watchdog(unsigned long data)
4473{
4474 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004475 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004476 u64 eics = 0;
4477 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004478
Alexander Duyckfe49f042009-06-04 16:00:09 +00004479 /*
4480 * Do the watchdog outside of interrupt context due to the lovely
4481 * delays that some of the newer hardware requires
4482 */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004483
Alexander Duyckfe49f042009-06-04 16:00:09 +00004484 if (test_bit(__IXGBE_DOWN, &adapter->state))
4485 goto watchdog_short_circuit;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004486
Alexander Duyckfe49f042009-06-04 16:00:09 +00004487 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
4488 /*
4489 * for legacy and MSI interrupts don't set any bits
4490 * that are enabled for EIAM, because this operation
4491 * would set *both* EIMS and EICS for any bit in EIAM
4492 */
4493 IXGBE_WRITE_REG(hw, IXGBE_EICS,
4494 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
4495 goto watchdog_reschedule;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004496 }
4497
Alexander Duyckfe49f042009-06-04 16:00:09 +00004498 /* get one bit for every active tx/rx interrupt vector */
4499 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
4500 struct ixgbe_q_vector *qv = adapter->q_vector[i];
4501 if (qv->rxr_count || qv->txr_count)
4502 eics |= ((u64)1 << i);
4503 }
4504
4505 /* Cause software interrupt to ensure rx rings are cleaned */
4506 ixgbe_irq_rearm_queues(adapter, eics);
4507
4508watchdog_reschedule:
4509 /* Reset the timer */
4510 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
4511
4512watchdog_short_circuit:
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004513 schedule_work(&adapter->watchdog_task);
4514}
4515
4516/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004517 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
4518 * @work: pointer to work_struct containing our data
4519 **/
4520static void ixgbe_multispeed_fiber_task(struct work_struct *work)
4521{
4522 struct ixgbe_adapter *adapter = container_of(work,
4523 struct ixgbe_adapter,
4524 multispeed_fiber_task);
4525 struct ixgbe_hw *hw = &adapter->hw;
4526 u32 autoneg;
4527
4528 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
Mallikarjuna R Chilakalaa1f25322009-06-30 11:44:36 +00004529 autoneg = hw->phy.autoneg_advertised;
4530 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004531 hw->mac.ops.get_link_capabilities(hw, &autoneg,
4532 &hw->mac.autoneg);
4533 if (hw->mac.ops.setup_link_speed)
4534 hw->mac.ops.setup_link_speed(hw, autoneg, true, true);
4535 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4536 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
4537}
4538
4539/**
4540 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
4541 * @work: pointer to work_struct containing our data
4542 **/
4543static void ixgbe_sfp_config_module_task(struct work_struct *work)
4544{
4545 struct ixgbe_adapter *adapter = container_of(work,
4546 struct ixgbe_adapter,
4547 sfp_config_module_task);
4548 struct ixgbe_hw *hw = &adapter->hw;
4549 u32 err;
4550
4551 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004552
4553 /* Time for electrical oscillations to settle down */
4554 msleep(100);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004555 err = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004556
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004557 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00004558 dev_err(&adapter->pdev->dev, "failed to initialize because "
4559 "an unsupported SFP+ module type was detected.\n"
4560 "Reload the driver after installing a supported "
4561 "module.\n");
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004562 unregister_netdev(adapter->netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004563 return;
4564 }
4565 hw->mac.ops.setup_sfp(hw);
4566
Tony Breeds8d1c3c02009-04-09 22:29:10 +00004567 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004568 /* This will also work for DA Twinax connections */
4569 schedule_work(&adapter->multispeed_fiber_task);
4570 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
4571}
4572
4573/**
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004574 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
4575 * @work: pointer to work_struct containing our data
4576 **/
4577static void ixgbe_fdir_reinit_task(struct work_struct *work)
4578{
4579 struct ixgbe_adapter *adapter = container_of(work,
4580 struct ixgbe_adapter,
4581 fdir_reinit_task);
4582 struct ixgbe_hw *hw = &adapter->hw;
4583 int i;
4584
4585 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
4586 for (i = 0; i < adapter->num_tx_queues; i++)
4587 set_bit(__IXGBE_FDIR_INIT_DONE,
4588 &(adapter->tx_ring[i].reinit_state));
4589 } else {
4590 DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, "
4591 "ignored adding FDIR ATR filters \n");
4592 }
4593 /* Done FDIR Re-initialization, enable transmits */
4594 netif_tx_start_all_queues(adapter->netdev);
4595}
4596
4597/**
Alexander Duyck69888672008-09-11 20:05:39 -07004598 * ixgbe_watchdog_task - worker thread to bring link up
4599 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004600 **/
4601static void ixgbe_watchdog_task(struct work_struct *work)
4602{
4603 struct ixgbe_adapter *adapter = container_of(work,
4604 struct ixgbe_adapter,
4605 watchdog_task);
4606 struct net_device *netdev = adapter->netdev;
4607 struct ixgbe_hw *hw = &adapter->hw;
4608 u32 link_speed = adapter->link_speed;
4609 bool link_up = adapter->link_up;
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004610 int i;
4611 struct ixgbe_ring *tx_ring;
4612 int some_tx_pending = 0;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004613
4614 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
4615
4616 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4617 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004618 if (link_up) {
4619#ifdef CONFIG_DCB
4620 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4621 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004622 hw->mac.ops.fc_enable(hw, i);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004623 } else {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004624 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004625 }
4626#else
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004627 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004628#endif
4629 }
4630
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004631 if (link_up ||
4632 time_after(jiffies, (adapter->link_check_timeout +
4633 IXGBE_TRY_LINK_TIMEOUT))) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004634 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004635 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004636 }
4637 adapter->link_up = link_up;
4638 adapter->link_speed = link_speed;
4639 }
Auke Kok9a799d72007-09-15 14:07:45 -07004640
4641 if (link_up) {
4642 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004643 bool flow_rx, flow_tx;
4644
4645 if (hw->mac.type == ixgbe_mac_82599EB) {
4646 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4647 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
4648 flow_rx = (mflcn & IXGBE_MFLCN_RFCE);
4649 flow_tx = (fccfg & IXGBE_FCCFG_TFCE_802_3X);
4650 } else {
4651 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4652 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
4653 flow_rx = (frctl & IXGBE_FCTRL_RFCE);
4654 flow_tx = (rmcs & IXGBE_RMCS_TFCE_802_3X);
4655 }
4656
Jeff Kirshera46e5342008-11-27 00:22:21 -08004657 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
4658 "Flow Control: %s\n",
4659 netdev->name,
4660 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
4661 "10 Gbps" :
4662 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
4663 "1 Gbps" : "unknown speed")),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004664 ((flow_rx && flow_tx) ? "RX/TX" :
4665 (flow_rx ? "RX" :
4666 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07004667
4668 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004669 } else {
4670 /* Force detection of hung controller */
4671 adapter->detect_tx_hung = true;
4672 }
4673 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004674 adapter->link_up = false;
4675 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004676 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08004677 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
4678 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07004679 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004680 }
4681 }
4682
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004683 if (!netif_carrier_ok(netdev)) {
4684 for (i = 0; i < adapter->num_tx_queues; i++) {
4685 tx_ring = &adapter->tx_ring[i];
4686 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
4687 some_tx_pending = 1;
4688 break;
4689 }
4690 }
4691
4692 if (some_tx_pending) {
4693 /* We've lost link, so the controller stops DMA,
4694 * but we've got queued Tx work that's never going
4695 * to get done, so reset controller to flush Tx.
4696 * (Do the reset outside of interrupt context).
4697 */
4698 schedule_work(&adapter->reset_task);
4699 }
4700 }
4701
Auke Kok9a799d72007-09-15 14:07:45 -07004702 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004703 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07004704}
4705
Auke Kok9a799d72007-09-15 14:07:45 -07004706static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004707 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
4708 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004709{
4710 struct ixgbe_adv_tx_context_desc *context_desc;
4711 unsigned int i;
4712 int err;
4713 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004714 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
4715 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07004716
4717 if (skb_is_gso(skb)) {
4718 if (skb_header_cloned(skb)) {
4719 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4720 if (err)
4721 return err;
4722 }
4723 l4len = tcp_hdrlen(skb);
4724 *hdr_len += l4len;
4725
Al Viro8327d002007-12-10 18:54:12 +00004726 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004727 struct iphdr *iph = ip_hdr(skb);
4728 iph->tot_len = 0;
4729 iph->check = 0;
4730 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004731 iph->daddr, 0,
4732 IPPROTO_TCP,
4733 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004734 adapter->hw_tso_ctxt++;
4735 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
4736 ipv6_hdr(skb)->payload_len = 0;
4737 tcp_hdr(skb)->check =
4738 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004739 &ipv6_hdr(skb)->daddr,
4740 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004741 adapter->hw_tso6_ctxt++;
4742 }
4743
4744 i = tx_ring->next_to_use;
4745
4746 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4747 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4748
4749 /* VLAN MACLEN IPLEN */
4750 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4751 vlan_macip_lens |=
4752 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4753 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004754 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004755 *hdr_len += skb_network_offset(skb);
4756 vlan_macip_lens |=
4757 (skb_transport_header(skb) - skb_network_header(skb));
4758 *hdr_len +=
4759 (skb_transport_header(skb) - skb_network_header(skb));
4760 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4761 context_desc->seqnum_seed = 0;
4762
4763 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004764 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004765 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004766
Al Viro8327d002007-12-10 18:54:12 +00004767 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004768 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4769 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
4770 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4771
4772 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004773 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07004774 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
4775 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004776 /* use index 1 for TSO */
4777 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004778 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4779
4780 tx_buffer_info->time_stamp = jiffies;
4781 tx_buffer_info->next_to_watch = i;
4782
4783 i++;
4784 if (i == tx_ring->count)
4785 i = 0;
4786 tx_ring->next_to_use = i;
4787
4788 return true;
4789 }
4790 return false;
4791}
4792
4793static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004794 struct ixgbe_ring *tx_ring,
4795 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07004796{
4797 struct ixgbe_adv_tx_context_desc *context_desc;
4798 unsigned int i;
4799 struct ixgbe_tx_buffer *tx_buffer_info;
4800 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4801
4802 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4803 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4804 i = tx_ring->next_to_use;
4805 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4806 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4807
4808 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4809 vlan_macip_lens |=
4810 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4811 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004812 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004813 if (skb->ip_summed == CHECKSUM_PARTIAL)
4814 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004815 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07004816
4817 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4818 context_desc->seqnum_seed = 0;
4819
4820 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004821 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004822
4823 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08004824 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004825 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07004826 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08004827 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4828 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004829 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004830 else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
4831 type_tucmd_mlhl |=
4832 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004833 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004834 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08004835 /* XXX what about other V6 headers?? */
4836 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4837 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004838 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004839 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
4840 type_tucmd_mlhl |=
4841 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004842 break;
Auke Kok41825d72008-02-12 15:20:33 -08004843 default:
4844 if (unlikely(net_ratelimit())) {
4845 DPRINTK(PROBE, WARNING,
4846 "partial checksum but proto=%x!\n",
4847 skb->protocol);
4848 }
4849 break;
4850 }
Auke Kok9a799d72007-09-15 14:07:45 -07004851 }
4852
4853 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004854 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07004855 context_desc->mss_l4len_idx = 0;
4856
4857 tx_buffer_info->time_stamp = jiffies;
4858 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004859
Auke Kok9a799d72007-09-15 14:07:45 -07004860 adapter->hw_csum_tx_good++;
4861 i++;
4862 if (i == tx_ring->count)
4863 i = 0;
4864 tx_ring->next_to_use = i;
4865
4866 return true;
4867 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004868
Auke Kok9a799d72007-09-15 14:07:45 -07004869 return false;
4870}
4871
4872static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004873 struct ixgbe_ring *tx_ring,
Yi Zoueacd73f2009-05-13 13:11:06 +00004874 struct sk_buff *skb, u32 tx_flags,
4875 unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07004876{
4877 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00004878 unsigned int len;
4879 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07004880 unsigned int offset = 0, size, count = 0, i;
4881 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
4882 unsigned int f;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004883 dma_addr_t *map;
Auke Kok9a799d72007-09-15 14:07:45 -07004884
4885 i = tx_ring->next_to_use;
4886
Alexander Duyck44df32c2009-03-31 21:34:23 +00004887 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
4888 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
4889 return 0;
4890 }
4891
4892 map = skb_shinfo(skb)->dma_maps;
4893
Yi Zoueacd73f2009-05-13 13:11:06 +00004894 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
4895 /* excluding fcoe_crc_eof for FCoE */
4896 total -= sizeof(struct fcoe_crc_eof);
4897
4898 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07004899 while (len) {
4900 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4901 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4902
4903 tx_buffer_info->length = size;
Eric Dumazet042a53a2009-06-05 04:04:16 +00004904 tx_buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004905 tx_buffer_info->time_stamp = jiffies;
4906 tx_buffer_info->next_to_watch = i;
4907
4908 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00004909 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07004910 offset += size;
4911 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004912
4913 if (len) {
4914 i++;
4915 if (i == tx_ring->count)
4916 i = 0;
4917 }
Auke Kok9a799d72007-09-15 14:07:45 -07004918 }
4919
4920 for (f = 0; f < nr_frags; f++) {
4921 struct skb_frag_struct *frag;
4922
4923 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00004924 len = min((unsigned int)frag->size, total);
Alexander Duyck44df32c2009-03-31 21:34:23 +00004925 offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004926
4927 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00004928 i++;
4929 if (i == tx_ring->count)
4930 i = 0;
4931
Auke Kok9a799d72007-09-15 14:07:45 -07004932 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4933 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4934
4935 tx_buffer_info->length = size;
Eric Dumazet042a53a2009-06-05 04:04:16 +00004936 tx_buffer_info->dma = map[f] + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004937 tx_buffer_info->time_stamp = jiffies;
4938 tx_buffer_info->next_to_watch = i;
4939
4940 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00004941 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07004942 offset += size;
4943 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07004944 }
Yi Zoueacd73f2009-05-13 13:11:06 +00004945 if (total == 0)
4946 break;
Auke Kok9a799d72007-09-15 14:07:45 -07004947 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00004948
Auke Kok9a799d72007-09-15 14:07:45 -07004949 tx_ring->tx_buffer_info[i].skb = skb;
4950 tx_ring->tx_buffer_info[first].next_to_watch = i;
4951
4952 return count;
4953}
4954
4955static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004956 struct ixgbe_ring *tx_ring,
4957 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004958{
4959 union ixgbe_adv_tx_desc *tx_desc = NULL;
4960 struct ixgbe_tx_buffer *tx_buffer_info;
4961 u32 olinfo_status = 0, cmd_type_len = 0;
4962 unsigned int i;
4963 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
4964
4965 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
4966
4967 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
4968
4969 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4970 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
4971
4972 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
4973 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4974
4975 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004976 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004977
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004978 /* use index 1 context for tso */
4979 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004980 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
4981 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004982 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004983
4984 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
4985 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004986 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004987
Yi Zoueacd73f2009-05-13 13:11:06 +00004988 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
4989 olinfo_status |= IXGBE_ADVTXD_CC;
4990 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
4991 if (tx_flags & IXGBE_TX_FLAGS_FSO)
4992 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4993 }
4994
Auke Kok9a799d72007-09-15 14:07:45 -07004995 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
4996
4997 i = tx_ring->next_to_use;
4998 while (count--) {
4999 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5000 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
5001 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
5002 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005003 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07005004 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07005005 i++;
5006 if (i == tx_ring->count)
5007 i = 0;
5008 }
5009
5010 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
5011
5012 /*
5013 * Force memory writes to complete before letting h/w
5014 * know there are new descriptors to fetch. (Only
5015 * applicable for weak-ordered memory model archs,
5016 * such as IA-64).
5017 */
5018 wmb();
5019
5020 tx_ring->next_to_use = i;
5021 writel(i, adapter->hw.hw_addr + tx_ring->tail);
5022}
5023
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005024static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
5025 int queue, u32 tx_flags)
5026{
5027 /* Right now, we support IPv4 only */
5028 struct ixgbe_atr_input atr_input;
5029 struct tcphdr *th;
5030 struct udphdr *uh;
5031 struct iphdr *iph = ip_hdr(skb);
5032 struct ethhdr *eth = (struct ethhdr *)skb->data;
5033 u16 vlan_id, src_port, dst_port, flex_bytes;
5034 u32 src_ipv4_addr, dst_ipv4_addr;
5035 u8 l4type = 0;
5036
5037 /* check if we're UDP or TCP */
5038 if (iph->protocol == IPPROTO_TCP) {
5039 th = tcp_hdr(skb);
5040 src_port = th->source;
5041 dst_port = th->dest;
5042 l4type |= IXGBE_ATR_L4TYPE_TCP;
5043 /* l4type IPv4 type is 0, no need to assign */
5044 } else if(iph->protocol == IPPROTO_UDP) {
5045 uh = udp_hdr(skb);
5046 src_port = uh->source;
5047 dst_port = uh->dest;
5048 l4type |= IXGBE_ATR_L4TYPE_UDP;
5049 /* l4type IPv4 type is 0, no need to assign */
5050 } else {
5051 /* Unsupported L4 header, just bail here */
5052 return;
5053 }
5054
5055 memset(&atr_input, 0, sizeof(struct ixgbe_atr_input));
5056
5057 vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >>
5058 IXGBE_TX_FLAGS_VLAN_SHIFT;
5059 src_ipv4_addr = iph->saddr;
5060 dst_ipv4_addr = iph->daddr;
5061 flex_bytes = eth->h_proto;
5062
5063 ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
5064 ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
5065 ixgbe_atr_set_dst_port_82599(&atr_input, src_port);
5066 ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes);
5067 ixgbe_atr_set_l4type_82599(&atr_input, l4type);
5068 /* src and dst are inverted, think how the receiver sees them */
5069 ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr);
5070 ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr);
5071
5072 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
5073 ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue);
5074}
5075
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005076static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005077 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005078{
5079 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5080
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005081 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005082 /* Herbert's original patch had:
5083 * smp_mb__after_netif_stop_queue();
5084 * but since that doesn't exist yet, just open code it. */
5085 smp_mb();
5086
5087 /* We need to check again in a case another CPU has just
5088 * made room available. */
5089 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
5090 return -EBUSY;
5091
5092 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07005093 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005094 ++adapter->restart_queue;
5095 return 0;
5096}
5097
5098static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005099 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005100{
5101 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
5102 return 0;
5103 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
5104}
5105
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005106static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
5107{
5108 struct ixgbe_adapter *adapter = netdev_priv(dev);
5109
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005110 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
5111 return smp_processor_id();
5112
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005113 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5114 return 0; /* All traffic should default to class 0 */
5115
5116 return skb_tx_hash(dev, skb);
5117}
5118
Auke Kok9a799d72007-09-15 14:07:45 -07005119static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
5120{
5121 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5122 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07005123 unsigned int first;
5124 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005125 u8 hdr_len = 0;
5126 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07005127 int count = 0;
5128 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005129
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005130 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
5131 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005132 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5133 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
5134 tx_flags |= (skb->queue_mapping << 13);
5135 }
5136 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5137 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5138 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Lucy Liu60127862009-07-22 14:07:33 +00005139 if (skb->priority != TC_PRIO_CONTROL) {
5140 tx_flags |= (skb->queue_mapping << 13);
5141 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5142 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5143 } else {
5144 skb->queue_mapping =
5145 adapter->ring_feature[RING_F_DCB].indices-1;
5146 }
Auke Kok9a799d72007-09-15 14:07:45 -07005147 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005148
Lucy Liu60127862009-07-22 14:07:33 +00005149 r_idx = skb->queue_mapping;
5150 tx_ring = &adapter->tx_ring[r_idx];
5151
Yi Zoueacd73f2009-05-13 13:11:06 +00005152 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
5153 (skb->protocol == htons(ETH_P_FCOE)))
5154 tx_flags |= IXGBE_TX_FLAGS_FCOE;
5155
5156 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005157 if (skb_is_gso(skb) ||
5158 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00005159 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
5160 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07005161 count++;
5162
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005163 count += TXD_USE_COUNT(skb_headlen(skb));
5164 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07005165 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
5166
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005167 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07005168 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07005169 return NETDEV_TX_BUSY;
5170 }
Auke Kok9a799d72007-09-15 14:07:45 -07005171
Auke Kok9a799d72007-09-15 14:07:45 -07005172 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00005173 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5174#ifdef IXGBE_FCOE
5175 /* setup tx offload for FCoE */
5176 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5177 if (tso < 0) {
5178 dev_kfree_skb_any(skb);
5179 return NETDEV_TX_OK;
5180 }
5181 if (tso)
5182 tx_flags |= IXGBE_TX_FLAGS_FSO;
5183#endif /* IXGBE_FCOE */
5184 } else {
5185 if (skb->protocol == htons(ETH_P_IP))
5186 tx_flags |= IXGBE_TX_FLAGS_IPV4;
5187 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5188 if (tso < 0) {
5189 dev_kfree_skb_any(skb);
5190 return NETDEV_TX_OK;
5191 }
5192
5193 if (tso)
5194 tx_flags |= IXGBE_TX_FLAGS_TSO;
5195 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
5196 (skb->ip_summed == CHECKSUM_PARTIAL))
5197 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005198 }
5199
Yi Zoueacd73f2009-05-13 13:11:06 +00005200 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005201 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005202 /* add the ATR filter if ATR is on */
5203 if (tx_ring->atr_sample_rate) {
5204 ++tx_ring->atr_count;
5205 if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) &&
5206 test_bit(__IXGBE_FDIR_INIT_DONE,
5207 &tx_ring->reinit_state)) {
5208 ixgbe_atr(adapter, skb, tx_ring->queue_index,
5209 tx_flags);
5210 tx_ring->atr_count = 0;
5211 }
5212 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00005213 ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
5214 hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005215 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07005216
Alexander Duyck44df32c2009-03-31 21:34:23 +00005217 } else {
5218 dev_kfree_skb_any(skb);
5219 tx_ring->tx_buffer_info[first].time_stamp = 0;
5220 tx_ring->next_to_use = first;
5221 }
Auke Kok9a799d72007-09-15 14:07:45 -07005222
5223 return NETDEV_TX_OK;
5224}
5225
5226/**
5227 * ixgbe_get_stats - Get System Network Statistics
5228 * @netdev: network interface device structure
5229 *
5230 * Returns the address of the device statistics structure.
5231 * The statistics are actually updated from the timer callback.
5232 **/
5233static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
5234{
5235 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5236
5237 /* only return the current stats */
5238 return &adapter->net_stats;
5239}
5240
5241/**
5242 * ixgbe_set_mac - Change the Ethernet Address of the NIC
5243 * @netdev: network interface device structure
5244 * @p: pointer to an address structure
5245 *
5246 * Returns 0 on success, negative on failure
5247 **/
5248static int ixgbe_set_mac(struct net_device *netdev, void *p)
5249{
5250 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005251 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005252 struct sockaddr *addr = p;
5253
5254 if (!is_valid_ether_addr(addr->sa_data))
5255 return -EADDRNOTAVAIL;
5256
5257 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005258 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07005259
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005260 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07005261
5262 return 0;
5263}
5264
Ben Hutchings6b73e102009-04-29 08:08:58 +00005265static int
5266ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
5267{
5268 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5269 struct ixgbe_hw *hw = &adapter->hw;
5270 u16 value;
5271 int rc;
5272
5273 if (prtad != hw->phy.mdio.prtad)
5274 return -EINVAL;
5275 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
5276 if (!rc)
5277 rc = value;
5278 return rc;
5279}
5280
5281static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
5282 u16 addr, u16 value)
5283{
5284 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5285 struct ixgbe_hw *hw = &adapter->hw;
5286
5287 if (prtad != hw->phy.mdio.prtad)
5288 return -EINVAL;
5289 return hw->phy.ops.write_reg(hw, addr, devad, value);
5290}
5291
5292static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
5293{
5294 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5295
5296 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
5297}
5298
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005299/**
5300 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00005301 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005302 * @netdev: network interface device structure
5303 *
5304 * Returns non-zero on failure
5305 **/
5306static int ixgbe_add_sanmac_netdev(struct net_device *dev)
5307{
5308 int err = 0;
5309 struct ixgbe_adapter *adapter = netdev_priv(dev);
5310 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5311
5312 if (is_valid_ether_addr(mac->san_addr)) {
5313 rtnl_lock();
5314 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5315 rtnl_unlock();
5316 }
5317 return err;
5318}
5319
5320/**
5321 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00005322 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005323 * @netdev: network interface device structure
5324 *
5325 * Returns non-zero on failure
5326 **/
5327static int ixgbe_del_sanmac_netdev(struct net_device *dev)
5328{
5329 int err = 0;
5330 struct ixgbe_adapter *adapter = netdev_priv(dev);
5331 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5332
5333 if (is_valid_ether_addr(mac->san_addr)) {
5334 rtnl_lock();
5335 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5336 rtnl_unlock();
5337 }
5338 return err;
5339}
5340
Auke Kok9a799d72007-09-15 14:07:45 -07005341#ifdef CONFIG_NET_POLL_CONTROLLER
5342/*
5343 * Polling 'interrupt' - used by things like netconsole to send skbs
5344 * without having to re-enable interrupts. It's not called while
5345 * the interrupt routine is executing.
5346 */
5347static void ixgbe_netpoll(struct net_device *netdev)
5348{
5349 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5350
5351 disable_irq(adapter->pdev->irq);
5352 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
5353 ixgbe_intr(adapter->pdev->irq, netdev);
5354 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
5355 enable_irq(adapter->pdev->irq);
5356}
5357#endif
5358
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005359static const struct net_device_ops ixgbe_netdev_ops = {
5360 .ndo_open = ixgbe_open,
5361 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005362 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005363 .ndo_select_queue = ixgbe_select_queue,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005364 .ndo_get_stats = ixgbe_get_stats,
Chris Leeche90d4002009-03-10 16:00:24 +00005365 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005366 .ndo_set_multicast_list = ixgbe_set_rx_mode,
5367 .ndo_validate_addr = eth_validate_addr,
5368 .ndo_set_mac_address = ixgbe_set_mac,
5369 .ndo_change_mtu = ixgbe_change_mtu,
5370 .ndo_tx_timeout = ixgbe_tx_timeout,
5371 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
5372 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
5373 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00005374 .ndo_do_ioctl = ixgbe_ioctl,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005375#ifdef CONFIG_NET_POLL_CONTROLLER
5376 .ndo_poll_controller = ixgbe_netpoll,
5377#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005378#ifdef IXGBE_FCOE
5379 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
5380 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
5381#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005382};
5383
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005384/**
Auke Kok9a799d72007-09-15 14:07:45 -07005385 * ixgbe_probe - Device Initialization Routine
5386 * @pdev: PCI device information struct
5387 * @ent: entry in ixgbe_pci_tbl
5388 *
5389 * Returns 0 on success, negative on failure
5390 *
5391 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
5392 * The OS initialization, configuring of the adapter private structure,
5393 * and a hardware reset occur.
5394 **/
5395static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005396 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07005397{
5398 struct net_device *netdev;
5399 struct ixgbe_adapter *adapter = NULL;
5400 struct ixgbe_hw *hw;
5401 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07005402 static int cards_found;
5403 int i, err, pci_using_dac;
Yi Zoueacd73f2009-05-13 13:11:06 +00005404#ifdef IXGBE_FCOE
5405 u16 device_caps;
5406#endif
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005407 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07005408
gouji-new9ce77662009-05-06 10:44:45 +00005409 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005410 if (err)
5411 return err;
5412
Yang Hongyang6a355282009-04-06 19:01:13 -07005413 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
5414 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07005415 pci_using_dac = 1;
5416 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07005417 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005418 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -07005419 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005420 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005421 dev_err(&pdev->dev, "No usable DMA "
5422 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005423 goto err_dma;
5424 }
5425 }
5426 pci_using_dac = 0;
5427 }
5428
gouji-new9ce77662009-05-06 10:44:45 +00005429 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
5430 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07005431 if (err) {
gouji-new9ce77662009-05-06 10:44:45 +00005432 dev_err(&pdev->dev,
5433 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07005434 goto err_pci_reg;
5435 }
5436
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005437 err = pci_enable_pcie_error_reporting(pdev);
5438 if (err) {
5439 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
5440 "0x%x\n", err);
5441 /* non-fatal, continue */
5442 }
5443
Auke Kok9a799d72007-09-15 14:07:45 -07005444 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07005445 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005446
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005447 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07005448 if (!netdev) {
5449 err = -ENOMEM;
5450 goto err_alloc_etherdev;
5451 }
5452
Auke Kok9a799d72007-09-15 14:07:45 -07005453 SET_NETDEV_DEV(netdev, &pdev->dev);
5454
5455 pci_set_drvdata(pdev, netdev);
5456 adapter = netdev_priv(netdev);
5457
5458 adapter->netdev = netdev;
5459 adapter->pdev = pdev;
5460 hw = &adapter->hw;
5461 hw->back = adapter;
5462 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
5463
Jeff Kirsher05857982008-09-11 19:57:00 -07005464 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
5465 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07005466 if (!hw->hw_addr) {
5467 err = -EIO;
5468 goto err_ioremap;
5469 }
5470
5471 for (i = 1; i <= 5; i++) {
5472 if (pci_resource_len(pdev, i) == 0)
5473 continue;
5474 }
5475
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005476 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07005477 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005478 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07005479 strcpy(netdev->name, pci_name(pdev));
5480
Auke Kok9a799d72007-09-15 14:07:45 -07005481 adapter->bd_number = cards_found;
5482
Auke Kok9a799d72007-09-15 14:07:45 -07005483 /* Setup hw api */
5484 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005485 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07005486
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005487 /* EEPROM */
5488 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
5489 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
5490 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
5491 if (!(eec & (1 << 8)))
5492 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
5493
5494 /* PHY */
5495 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08005496 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00005497 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
5498 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
5499 hw->phy.mdio.mmds = 0;
5500 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
5501 hw->phy.mdio.dev = netdev;
5502 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
5503 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08005504
5505 /* set up this timer and work struct before calling get_invariants
5506 * which might start the timer
5507 */
5508 init_timer(&adapter->sfp_timer);
5509 adapter->sfp_timer.function = &ixgbe_sfp_timer;
5510 adapter->sfp_timer.data = (unsigned long) adapter;
5511
5512 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005513
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005514 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
5515 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
5516
5517 /* a new SFP+ module arrival, called from GPI SDP2 context */
5518 INIT_WORK(&adapter->sfp_config_module_task,
5519 ixgbe_sfp_config_module_task);
5520
Don Skidmore8ca783a2009-05-26 20:40:47 -07005521 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005522
5523 /* setup the private structure */
5524 err = ixgbe_sw_init(adapter);
5525 if (err)
5526 goto err_sw_init;
5527
Don Skidmorebf069c92009-05-07 10:39:54 +00005528 /*
5529 * If there is a fan on this device and it has failed log the
5530 * failure.
5531 */
5532 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5533 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5534 if (esdp & IXGBE_ESDP_SDP1)
5535 DPRINTK(PROBE, CRIT,
5536 "Fan has stopped, replace the adapter\n");
5537 }
5538
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005539 /* reset_hw fills in the perm_addr as well */
5540 err = hw->mac.ops.reset_hw(hw);
Don Skidmore8ca783a2009-05-26 20:40:47 -07005541 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
5542 hw->mac.type == ixgbe_mac_82598EB) {
5543 /*
5544 * Start a kernel thread to watch for a module to arrive.
5545 * Only do this for 82598, since 82599 will generate
5546 * interrupts on module arrival.
5547 */
5548 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5549 mod_timer(&adapter->sfp_timer,
5550 round_jiffies(jiffies + (2 * HZ)));
5551 err = 0;
5552 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00005553 dev_err(&adapter->pdev->dev, "failed to initialize because "
5554 "an unsupported SFP+ module type was detected.\n"
5555 "Reload the driver after installing a supported "
5556 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005557 goto err_sw_init;
5558 } else if (err) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005559 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
5560 goto err_sw_init;
5561 }
5562
Auke Kok9a799d72007-09-15 14:07:45 -07005563 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005564 NETIF_F_IP_CSUM |
5565 NETIF_F_HW_VLAN_TX |
5566 NETIF_F_HW_VLAN_RX |
5567 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07005568
Jesse Brandeburge9990a92008-08-26 04:27:24 -07005569 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005570 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07005571 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08005572 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005573
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00005574 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
5575 netdev->features |= NETIF_F_SCTP_CSUM;
5576
Jeff Kirsherad31c402008-06-05 04:05:30 -07005577 netdev->vlan_features |= NETIF_F_TSO;
5578 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07005579 netdev->vlan_features |= NETIF_F_IP_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005580 netdev->vlan_features |= NETIF_F_SG;
5581
Alexander Duyck2f90b862008-11-20 20:52:10 -08005582 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5583 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
5584
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005585#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005586 netdev->dcbnl_ops = &dcbnl_ops;
5587#endif
5588
Yi Zoueacd73f2009-05-13 13:11:06 +00005589#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005590 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00005591 if (hw->mac.ops.get_device_caps) {
5592 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00005593 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
5594 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00005595 }
5596 }
5597#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005598 if (pci_using_dac)
5599 netdev->features |= NETIF_F_HIGHDMA;
5600
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00005601 if (adapter->flags & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00005602 netdev->features |= NETIF_F_LRO;
5603
Auke Kok9a799d72007-09-15 14:07:45 -07005604 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005605 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07005606 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
5607 err = -EIO;
5608 goto err_eeprom;
5609 }
5610
5611 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
5612 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
5613
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005614 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
5615 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005616 err = -EIO;
5617 goto err_eeprom;
5618 }
5619
5620 init_timer(&adapter->watchdog_timer);
5621 adapter->watchdog_timer.function = &ixgbe_watchdog;
5622 adapter->watchdog_timer.data = (unsigned long)adapter;
5623
5624 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005625 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005626
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005627 err = ixgbe_init_interrupt_scheme(adapter);
5628 if (err)
5629 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07005630
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005631 switch (pdev->device) {
5632 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005633 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
5634 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
Peter P Waskiewicz Jrbdf0a552009-06-04 11:09:58 +00005635 /* Enable ACPI wakeup in GRC */
5636 IXGBE_WRITE_REG(hw, IXGBE_GRC,
5637 (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005638 break;
5639 default:
5640 adapter->wol = 0;
5641 break;
5642 }
5643 device_init_wakeup(&adapter->pdev->dev, true);
5644 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
5645
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005646 /* pick up the PCI bus settings for reporting later */
5647 hw->mac.ops.get_bus_info(hw);
5648
Auke Kok9a799d72007-09-15 14:07:45 -07005649 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07005650 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005651 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
5652 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
5653 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
5654 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
5655 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005656 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07005657 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005658 ixgbe_read_pba_num_generic(hw, &part_num);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005659 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
5660 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
5661 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
5662 (part_num >> 8), (part_num & 0xff));
5663 else
5664 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
5665 hw->mac.type, hw->phy.type,
5666 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07005667
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005668 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Auke Kok0c254d82008-02-11 09:25:56 -08005669 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005670 "this card is not sufficient for optimal "
5671 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005672 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005673 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005674 }
5675
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08005676 /* save off EEPROM version number */
5677 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
5678
Auke Kok9a799d72007-09-15 14:07:45 -07005679 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005680 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005681
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005682 if (err == IXGBE_ERR_EEPROM_VERSION) {
5683 /* We are running on a pre-production device, log a warning */
5684 dev_warn(&pdev->dev, "This device is a pre-production "
5685 "adapter/LOM. Please be aware there may be issues "
5686 "associated with your hardware. If you are "
5687 "experiencing problems please contact your Intel or "
5688 "hardware representative who provided you with this "
5689 "hardware.\n");
5690 }
Auke Kok9a799d72007-09-15 14:07:45 -07005691 strcpy(netdev->name, "eth%d");
5692 err = register_netdev(netdev);
5693 if (err)
5694 goto err_register;
5695
Jesse Brandeburg54386462009-04-17 20:44:27 +00005696 /* carrier off reporting is important to ethtool even BEFORE open */
5697 netif_carrier_off(netdev);
5698
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005699 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5700 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5701 INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
5702
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005703#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03005704 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005705 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005706 ixgbe_setup_dca(adapter);
5707 }
5708#endif
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005709 /* add san mac addr to netdev */
5710 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005711
5712 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
5713 cards_found++;
5714 return 0;
5715
5716err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005717 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005718 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005719err_sw_init:
5720err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08005721 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5722 del_timer_sync(&adapter->sfp_timer);
5723 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005724 cancel_work_sync(&adapter->multispeed_fiber_task);
5725 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005726 iounmap(hw->hw_addr);
5727err_ioremap:
5728 free_netdev(netdev);
5729err_alloc_etherdev:
gouji-new9ce77662009-05-06 10:44:45 +00005730 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5731 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005732err_pci_reg:
5733err_dma:
5734 pci_disable_device(pdev);
5735 return err;
5736}
5737
5738/**
5739 * ixgbe_remove - Device Removal Routine
5740 * @pdev: PCI device information struct
5741 *
5742 * ixgbe_remove is called by the PCI subsystem to alert the driver
5743 * that it should release a PCI device. The could be caused by a
5744 * Hot-Plug event, or because the driver is going to be removed from
5745 * memory.
5746 **/
5747static void __devexit ixgbe_remove(struct pci_dev *pdev)
5748{
5749 struct net_device *netdev = pci_get_drvdata(pdev);
5750 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005751 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005752
5753 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08005754 /* clear the module not found bit to make sure the worker won't
5755 * reschedule
5756 */
5757 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07005758 del_timer_sync(&adapter->watchdog_timer);
5759
Donald Skidmorec4900be2008-11-20 21:11:42 -08005760 del_timer_sync(&adapter->sfp_timer);
5761 cancel_work_sync(&adapter->watchdog_task);
5762 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005763 cancel_work_sync(&adapter->multispeed_fiber_task);
5764 cancel_work_sync(&adapter->sfp_config_module_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005765 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5766 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5767 cancel_work_sync(&adapter->fdir_reinit_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005768 flush_scheduled_work();
5769
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005770#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005771 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
5772 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
5773 dca_remove_requester(&pdev->dev);
5774 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
5775 }
5776
5777#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005778#ifdef IXGBE_FCOE
5779 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
5780 ixgbe_cleanup_fcoe(adapter);
5781
5782#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005783
5784 /* remove the added san mac */
5785 ixgbe_del_sanmac_netdev(netdev);
5786
Donald Skidmorec4900be2008-11-20 21:11:42 -08005787 if (netdev->reg_state == NETREG_REGISTERED)
5788 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005789
Alexander Duyck7a921c92009-05-06 10:43:28 +00005790 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005791
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005792 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005793
5794 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00005795 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5796 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005797
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005798 DPRINTK(PROBE, INFO, "complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005799
Auke Kok9a799d72007-09-15 14:07:45 -07005800 free_netdev(netdev);
5801
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005802 err = pci_disable_pcie_error_reporting(pdev);
5803 if (err)
5804 dev_err(&pdev->dev,
5805 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
5806
Auke Kok9a799d72007-09-15 14:07:45 -07005807 pci_disable_device(pdev);
5808}
5809
5810/**
5811 * ixgbe_io_error_detected - called when PCI error is detected
5812 * @pdev: Pointer to PCI device
5813 * @state: The current pci connection state
5814 *
5815 * This function is called after a PCI bus error affecting
5816 * this device has been detected.
5817 */
5818static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005819 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07005820{
5821 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005822 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005823
5824 netif_device_detach(netdev);
5825
Breno Leitao3044b8d2009-05-06 10:44:26 +00005826 if (state == pci_channel_io_perm_failure)
5827 return PCI_ERS_RESULT_DISCONNECT;
5828
Auke Kok9a799d72007-09-15 14:07:45 -07005829 if (netif_running(netdev))
5830 ixgbe_down(adapter);
5831 pci_disable_device(pdev);
5832
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005833 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07005834 return PCI_ERS_RESULT_NEED_RESET;
5835}
5836
5837/**
5838 * ixgbe_io_slot_reset - called after the pci bus has been reset.
5839 * @pdev: Pointer to PCI device
5840 *
5841 * Restart the card from scratch, as if from a cold-boot.
5842 */
5843static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
5844{
5845 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005846 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005847 pci_ers_result_t result;
5848 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005849
gouji-new9ce77662009-05-06 10:44:45 +00005850 if (pci_enable_device_mem(pdev)) {
Auke Kok9a799d72007-09-15 14:07:45 -07005851 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005852 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005853 result = PCI_ERS_RESULT_DISCONNECT;
5854 } else {
5855 pci_set_master(pdev);
5856 pci_restore_state(pdev);
5857
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005858 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005859
5860 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00005861 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005862 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07005863 }
Auke Kok9a799d72007-09-15 14:07:45 -07005864
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005865 err = pci_cleanup_aer_uncorrect_error_status(pdev);
5866 if (err) {
5867 dev_err(&pdev->dev,
5868 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
5869 /* non-fatal, continue */
5870 }
Auke Kok9a799d72007-09-15 14:07:45 -07005871
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005872 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07005873}
5874
5875/**
5876 * ixgbe_io_resume - called when traffic can start flowing again.
5877 * @pdev: Pointer to PCI device
5878 *
5879 * This callback is called when the error recovery driver tells us that
5880 * its OK to resume normal operation.
5881 */
5882static void ixgbe_io_resume(struct pci_dev *pdev)
5883{
5884 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005885 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005886
5887 if (netif_running(netdev)) {
5888 if (ixgbe_up(adapter)) {
5889 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
5890 return;
5891 }
5892 }
5893
5894 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005895}
5896
5897static struct pci_error_handlers ixgbe_err_handler = {
5898 .error_detected = ixgbe_io_error_detected,
5899 .slot_reset = ixgbe_io_slot_reset,
5900 .resume = ixgbe_io_resume,
5901};
5902
5903static struct pci_driver ixgbe_driver = {
5904 .name = ixgbe_driver_name,
5905 .id_table = ixgbe_pci_tbl,
5906 .probe = ixgbe_probe,
5907 .remove = __devexit_p(ixgbe_remove),
5908#ifdef CONFIG_PM
5909 .suspend = ixgbe_suspend,
5910 .resume = ixgbe_resume,
5911#endif
5912 .shutdown = ixgbe_shutdown,
5913 .err_handler = &ixgbe_err_handler
5914};
5915
5916/**
5917 * ixgbe_init_module - Driver Registration Routine
5918 *
5919 * ixgbe_init_module is the first routine called when the driver is
5920 * loaded. All it does is register with the PCI subsystem.
5921 **/
5922static int __init ixgbe_init_module(void)
5923{
5924 int ret;
5925 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
5926 ixgbe_driver_string, ixgbe_driver_version);
5927
5928 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
5929
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005930#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005931 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005932#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005933
Auke Kok9a799d72007-09-15 14:07:45 -07005934 ret = pci_register_driver(&ixgbe_driver);
5935 return ret;
5936}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005937
Auke Kok9a799d72007-09-15 14:07:45 -07005938module_init(ixgbe_init_module);
5939
5940/**
5941 * ixgbe_exit_module - Driver Exit Cleanup Routine
5942 *
5943 * ixgbe_exit_module is called just before the driver is removed
5944 * from memory.
5945 **/
5946static void __exit ixgbe_exit_module(void)
5947{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005948#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005949 dca_unregister_notify(&dca_notifier);
5950#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005951 pci_unregister_driver(&ixgbe_driver);
5952}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005953
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005954#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005955static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005956 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005957{
5958 int ret_val;
5959
5960 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005961 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005962
5963 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
5964}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005965
Alexander Duyckb4533682009-03-31 21:32:42 +00005966#endif /* CONFIG_IXGBE_DCA */
5967#ifdef DEBUG
5968/**
5969 * ixgbe_get_hw_dev_name - return device name string
5970 * used by hardware layer to print debugging information
5971 **/
5972char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
5973{
5974 struct ixgbe_adapter *adapter = hw->back;
5975 return adapter->netdev->name;
5976}
5977
5978#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005979module_exit(ixgbe_exit_module);
5980
5981/* ixgbe_main.c */