blob: 45bf8b9716e39b0172fc2ac883967437b22ce8e4 [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 Jrbbf50e42009-07-16 15:51:11 +000052#define DRV_VERSION "2.0.37-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 },
Peter P Waskiewicz Jr3845bec2009-07-16 15:50:52 +000078 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
79 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070080 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070081 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070082 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
83 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080084 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
85 board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
87 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070088 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
89 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080090 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
91 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -080092 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
93 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +000094 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
95 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +000096 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
97 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +000098 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
99 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700100
101 /* required last entry */
102 {0, }
103};
104MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
105
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400106#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800107static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700108 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800109static struct notifier_block dca_notifier = {
110 .notifier_call = ixgbe_notify_dca,
111 .next = NULL,
112 .priority = 0
113};
114#endif
115
Auke Kok9a799d72007-09-15 14:07:45 -0700116MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
117MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
118MODULE_LICENSE("GPL");
119MODULE_VERSION(DRV_VERSION);
120
121#define DEFAULT_DEBUG_LEVEL_SHIFT 3
122
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800123static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
124{
125 u32 ctrl_ext;
126
127 /* Let firmware take over control of h/w */
128 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
129 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700130 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800131}
132
133static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
134{
135 u32 ctrl_ext;
136
137 /* Let firmware know the driver has taken over */
138 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
139 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700140 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800141}
Auke Kok9a799d72007-09-15 14:07:45 -0700142
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000143/*
144 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
145 * @adapter: pointer to adapter struct
146 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
147 * @queue: queue to map the corresponding interrupt to
148 * @msix_vector: the vector to map to the corresponding queue
149 *
150 */
151static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
152 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700153{
154 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000155 struct ixgbe_hw *hw = &adapter->hw;
156 switch (hw->mac.type) {
157 case ixgbe_mac_82598EB:
158 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
159 if (direction == -1)
160 direction = 0;
161 index = (((direction * 64) + queue) >> 2) & 0x1F;
162 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
163 ivar &= ~(0xFF << (8 * (queue & 0x3)));
164 ivar |= (msix_vector << (8 * (queue & 0x3)));
165 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
166 break;
167 case ixgbe_mac_82599EB:
168 if (direction == -1) {
169 /* other causes */
170 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
171 index = ((queue & 1) * 8);
172 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
173 ivar &= ~(0xFF << index);
174 ivar |= (msix_vector << index);
175 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
176 break;
177 } else {
178 /* tx or rx causes */
179 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
180 index = ((16 * (queue & 1)) + (8 * direction));
181 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
182 ivar &= ~(0xFF << index);
183 ivar |= (msix_vector << index);
184 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
185 break;
186 }
187 default:
188 break;
189 }
Auke Kok9a799d72007-09-15 14:07:45 -0700190}
191
Alexander Duyckfe49f042009-06-04 16:00:09 +0000192static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
193 u64 qmask)
194{
195 u32 mask;
196
197 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
198 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
199 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
200 } else {
201 mask = (qmask & 0xFFFFFFFF);
202 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
203 mask = (qmask >> 32);
204 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
205 }
206}
207
Auke Kok9a799d72007-09-15 14:07:45 -0700208static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700209 struct ixgbe_tx_buffer
210 *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700211{
Alexander Duyck44df32c2009-03-31 21:34:23 +0000212 tx_buffer_info->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700213 if (tx_buffer_info->skb) {
Alexander Duyck44df32c2009-03-31 21:34:23 +0000214 skb_dma_unmap(&adapter->pdev->dev, tx_buffer_info->skb,
215 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700216 dev_kfree_skb_any(tx_buffer_info->skb);
217 tx_buffer_info->skb = NULL;
218 }
Alexander Duyck44df32c2009-03-31 21:34:23 +0000219 tx_buffer_info->time_stamp = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700220 /* tx_buffer_info must be completely set up in the transmit path */
221}
222
223static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700224 struct ixgbe_ring *tx_ring,
225 unsigned int eop)
Auke Kok9a799d72007-09-15 14:07:45 -0700226{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700227 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700228
Auke Kok9a799d72007-09-15 14:07:45 -0700229 /* Detect a transmit hang in hardware, this serializes the
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700230 * check with the clearing of time_stamp and movement of eop */
Auke Kok9a799d72007-09-15 14:07:45 -0700231 adapter->detect_tx_hung = false;
Alexander Duyck44df32c2009-03-31 21:34:23 +0000232 if (tx_ring->tx_buffer_info[eop].time_stamp &&
Auke Kok9a799d72007-09-15 14:07:45 -0700233 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
234 !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) {
235 /* detected Tx unit hang */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700236 union ixgbe_adv_tx_desc *tx_desc;
237 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
Auke Kok9a799d72007-09-15 14:07:45 -0700238 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700239 " Tx Queue <%d>\n"
240 " TDH, TDT <%x>, <%x>\n"
Auke Kok9a799d72007-09-15 14:07:45 -0700241 " next_to_use <%x>\n"
242 " next_to_clean <%x>\n"
243 "tx_buffer_info[next_to_clean]\n"
244 " time_stamp <%lx>\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700245 " jiffies <%lx>\n",
246 tx_ring->queue_index,
Alexander Duyck44df32c2009-03-31 21:34:23 +0000247 IXGBE_READ_REG(hw, tx_ring->head),
248 IXGBE_READ_REG(hw, tx_ring->tail),
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700249 tx_ring->next_to_use, eop,
250 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
Auke Kok9a799d72007-09-15 14:07:45 -0700251 return true;
252 }
253
254 return false;
255}
256
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700257#define IXGBE_MAX_TXD_PWR 14
258#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800259
260/* Tx Descriptors needed, worst case */
261#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
262 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
263#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700264 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800265
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700266static void ixgbe_tx_timeout(struct net_device *netdev);
267
Auke Kok9a799d72007-09-15 14:07:45 -0700268/**
269 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000270 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700271 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700272 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000273static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700274 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700275{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000276 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700277 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800278 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
279 struct ixgbe_tx_buffer *tx_buffer_info;
280 unsigned int i, eop, count = 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700281 unsigned int total_bytes = 0, total_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700282
283 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800284 eop = tx_ring->tx_buffer_info[i].next_to_watch;
285 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
286
287 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000288 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800289 bool cleaned = false;
290 for ( ; !cleaned; count++) {
291 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700292 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
293 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800294 cleaned = (i == eop);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700295 skb = tx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700296
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800297 if (cleaned && skb) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800298 unsigned int segs, bytecount;
Yi Zou3d8fd382009-06-08 14:38:44 +0000299 unsigned int hlen = skb_headlen(skb);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700300
301 /* gso_segs is currently only valid for tcp */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800302 segs = skb_shinfo(skb)->gso_segs ?: 1;
Yi Zou3d8fd382009-06-08 14:38:44 +0000303#ifdef IXGBE_FCOE
304 /* adjust for FCoE Sequence Offload */
305 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
306 && (skb->protocol == htons(ETH_P_FCOE)) &&
307 skb_is_gso(skb)) {
308 hlen = skb_transport_offset(skb) +
309 sizeof(struct fc_frame_header) +
310 sizeof(struct fcoe_crc_eof);
311 segs = DIV_ROUND_UP(skb->len - hlen,
312 skb_shinfo(skb)->gso_size);
313 }
314#endif /* IXGBE_FCOE */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800315 /* multiply data chunks by size of headers */
Yi Zou3d8fd382009-06-08 14:38:44 +0000316 bytecount = ((segs - 1) * hlen) + skb->len;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700317 total_packets += segs;
318 total_bytes += bytecount;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800319 }
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700320
Auke Kok9a799d72007-09-15 14:07:45 -0700321 ixgbe_unmap_and_free_tx_resource(adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700322 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700323
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800324 tx_desc->wb.status = 0;
325
Auke Kok9a799d72007-09-15 14:07:45 -0700326 i++;
327 if (i == tx_ring->count)
328 i = 0;
329 }
330
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800331 eop = tx_ring->tx_buffer_info[i].next_to_watch;
332 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
333 }
334
Auke Kok9a799d72007-09-15 14:07:45 -0700335 tx_ring->next_to_clean = i;
336
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800337#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700338 if (unlikely(count && netif_carrier_ok(netdev) &&
339 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800340 /* Make sure that anybody stopping the queue after this
341 * sees the new next_to_clean.
342 */
343 smp_mb();
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800344 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
345 !test_bit(__IXGBE_DOWN, &adapter->state)) {
346 netif_wake_subqueue(netdev, tx_ring->queue_index);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700347 ++adapter->restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800348 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800349 }
Auke Kok9a799d72007-09-15 14:07:45 -0700350
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700351 if (adapter->detect_tx_hung) {
352 if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
353 /* schedule immediate reset if we believe we hung */
354 DPRINTK(PROBE, INFO,
355 "tx hang %d detected, resetting adapter\n",
356 adapter->tx_timeout_count + 1);
357 ixgbe_tx_timeout(adapter->netdev);
358 }
359 }
Auke Kok9a799d72007-09-15 14:07:45 -0700360
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700361 /* re-arm the interrupt */
Alexander Duyckfe49f042009-06-04 16:00:09 +0000362 if (count >= tx_ring->work_limit)
363 ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -0700364
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700365 tx_ring->total_bytes += total_bytes;
366 tx_ring->total_packets += total_packets;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700367 tx_ring->stats.packets += total_packets;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800368 tx_ring->stats.bytes += total_bytes;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700369 adapter->net_stats.tx_bytes += total_bytes;
370 adapter->net_stats.tx_packets += total_packets;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000371 return (count < tx_ring->work_limit);
Auke Kok9a799d72007-09-15 14:07:45 -0700372}
373
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400374#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800375static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700376 struct ixgbe_ring *rx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800377{
378 u32 rxctrl;
379 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700380 int q = rx_ring - adapter->rx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800381
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700382 if (rx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800383 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000384 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
385 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
386 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
387 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
388 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
389 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
390 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
391 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800392 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
393 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
Don Skidmore15005a32009-01-19 16:54:13 -0800394 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
395 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000396 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800397 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700398 rx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800399 }
400 put_cpu();
401}
402
403static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700404 struct ixgbe_ring *tx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800405{
406 u32 txctrl;
407 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700408 int q = tx_ring - adapter->tx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800409
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700410 if (tx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800411 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000412 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
413 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
414 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
415 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
416 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
417 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
418 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
419 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800420 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
421 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700422 tx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800423 }
424 put_cpu();
425}
426
427static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
428{
429 int i;
430
431 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
432 return;
433
Alexander Duycke35ec122009-05-21 13:07:12 +0000434 /* always use CB2 mode, difference is masked in the CB driver */
435 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
436
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800437 for (i = 0; i < adapter->num_tx_queues; i++) {
438 adapter->tx_ring[i].cpu = -1;
439 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
440 }
441 for (i = 0; i < adapter->num_rx_queues; i++) {
442 adapter->rx_ring[i].cpu = -1;
443 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
444 }
445}
446
447static int __ixgbe_notify_dca(struct device *dev, void *data)
448{
449 struct net_device *netdev = dev_get_drvdata(dev);
450 struct ixgbe_adapter *adapter = netdev_priv(netdev);
451 unsigned long event = *(unsigned long *)data;
452
453 switch (event) {
454 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700455 /* if we're already enabled, don't do it again */
456 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
457 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300458 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700459 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800460 ixgbe_setup_dca(adapter);
461 break;
462 }
463 /* Fall Through since DCA is disabled. */
464 case DCA_PROVIDER_REMOVE:
465 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
466 dca_remove_requester(dev);
467 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
468 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
469 }
470 break;
471 }
472
Denis V. Lunev652f0932008-03-27 14:39:17 +0300473 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800474}
475
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400476#endif /* CONFIG_IXGBE_DCA */
Auke Kok9a799d72007-09-15 14:07:45 -0700477/**
478 * ixgbe_receive_skb - Send a completed packet up the stack
479 * @adapter: board private structure
480 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700481 * @status: hardware indication of status of receive
482 * @rx_ring: rx descriptor ring (for a specific queue) to setup
483 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -0700484 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800485static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700486 struct sk_buff *skb, u8 status,
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000487 struct ixgbe_ring *ring,
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700488 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -0700489{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800490 struct ixgbe_adapter *adapter = q_vector->adapter;
491 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700492 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
493 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -0700494
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000495 skb_record_rx_queue(skb, ring->queue_index);
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000496 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
Lucy Liu8a62bab2009-08-13 14:09:38 +0000497 if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800498 vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700499 else
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800500 napi_gro_receive(napi, skb);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700501 } else {
Lucy Liu8a62bab2009-08-13 14:09:38 +0000502 if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000503 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
504 else
505 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700506 }
507}
508
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800509/**
510 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
511 * @adapter: address of board private structure
512 * @status_err: hardware indication of status of receive
513 * @skb: skb currently being received and modified
514 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700515static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +0000516 union ixgbe_adv_rx_desc *rx_desc,
517 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700518{
Don Skidmore8bae1b22009-07-23 18:00:39 +0000519 u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
520
Auke Kok9a799d72007-09-15 14:07:45 -0700521 skb->ip_summed = CHECKSUM_NONE;
522
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700523 /* Rx csum disabled */
524 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -0700525 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800526
527 /* if IP and error */
528 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
529 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700530 adapter->hw_csum_rx_error++;
531 return;
532 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800533
534 if (!(status_err & IXGBE_RXD_STAT_L4CS))
535 return;
536
537 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +0000538 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
539
540 /*
541 * 82599 errata, UDP frames with a 0 checksum can be marked as
542 * checksum errors.
543 */
544 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
545 (adapter->hw.mac.type == ixgbe_mac_82599EB))
546 return;
547
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800548 adapter->hw_csum_rx_error++;
549 return;
550 }
551
Auke Kok9a799d72007-09-15 14:07:45 -0700552 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800553 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -0700554 adapter->hw_csum_rx_good++;
555}
556
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000557static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
558 struct ixgbe_ring *rx_ring, u32 val)
559{
560 /*
561 * Force memory writes to complete before letting h/w
562 * know there are new descriptors to fetch. (Only
563 * applicable for weak-ordered memory model archs,
564 * such as IA-64).
565 */
566 wmb();
567 IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
568}
569
Auke Kok9a799d72007-09-15 14:07:45 -0700570/**
571 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
572 * @adapter: address of board private structure
573 **/
574static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700575 struct ixgbe_ring *rx_ring,
576 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700577{
Auke Kok9a799d72007-09-15 14:07:45 -0700578 struct pci_dev *pdev = adapter->pdev;
579 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700580 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700581 unsigned int i;
Auke Kok9a799d72007-09-15 14:07:45 -0700582
583 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700584 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700585
586 while (cleaned_count--) {
587 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
588
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700589 if (!bi->page_dma &&
Yi Zou6e455b892009-08-06 13:05:44 +0000590 (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700591 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700592 bi->page = alloc_page(GFP_ATOMIC);
593 if (!bi->page) {
594 adapter->alloc_rx_page_failed++;
595 goto no_buffers;
596 }
597 bi->page_offset = 0;
598 } else {
599 /* use a half page if we're re-using */
600 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700601 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700602
603 bi->page_dma = pci_map_page(pdev, bi->page,
604 bi->page_offset,
605 (PAGE_SIZE / 2),
606 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700607 }
608
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700609 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800610 struct sk_buff *skb;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000611 skb = netdev_alloc_skb(adapter->netdev,
612 (rx_ring->rx_buf_len +
613 NET_IP_ALIGN));
Auke Kok9a799d72007-09-15 14:07:45 -0700614
615 if (!skb) {
616 adapter->alloc_rx_buff_failed++;
617 goto no_buffers;
618 }
619
620 /*
621 * Make buffer alignment 2 beyond a 16 byte boundary
622 * this will result in a 16 byte aligned IP header after
623 * the 14 byte MAC header is removed
624 */
625 skb_reserve(skb, NET_IP_ALIGN);
626
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700627 bi->skb = skb;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000628 bi->dma = pci_map_single(pdev, skb->data,
629 rx_ring->rx_buf_len,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700630 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700631 }
632 /* Refresh the desc even if buffer_addrs didn't change because
633 * each write-back erases this info. */
Yi Zou6e455b892009-08-06 13:05:44 +0000634 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700635 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
636 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700637 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700638 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700639 }
640
641 i++;
642 if (i == rx_ring->count)
643 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700644 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700645 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700646
Auke Kok9a799d72007-09-15 14:07:45 -0700647no_buffers:
648 if (rx_ring->next_to_use != i) {
649 rx_ring->next_to_use = i;
650 if (i-- == 0)
651 i = (rx_ring->count - 1);
652
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000653 ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700654 }
655}
656
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700657static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
658{
659 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
660}
661
662static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
663{
664 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
665}
666
Alexander Duyckf8212f92009-04-27 22:42:37 +0000667static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
668{
669 return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
670 IXGBE_RXDADV_RSCCNT_MASK) >>
671 IXGBE_RXDADV_RSCCNT_SHIFT;
672}
673
674/**
675 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
676 * @skb: pointer to the last skb in the rsc queue
677 *
678 * This function changes a queue full of hw rsc buffers into a completed
679 * packet. It uses the ->prev pointers to find the first packet and then
680 * turns it into the frag list owner.
681 **/
682static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
683{
684 unsigned int frag_list_size = 0;
685
686 while (skb->prev) {
687 struct sk_buff *prev = skb->prev;
688 frag_list_size += skb->len;
689 skb->prev = NULL;
690 skb = prev;
691 }
692
693 skb_shinfo(skb)->frag_list = skb->next;
694 skb->next = NULL;
695 skb->len += frag_list_size;
696 skb->data_len += frag_list_size;
697 skb->truesize += frag_list_size;
698 return skb;
699}
700
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800701static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700702 struct ixgbe_ring *rx_ring,
703 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700704{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800705 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -0700706 struct pci_dev *pdev = adapter->pdev;
707 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
708 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
709 struct sk_buff *skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000710 unsigned int i, rsc_count = 0;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700711 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700712 u16 hdr_info;
713 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700714 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800715 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +0000716#ifdef IXGBE_FCOE
717 int ddp_bytes = 0;
718#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -0700719
720 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700721 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
722 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
723 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700724
725 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700726 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700727 if (*work_done >= work_to_do)
728 break;
729 (*work_done)++;
730
Yi Zou6e455b892009-08-06 13:05:44 +0000731 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700732 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
733 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700734 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700735 if (hdr_info & IXGBE_RXDADV_SPH)
736 adapter->rx_hdr_split++;
737 if (len > IXGBE_RX_HDR_SIZE)
738 len = IXGBE_RX_HDR_SIZE;
739 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700740 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700741 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700742 }
Auke Kok9a799d72007-09-15 14:07:45 -0700743
744 cleaned = true;
745 skb = rx_buffer_info->skb;
746 prefetch(skb->data - NET_IP_ALIGN);
747 rx_buffer_info->skb = NULL;
748
Alexander Duyck21fa4e62009-06-04 15:59:49 +0000749 if (rx_buffer_info->dma) {
Auke Kok9a799d72007-09-15 14:07:45 -0700750 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800751 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700752 PCI_DMA_FROMDEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000753 rx_buffer_info->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700754 skb_put(skb, len);
755 }
756
757 if (upper_len) {
758 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700759 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700760 rx_buffer_info->page_dma = 0;
761 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700762 rx_buffer_info->page,
763 rx_buffer_info->page_offset,
764 upper_len);
765
766 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
767 (page_count(rx_buffer_info->page) != 1))
768 rx_buffer_info->page = NULL;
769 else
770 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700771
772 skb->len += upper_len;
773 skb->data_len += upper_len;
774 skb->truesize += upper_len;
775 }
776
777 i++;
778 if (i == rx_ring->count)
779 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700780
781 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
782 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -0700783 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000784
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +0000785 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
Alexander Duyckf8212f92009-04-27 22:42:37 +0000786 rsc_count = ixgbe_get_rsc_count(rx_desc);
787
788 if (rsc_count) {
789 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
790 IXGBE_RXDADV_NEXTP_SHIFT;
791 next_buffer = &rx_ring->rx_buffer_info[nextp];
792 rx_ring->rsc_count += (rsc_count - 1);
793 } else {
794 next_buffer = &rx_ring->rx_buffer_info[i];
795 }
796
Auke Kok9a799d72007-09-15 14:07:45 -0700797 if (staterr & IXGBE_RXD_STAT_EOP) {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000798 if (skb->prev)
799 skb = ixgbe_transform_rsc_queue(skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700800 rx_ring->stats.packets++;
801 rx_ring->stats.bytes += skb->len;
802 } else {
Yi Zou6e455b892009-08-06 13:05:44 +0000803 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000804 rx_buffer_info->skb = next_buffer->skb;
805 rx_buffer_info->dma = next_buffer->dma;
806 next_buffer->skb = skb;
807 next_buffer->dma = 0;
808 } else {
809 skb->next = next_buffer->skb;
810 skb->next->prev = skb;
811 }
Auke Kok9a799d72007-09-15 14:07:45 -0700812 adapter->non_eop_descs++;
813 goto next_desc;
814 }
815
816 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
817 dev_kfree_skb_irq(skb);
818 goto next_desc;
819 }
820
Don Skidmore8bae1b22009-07-23 18:00:39 +0000821 ixgbe_rx_checksum(adapter, rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800822
823 /* probably a little skewed due to removing CRC */
824 total_rx_bytes += skb->len;
825 total_rx_packets++;
826
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700827 skb->protocol = eth_type_trans(skb, adapter->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +0000828#ifdef IXGBE_FCOE
829 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +0000830 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
831 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
832 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +0000833 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +0000834 }
Yi Zou332d4a72009-05-13 13:11:53 +0000835#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000836 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700837
838next_desc:
839 rx_desc->wb.upper.status_error = 0;
840
841 /* return some buffers to hardware, one at a time is too slow */
842 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
843 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
844 cleaned_count = 0;
845 }
846
847 /* use prefetched values */
848 rx_desc = next_rxd;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000849 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700850
851 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700852 }
853
Auke Kok9a799d72007-09-15 14:07:45 -0700854 rx_ring->next_to_clean = i;
855 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
856
857 if (cleaned_count)
858 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
859
Yi Zou3d8fd382009-06-08 14:38:44 +0000860#ifdef IXGBE_FCOE
861 /* include DDPed FCoE data */
862 if (ddp_bytes > 0) {
863 unsigned int mss;
864
865 mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) -
866 sizeof(struct fc_frame_header) -
867 sizeof(struct fcoe_crc_eof);
868 if (mss > 512)
869 mss &= ~511;
870 total_rx_bytes += ddp_bytes;
871 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
872 }
873#endif /* IXGBE_FCOE */
874
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800875 rx_ring->total_packets += total_rx_packets;
876 rx_ring->total_bytes += total_rx_bytes;
877 adapter->net_stats.rx_bytes += total_rx_bytes;
878 adapter->net_stats.rx_packets += total_rx_packets;
879
Auke Kok9a799d72007-09-15 14:07:45 -0700880 return cleaned;
881}
882
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800883static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700884/**
885 * ixgbe_configure_msix - Configure MSI-X hardware
886 * @adapter: board private structure
887 *
888 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
889 * interrupts.
890 **/
891static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
892{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800893 struct ixgbe_q_vector *q_vector;
894 int i, j, q_vectors, v_idx, r_idx;
895 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700896
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800897 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
898
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000899 /*
900 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800901 * corresponding register.
902 */
903 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +0000904 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800905 /* XXX for_each_bit(...) */
906 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700907 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800908
909 for (i = 0; i < q_vector->rxr_count; i++) {
910 j = adapter->rx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000911 ixgbe_set_ivar(adapter, 0, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800912 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700913 adapter->num_rx_queues,
914 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800915 }
916 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700917 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800918
919 for (i = 0; i < q_vector->txr_count; i++) {
920 j = adapter->tx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000921 ixgbe_set_ivar(adapter, 1, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800922 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700923 adapter->num_tx_queues,
924 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800925 }
926
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700927 /* if this is a tx only vector halve the interrupt rate */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800928 if (q_vector->txr_count && !q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700929 q_vector->eitr = (adapter->eitr_param >> 1);
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000930 else if (q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700931 /* rx only */
932 q_vector->eitr = adapter->eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800933
Alexander Duyckfe49f042009-06-04 16:00:09 +0000934 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -0700935 }
936
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000937 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
938 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
939 v_idx);
940 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
941 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800942 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -0700943
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700944 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800945 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700946 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800947 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -0700948}
949
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800950enum latency_range {
951 lowest_latency = 0,
952 low_latency = 1,
953 bulk_latency = 2,
954 latency_invalid = 255
955};
956
957/**
958 * ixgbe_update_itr - update the dynamic ITR value based on statistics
959 * @adapter: pointer to adapter
960 * @eitr: eitr setting (ints per sec) to give last timeslice
961 * @itr_setting: current throttle rate in ints/second
962 * @packets: the number of packets during this measurement interval
963 * @bytes: the number of bytes during this measurement interval
964 *
965 * Stores a new ITR value based on packets and byte
966 * counts during the last interrupt. The advantage of per interrupt
967 * computation is faster updates and more accurate ITR for the current
968 * traffic pattern. Constants in this function were computed
969 * based on theoretical maximum wire speed and thresholds were set based
970 * on testing data as well as attempting to minimize response time
971 * while increasing bulk throughput.
972 * this functionality is controlled by the InterruptThrottleRate module
973 * parameter (see ixgbe_param.c)
974 **/
975static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700976 u32 eitr, u8 itr_setting,
977 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800978{
979 unsigned int retval = itr_setting;
980 u32 timepassed_us;
981 u64 bytes_perint;
982
983 if (packets == 0)
984 goto update_itr_done;
985
986
987 /* simple throttlerate management
988 * 0-20MB/s lowest (100000 ints/s)
989 * 20-100MB/s low (20000 ints/s)
990 * 100-1249MB/s bulk (8000 ints/s)
991 */
992 /* what was last interrupt timeslice? */
993 timepassed_us = 1000000/eitr;
994 bytes_perint = bytes / timepassed_us; /* bytes/usec */
995
996 switch (itr_setting) {
997 case lowest_latency:
998 if (bytes_perint > adapter->eitr_low)
999 retval = low_latency;
1000 break;
1001 case low_latency:
1002 if (bytes_perint > adapter->eitr_high)
1003 retval = bulk_latency;
1004 else if (bytes_perint <= adapter->eitr_low)
1005 retval = lowest_latency;
1006 break;
1007 case bulk_latency:
1008 if (bytes_perint <= adapter->eitr_high)
1009 retval = low_latency;
1010 break;
1011 }
1012
1013update_itr_done:
1014 return retval;
1015}
1016
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001017/**
1018 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001019 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001020 *
1021 * This function is made to be called by ethtool and by the driver
1022 * when it needs to update EITR registers at runtime. Hardware
1023 * specific quirks/differences are taken care of here.
1024 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001025void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001026{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001027 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001028 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001029 int v_idx = q_vector->v_idx;
1030 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1031
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001032 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1033 /* must write high and low 16 bits to reset counter */
1034 itr_reg |= (itr_reg << 16);
1035 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1036 /*
1037 * set the WDIS bit to not clear the timer bits and cause an
1038 * immediate assertion of the interrupt
1039 */
1040 itr_reg |= IXGBE_EITR_CNT_WDIS;
1041 }
1042 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1043}
1044
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001045static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1046{
1047 struct ixgbe_adapter *adapter = q_vector->adapter;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001048 u32 new_itr;
1049 u8 current_itr, ret_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001050 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001051 struct ixgbe_ring *rx_ring, *tx_ring;
1052
1053 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1054 for (i = 0; i < q_vector->txr_count; i++) {
1055 tx_ring = &(adapter->tx_ring[r_idx]);
1056 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001057 q_vector->tx_itr,
1058 tx_ring->total_packets,
1059 tx_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->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001063 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001064 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001065 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001066 }
1067
1068 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1069 for (i = 0; i < q_vector->rxr_count; i++) {
1070 rx_ring = &(adapter->rx_ring[r_idx]);
1071 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001072 q_vector->rx_itr,
1073 rx_ring->total_packets,
1074 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001075 /* if the result for this queue would decrease interrupt
1076 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001077 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001078 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001079 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001080 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001081 }
1082
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001083 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001084
1085 switch (current_itr) {
1086 /* counts and packets in update_itr are dependent on these numbers */
1087 case lowest_latency:
1088 new_itr = 100000;
1089 break;
1090 case low_latency:
1091 new_itr = 20000; /* aka hwitr = ~200 */
1092 break;
1093 case bulk_latency:
1094 default:
1095 new_itr = 8000;
1096 break;
1097 }
1098
1099 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001100 /* do an exponential smoothing */
1101 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001102
1103 /* save the algorithm value here, not the smoothed one */
1104 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001105
1106 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001107 }
1108
1109 return;
1110}
1111
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001112static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1113{
1114 struct ixgbe_hw *hw = &adapter->hw;
1115
1116 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1117 (eicr & IXGBE_EICR_GPI_SDP1)) {
1118 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
1119 /* write to clear the interrupt */
1120 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1121 }
1122}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001123
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001124static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1125{
1126 struct ixgbe_hw *hw = &adapter->hw;
1127
1128 if (eicr & IXGBE_EICR_GPI_SDP1) {
1129 /* Clear the interrupt */
1130 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1131 schedule_work(&adapter->multispeed_fiber_task);
1132 } else if (eicr & IXGBE_EICR_GPI_SDP2) {
1133 /* Clear the interrupt */
1134 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1135 schedule_work(&adapter->sfp_config_module_task);
1136 } else {
1137 /* Interrupt isn't for us... */
1138 return;
1139 }
1140}
1141
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001142static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1143{
1144 struct ixgbe_hw *hw = &adapter->hw;
1145
1146 adapter->lsc_int++;
1147 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1148 adapter->link_check_timeout = jiffies;
1149 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1150 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1151 schedule_work(&adapter->watchdog_task);
1152 }
1153}
1154
Auke Kok9a799d72007-09-15 14:07:45 -07001155static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1156{
1157 struct net_device *netdev = data;
1158 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1159 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001160 u32 eicr;
1161
1162 /*
1163 * Workaround for Silicon errata. Use clear-by-write instead
1164 * of clear-by-read. Reading with EICS will return the
1165 * interrupt causes without clearing, which later be done
1166 * with the write to EICR.
1167 */
1168 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1169 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001170
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001171 if (eicr & IXGBE_EICR_LSC)
1172 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001173
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001174 if (hw->mac.type == ixgbe_mac_82598EB)
1175 ixgbe_check_fan_failure(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001176
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001177 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001178 ixgbe_check_sfp_event(adapter, eicr);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001179
1180 /* Handle Flow Director Full threshold interrupt */
1181 if (eicr & IXGBE_EICR_FLOW_DIR) {
1182 int i;
1183 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
1184 /* Disable transmits before FDIR Re-initialization */
1185 netif_tx_stop_all_queues(netdev);
1186 for (i = 0; i < adapter->num_tx_queues; i++) {
1187 struct ixgbe_ring *tx_ring =
1188 &adapter->tx_ring[i];
1189 if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE,
1190 &tx_ring->reinit_state))
1191 schedule_work(&adapter->fdir_reinit_task);
1192 }
1193 }
1194 }
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001195 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1196 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -07001197
1198 return IRQ_HANDLED;
1199}
1200
Alexander Duyckfe49f042009-06-04 16:00:09 +00001201static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1202 u64 qmask)
1203{
1204 u32 mask;
1205
1206 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1207 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1208 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1209 } else {
1210 mask = (qmask & 0xFFFFFFFF);
1211 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
1212 mask = (qmask >> 32);
1213 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
1214 }
1215 /* skip the flush */
1216}
1217
1218static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
1219 u64 qmask)
1220{
1221 u32 mask;
1222
1223 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1224 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1225 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
1226 } else {
1227 mask = (qmask & 0xFFFFFFFF);
1228 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
1229 mask = (qmask >> 32);
1230 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
1231 }
1232 /* skip the flush */
1233}
1234
Auke Kok9a799d72007-09-15 14:07:45 -07001235static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1236{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001237 struct ixgbe_q_vector *q_vector = data;
1238 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001239 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001240 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001241
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001242 if (!q_vector->txr_count)
1243 return IRQ_HANDLED;
1244
1245 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1246 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001247 tx_ring = &(adapter->tx_ring[r_idx]);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001248 tx_ring->total_bytes = 0;
1249 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001250 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001251 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001252 }
1253
Alexander Duyck91281fd2009-06-04 16:00:27 +00001254 /* disable interrupts on this vector only */
1255 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1256 napi_schedule(&q_vector->napi);
1257
Auke Kok9a799d72007-09-15 14:07:45 -07001258 return IRQ_HANDLED;
1259}
1260
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001261/**
1262 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1263 * @irq: unused
1264 * @data: pointer to our q_vector struct for this interrupt vector
1265 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001266static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1267{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001268 struct ixgbe_q_vector *q_vector = data;
1269 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001270 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001271 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001272 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001273
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001274 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001275 for (i = 0; i < q_vector->rxr_count; i++) {
1276 rx_ring = &(adapter->rx_ring[r_idx]);
1277 rx_ring->total_bytes = 0;
1278 rx_ring->total_packets = 0;
1279 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1280 r_idx + 1);
1281 }
1282
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001283 if (!q_vector->rxr_count)
1284 return IRQ_HANDLED;
1285
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001286 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001287 rx_ring = &(adapter->rx_ring[r_idx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001288 /* disable interrupts on this vector only */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001289 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
Ben Hutchings288379f2009-01-19 16:43:59 -08001290 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001291
Auke Kok9a799d72007-09-15 14:07:45 -07001292 return IRQ_HANDLED;
1293}
1294
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001295static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1296{
Alexander Duyck91281fd2009-06-04 16:00:27 +00001297 struct ixgbe_q_vector *q_vector = data;
1298 struct ixgbe_adapter *adapter = q_vector->adapter;
1299 struct ixgbe_ring *ring;
1300 int r_idx;
1301 int i;
1302
1303 if (!q_vector->txr_count && !q_vector->rxr_count)
1304 return IRQ_HANDLED;
1305
1306 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1307 for (i = 0; i < q_vector->txr_count; i++) {
1308 ring = &(adapter->tx_ring[r_idx]);
1309 ring->total_bytes = 0;
1310 ring->total_packets = 0;
1311 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1312 r_idx + 1);
1313 }
1314
1315 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1316 for (i = 0; i < q_vector->rxr_count; i++) {
1317 ring = &(adapter->rx_ring[r_idx]);
1318 ring->total_bytes = 0;
1319 ring->total_packets = 0;
1320 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1321 r_idx + 1);
1322 }
1323
1324 /* disable interrupts on this vector only */
1325 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1326 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001327
1328 return IRQ_HANDLED;
1329}
1330
1331/**
1332 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1333 * @napi: napi struct with our devices info in it
1334 * @budget: amount of work driver is allowed to do this pass, in packets
1335 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001336 * This function is optimized for cleaning one queue only on a single
1337 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001338 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001339static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1340{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001341 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001342 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001343 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001344 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001345 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001346 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001347
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001348 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001349 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001350#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001351 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001352 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001353#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001354
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001355 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001356
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001357 /* If all Rx work done, exit the polling mode */
1358 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001359 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001360 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001361 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001362 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001363 ixgbe_irq_enable_queues(adapter,
1364 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07001365 }
1366
1367 return work_done;
1368}
1369
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001370/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00001371 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001372 * @napi: napi struct with our devices info in it
1373 * @budget: amount of work driver is allowed to do this pass, in packets
1374 *
1375 * This function will clean more than one rx queue associated with a
1376 * q_vector.
1377 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00001378static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001379{
1380 struct ixgbe_q_vector *q_vector =
1381 container_of(napi, struct ixgbe_q_vector, napi);
1382 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001383 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001384 int work_done = 0, i;
1385 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001386 bool tx_clean_complete = true;
1387
1388 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1389 for (i = 0; i < q_vector->txr_count; i++) {
1390 ring = &(adapter->tx_ring[r_idx]);
1391#ifdef CONFIG_IXGBE_DCA
1392 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1393 ixgbe_update_tx_dca(adapter, ring);
1394#endif
1395 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
1396 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1397 r_idx + 1);
1398 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001399
1400 /* attempt to distribute budget to each queue fairly, but don't allow
1401 * the budget to go below 1 because we'll exit polling */
1402 budget /= (q_vector->rxr_count ?: 1);
1403 budget = max(budget, 1);
1404 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1405 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck91281fd2009-06-04 16:00:27 +00001406 ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001407#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001408 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck91281fd2009-06-04 16:00:27 +00001409 ixgbe_update_rx_dca(adapter, ring);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001410#endif
Alexander Duyck91281fd2009-06-04 16:00:27 +00001411 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001412 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1413 r_idx + 1);
1414 }
1415
1416 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck91281fd2009-06-04 16:00:27 +00001417 ring = &(adapter->rx_ring[r_idx]);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001418 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001419 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001420 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001421 if (adapter->itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001422 ixgbe_set_itr_msix(q_vector);
1423 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001424 ixgbe_irq_enable_queues(adapter,
1425 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001426 return 0;
1427 }
1428
1429 return work_done;
1430}
Alexander Duyck91281fd2009-06-04 16:00:27 +00001431
1432/**
1433 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
1434 * @napi: napi struct with our devices info in it
1435 * @budget: amount of work driver is allowed to do this pass, in packets
1436 *
1437 * This function is optimized for cleaning one queue only on a single
1438 * q_vector!!!
1439 **/
1440static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
1441{
1442 struct ixgbe_q_vector *q_vector =
1443 container_of(napi, struct ixgbe_q_vector, napi);
1444 struct ixgbe_adapter *adapter = q_vector->adapter;
1445 struct ixgbe_ring *tx_ring = NULL;
1446 int work_done = 0;
1447 long r_idx;
1448
1449 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1450 tx_ring = &(adapter->tx_ring[r_idx]);
1451#ifdef CONFIG_IXGBE_DCA
1452 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1453 ixgbe_update_tx_dca(adapter, tx_ring);
1454#endif
1455
1456 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
1457 work_done = budget;
1458
1459 /* If all Rx work done, exit the polling mode */
1460 if (work_done < budget) {
1461 napi_complete(napi);
1462 if (adapter->itr_setting & 1)
1463 ixgbe_set_itr_msix(q_vector);
1464 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1465 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
1466 }
1467
1468 return work_done;
1469}
1470
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001471static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001472 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001473{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001474 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1475
1476 set_bit(r_idx, q_vector->rxr_idx);
1477 q_vector->rxr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001478}
Auke Kok9a799d72007-09-15 14:07:45 -07001479
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001480static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001481 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001482{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001483 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1484
1485 set_bit(t_idx, q_vector->txr_idx);
1486 q_vector->txr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001487}
Auke Kok9a799d72007-09-15 14:07:45 -07001488
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001489/**
1490 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1491 * @adapter: board private structure to initialize
1492 * @vectors: allotted vector count for descriptor rings
1493 *
1494 * This function maps descriptor rings to the queue-specific vectors
1495 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1496 * one vector per ring/queue, but on a constrained vector budget, we
1497 * group the rings as "efficiently" as possible. You would add new
1498 * mapping configurations in here.
1499 **/
1500static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001501 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001502{
1503 int v_start = 0;
1504 int rxr_idx = 0, txr_idx = 0;
1505 int rxr_remaining = adapter->num_rx_queues;
1506 int txr_remaining = adapter->num_tx_queues;
1507 int i, j;
1508 int rqpv, tqpv;
1509 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001510
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001511 /* No mapping required if MSI-X is disabled. */
1512 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001513 goto out;
1514
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001515 /*
1516 * The ideal configuration...
1517 * We have enough vectors to map one per queue.
1518 */
1519 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1520 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1521 map_vector_to_rxq(adapter, v_start, rxr_idx);
1522
1523 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1524 map_vector_to_txq(adapter, v_start, txr_idx);
1525
1526 goto out;
1527 }
1528
1529 /*
1530 * If we don't have enough vectors for a 1-to-1
1531 * mapping, we'll have to group them so there are
1532 * multiple queues per vector.
1533 */
1534 /* Re-adjusting *qpv takes care of the remainder. */
1535 for (i = v_start; i < vectors; i++) {
1536 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1537 for (j = 0; j < rqpv; j++) {
1538 map_vector_to_rxq(adapter, i, rxr_idx);
1539 rxr_idx++;
1540 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001541 }
Auke Kok9a799d72007-09-15 14:07:45 -07001542 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001543 for (i = v_start; i < vectors; i++) {
1544 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1545 for (j = 0; j < tqpv; j++) {
1546 map_vector_to_txq(adapter, i, txr_idx);
1547 txr_idx++;
1548 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001549 }
Auke Kok9a799d72007-09-15 14:07:45 -07001550 }
1551
Auke Kok9a799d72007-09-15 14:07:45 -07001552out:
Auke Kok9a799d72007-09-15 14:07:45 -07001553 return err;
1554}
1555
1556/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001557 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1558 * @adapter: board private structure
1559 *
1560 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1561 * interrupts from the kernel.
1562 **/
1563static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1564{
1565 struct net_device *netdev = adapter->netdev;
1566 irqreturn_t (*handler)(int, void *);
1567 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001568 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001569
1570 /* Decrement for Other and TCP Timer vectors */
1571 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1572
1573 /* Map the Tx/Rx rings to the vectors we were allotted. */
1574 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1575 if (err)
1576 goto out;
1577
1578#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001579 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1580 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001581 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001582 handler = SET_HANDLER(adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001583
1584 if(handler == &ixgbe_msix_clean_rx) {
1585 sprintf(adapter->name[vector], "%s-%s-%d",
1586 netdev->name, "rx", ri++);
1587 }
1588 else if(handler == &ixgbe_msix_clean_tx) {
1589 sprintf(adapter->name[vector], "%s-%s-%d",
1590 netdev->name, "tx", ti++);
1591 }
1592 else
1593 sprintf(adapter->name[vector], "%s-%s-%d",
1594 netdev->name, "TxRx", vector);
1595
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001596 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001597 handler, 0, adapter->name[vector],
Alexander Duyck7a921c92009-05-06 10:43:28 +00001598 adapter->q_vector[vector]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001599 if (err) {
1600 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001601 "request_irq failed for MSIX interrupt "
1602 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001603 goto free_queue_irqs;
1604 }
1605 }
1606
1607 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1608 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001609 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001610 if (err) {
1611 DPRINTK(PROBE, ERR,
1612 "request_irq for msix_lsc failed: %d\n", err);
1613 goto free_queue_irqs;
1614 }
1615
1616 return 0;
1617
1618free_queue_irqs:
1619 for (i = vector - 1; i >= 0; i--)
1620 free_irq(adapter->msix_entries[--vector].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001621 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001622 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1623 pci_disable_msix(adapter->pdev);
1624 kfree(adapter->msix_entries);
1625 adapter->msix_entries = NULL;
1626out:
1627 return err;
1628}
1629
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001630static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1631{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001632 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001633 u8 current_itr;
1634 u32 new_itr = q_vector->eitr;
1635 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1636 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1637
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001638 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001639 q_vector->tx_itr,
1640 tx_ring->total_packets,
1641 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001642 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001643 q_vector->rx_itr,
1644 rx_ring->total_packets,
1645 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001646
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001647 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001648
1649 switch (current_itr) {
1650 /* counts and packets in update_itr are dependent on these numbers */
1651 case lowest_latency:
1652 new_itr = 100000;
1653 break;
1654 case low_latency:
1655 new_itr = 20000; /* aka hwitr = ~200 */
1656 break;
1657 case bulk_latency:
1658 new_itr = 8000;
1659 break;
1660 default:
1661 break;
1662 }
1663
1664 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001665 /* do an exponential smoothing */
1666 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001667
1668 /* save the algorithm value here, not the smoothed one */
1669 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001670
1671 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001672 }
1673
1674 return;
1675}
1676
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001677/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001678 * ixgbe_irq_enable - Enable default interrupt generation settings
1679 * @adapter: board private structure
1680 **/
1681static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1682{
1683 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00001684
1685 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
David S. Miller6ab33d52008-11-20 16:44:00 -08001686 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1687 mask |= IXGBE_EIMS_GPI_SDP1;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001688 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001689 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001690 mask |= IXGBE_EIMS_GPI_SDP1;
1691 mask |= IXGBE_EIMS_GPI_SDP2;
1692 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001693 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
1694 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
1695 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001696
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001697 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Nelson, Shannon835462f2009-04-27 22:42:54 +00001698 ixgbe_irq_enable_queues(adapter, ~0);
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001699 IXGBE_WRITE_FLUSH(&adapter->hw);
1700}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001701
1702/**
1703 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001704 * @irq: interrupt number
1705 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001706 **/
1707static irqreturn_t ixgbe_intr(int irq, void *data)
1708{
1709 struct net_device *netdev = data;
1710 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1711 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001712 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07001713 u32 eicr;
1714
Don Skidmore54037502009-02-21 15:42:56 -08001715 /*
1716 * Workaround for silicon errata. Mask the interrupts
1717 * before the read of EICR.
1718 */
1719 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1720
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001721 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1722 * therefore no explict interrupt disable is necessary */
1723 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001724 if (!eicr) {
1725 /* shared interrupt alert!
1726 * make sure interrupts are enabled because the read will
1727 * have disabled interrupts due to EIAM */
1728 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001729 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001730 }
Auke Kok9a799d72007-09-15 14:07:45 -07001731
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001732 if (eicr & IXGBE_EICR_LSC)
1733 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001734
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001735 if (hw->mac.type == ixgbe_mac_82599EB)
1736 ixgbe_check_sfp_event(adapter, eicr);
1737
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001738 ixgbe_check_fan_failure(adapter, eicr);
1739
Alexander Duyck7a921c92009-05-06 10:43:28 +00001740 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001741 adapter->tx_ring[0].total_packets = 0;
1742 adapter->tx_ring[0].total_bytes = 0;
1743 adapter->rx_ring[0].total_packets = 0;
1744 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001745 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00001746 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07001747 }
1748
1749 return IRQ_HANDLED;
1750}
1751
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001752static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1753{
1754 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1755
1756 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001757 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001758 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1759 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1760 q_vector->rxr_count = 0;
1761 q_vector->txr_count = 0;
1762 }
1763}
1764
Auke Kok9a799d72007-09-15 14:07:45 -07001765/**
1766 * ixgbe_request_irq - initialize interrupts
1767 * @adapter: board private structure
1768 *
1769 * Attempts to configure interrupts using the best available
1770 * capabilities of the hardware and kernel.
1771 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001772static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001773{
1774 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001775 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001776
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001777 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1778 err = ixgbe_request_msix_irqs(adapter);
1779 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1780 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001781 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001782 } else {
1783 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001784 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001785 }
1786
Auke Kok9a799d72007-09-15 14:07:45 -07001787 if (err)
1788 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1789
Auke Kok9a799d72007-09-15 14:07:45 -07001790 return err;
1791}
1792
1793static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1794{
1795 struct net_device *netdev = adapter->netdev;
1796
1797 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001798 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001799
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001800 q_vectors = adapter->num_msix_vectors;
1801
1802 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001803 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001804
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001805 i--;
1806 for (; i >= 0; i--) {
1807 free_irq(adapter->msix_entries[i].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001808 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001809 }
1810
1811 ixgbe_reset_q_vectors(adapter);
1812 } else {
1813 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001814 }
1815}
1816
1817/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001818 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1819 * @adapter: board private structure
1820 **/
1821static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1822{
Nelson, Shannon835462f2009-04-27 22:42:54 +00001823 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1824 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1825 } else {
1826 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
1827 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001828 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001829 }
1830 IXGBE_WRITE_FLUSH(&adapter->hw);
1831 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1832 int i;
1833 for (i = 0; i < adapter->num_msix_vectors; i++)
1834 synchronize_irq(adapter->msix_entries[i].vector);
1835 } else {
1836 synchronize_irq(adapter->pdev->irq);
1837 }
1838}
1839
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001840/**
Auke Kok9a799d72007-09-15 14:07:45 -07001841 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1842 *
1843 **/
1844static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1845{
Auke Kok9a799d72007-09-15 14:07:45 -07001846 struct ixgbe_hw *hw = &adapter->hw;
1847
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001848 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001849 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001850
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001851 ixgbe_set_ivar(adapter, 0, 0, 0);
1852 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001853
1854 map_vector_to_rxq(adapter, 0, 0);
1855 map_vector_to_txq(adapter, 0, 0);
1856
1857 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001858}
1859
1860/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001861 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001862 * @adapter: board private structure
1863 *
1864 * Configure the Tx unit of the MAC after a reset.
1865 **/
1866static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1867{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001868 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001869 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001870 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001871
1872 /* Setup the HW Tx Head and Tail descriptor pointers */
1873 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001874 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1875 j = ring->reg_idx;
1876 tdba = ring->dma;
1877 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001878 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Yang Hongyang284901a2009-04-06 19:01:15 -07001879 (tdba & DMA_BIT_MASK(32)));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001880 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1881 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1882 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1883 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1884 adapter->tx_ring[i].head = IXGBE_TDH(j);
1885 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1886 /* Disable Tx Head Writeback RO bit, since this hoses
1887 * bookkeeping if things aren't delivered in order.
1888 */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001889 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001890 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001891 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001892 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001893 if (hw->mac.type == ixgbe_mac_82599EB) {
1894 /* We enable 8 traffic classes, DCB only */
1895 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1896 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1897 IXGBE_MTQC_8TC_8TQ));
1898 }
Auke Kok9a799d72007-09-15 14:07:45 -07001899}
1900
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001901#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07001902
Yi Zoua6616b42009-08-06 13:05:23 +00001903static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
1904 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001905{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001906 u32 srrctl;
Yi Zoua6616b42009-08-06 13:05:23 +00001907 int index;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001908 struct ixgbe_ring_feature *feature = adapter->ring_feature;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001909
Yi Zoua6616b42009-08-06 13:05:23 +00001910 index = rx_ring->reg_idx;
1911 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1912 unsigned long mask;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001913 mask = (unsigned long) feature[RING_F_RSS].mask;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001914 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001915 }
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001916 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1917
1918 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1919 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1920
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001921 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1922 IXGBE_SRRCTL_BSIZEHDR_MASK;
1923
Yi Zou6e455b892009-08-06 13:05:44 +00001924 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001925#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
1926 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1927#else
1928 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1929#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001930 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001931 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001932 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
1933 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001934 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001935 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001936
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001937 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1938}
1939
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001940static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
1941{
1942 u32 mrqc = 0;
1943 int mask;
1944
1945 if (!(adapter->hw.mac.type == ixgbe_mac_82599EB))
1946 return mrqc;
1947
1948 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
1949#ifdef CONFIG_IXGBE_DCB
1950 | IXGBE_FLAG_DCB_ENABLED
1951#endif
1952 );
1953
1954 switch (mask) {
1955 case (IXGBE_FLAG_RSS_ENABLED):
1956 mrqc = IXGBE_MRQC_RSSEN;
1957 break;
1958#ifdef CONFIG_IXGBE_DCB
1959 case (IXGBE_FLAG_DCB_ENABLED):
1960 mrqc = IXGBE_MRQC_RT8TCEN;
1961 break;
1962#endif /* CONFIG_IXGBE_DCB */
1963 default:
1964 break;
1965 }
1966
1967 return mrqc;
1968}
1969
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001970/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001971 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001972 * @adapter: board private structure
1973 *
1974 * Configure the Rx unit of the MAC after a reset.
1975 **/
1976static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1977{
1978 u64 rdba;
1979 struct ixgbe_hw *hw = &adapter->hw;
Yi Zoua6616b42009-08-06 13:05:23 +00001980 struct ixgbe_ring *rx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07001981 struct net_device *netdev = adapter->netdev;
1982 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001983 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001984 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001985 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1986 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1987 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001988 u32 fctrl, hlreg0;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001989 u32 reta = 0, mrqc = 0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001990 u32 rdrxctl;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001991 u32 rscctrl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001992 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07001993
1994 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001995 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07001996
1997 /* Set the RX buffer length according to the mode */
1998 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001999 rx_buf_len = IXGBE_RX_HDR_SIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002000 if (hw->mac.type == ixgbe_mac_82599EB) {
2001 /* PSRTYPE must be initialized in 82599 */
2002 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
2003 IXGBE_PSRTYPE_UDPHDR |
2004 IXGBE_PSRTYPE_IPV4HDR |
Yi Zoudfa12f02009-05-07 10:39:35 +00002005 IXGBE_PSRTYPE_IPV6HDR |
2006 IXGBE_PSRTYPE_L2HDR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002007 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
2008 }
Auke Kok9a799d72007-09-15 14:07:45 -07002009 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00002010 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00002011 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002012 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07002013 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002014 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07002015 }
2016
2017 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
2018 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002019 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002020 fctrl |= IXGBE_FCTRL_PMCF;
Auke Kok9a799d72007-09-15 14:07:45 -07002021 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
2022
2023 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2024 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2025 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
2026 else
2027 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Yi Zou63f39bd2009-05-17 12:34:35 +00002028#ifdef IXGBE_FCOE
Yi Zouf34c5c82009-08-14 12:42:17 +00002029 if (netdev->features & NETIF_F_FCOE_MTU)
Yi Zou63f39bd2009-05-17 12:34:35 +00002030 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2031#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002032 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2033
Auke Kok9a799d72007-09-15 14:07:45 -07002034 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
2035 /* disable receives while setting up the descriptors */
2036 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2037 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
2038
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002039 /*
2040 * Setup the HW Rx Head and Tail Descriptor Pointers and
2041 * the Base and Length of the Rx Descriptor Ring
2042 */
Auke Kok9a799d72007-09-15 14:07:45 -07002043 for (i = 0; i < adapter->num_rx_queues; i++) {
Yi Zoua6616b42009-08-06 13:05:23 +00002044 rx_ring = &adapter->rx_ring[i];
2045 rdba = rx_ring->dma;
2046 j = rx_ring->reg_idx;
Yang Hongyang284901a2009-04-06 19:01:15 -07002047 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32)));
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002048 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
2049 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
2050 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
2051 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
Yi Zoua6616b42009-08-06 13:05:23 +00002052 rx_ring->head = IXGBE_RDH(j);
2053 rx_ring->tail = IXGBE_RDT(j);
2054 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002055
Yi Zou6e455b892009-08-06 13:05:44 +00002056 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
2057 rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002058
Yi Zou63f39bd2009-05-17 12:34:35 +00002059#ifdef IXGBE_FCOE
Yi Zouf34c5c82009-08-14 12:42:17 +00002060 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00002061 struct ixgbe_ring_feature *f;
2062 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00002063 if ((i >= f->mask) && (i < f->mask + f->indices)) {
2064 rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
2065 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
2066 rx_ring->rx_buf_len =
2067 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2068 }
Yi Zou63f39bd2009-05-17 12:34:35 +00002069 }
2070
2071#endif /* IXGBE_FCOE */
Yi Zoua6616b42009-08-06 13:05:23 +00002072 ixgbe_configure_srrctl(adapter, rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002073 }
2074
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002075 if (hw->mac.type == ixgbe_mac_82598EB) {
2076 /*
2077 * For VMDq support of different descriptor types or
2078 * buffer sizes through the use of multiple SRRCTL
2079 * registers, RDRXCTL.MVMEN must be set to 1
2080 *
2081 * also, the manual doesn't mention it clearly but DCA hints
2082 * will only use queue 0's tags unless this bit is set. Side
2083 * effects of setting this bit are only that SRRCTL must be
2084 * fully programmed [0..15]
2085 */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002086 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2087 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
2088 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
Alexander Duyck2f90b862008-11-20 20:52:10 -08002089 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002090
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002091 /* Program MRQC for the distribution of queues */
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002092 mrqc = ixgbe_setup_mrqc(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002093
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002094 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07002095 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002096 for (i = 0, j = 0; i < 128; i++, j++) {
2097 if (j == adapter->ring_feature[RING_F_RSS].indices)
2098 j = 0;
2099 /* reta = 4-byte sliding window of
2100 * 0x00..(indices-1)(indices-1)00..etc. */
2101 reta = (reta << 8) | (j * 0x11);
2102 if ((i & 3) == 3)
2103 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07002104 }
2105
2106 /* Fill out hash function seeds */
2107 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002108 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002109
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002110 if (hw->mac.type == ixgbe_mac_82598EB)
2111 mrqc |= IXGBE_MRQC_RSSEN;
Auke Kok9a799d72007-09-15 14:07:45 -07002112 /* Perform hash on these packet types */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002113 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2114 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2115 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
2116 | IXGBE_MRQC_RSS_FIELD_IPV6
2117 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
2118 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07002119 }
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002120 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002121
2122 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2123
2124 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
2125 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
2126 /* Disable indicating checksum in descriptor, enables
2127 * RSS hash */
2128 rxcsum |= IXGBE_RXCSUM_PCSD;
2129 }
2130 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
2131 /* Enable IPv4 payload checksum for UDP fragments
2132 * if PCSD is not set */
2133 rxcsum |= IXGBE_RXCSUM_IPPCSE;
2134 }
2135
2136 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002137
2138 if (hw->mac.type == ixgbe_mac_82599EB) {
2139 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2140 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002141 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002142 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
2143 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002144
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00002145 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002146 /* Enable 82599 HW-RSC */
2147 for (i = 0; i < adapter->num_rx_queues; i++) {
Yi Zou6e455b892009-08-06 13:05:44 +00002148 rx_ring = &adapter->rx_ring[i];
2149 j = rx_ring->reg_idx;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002150 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j));
2151 rscctrl |= IXGBE_RSCCTL_RSCEN;
2152 /*
Alexander Duycke76678d2009-05-17 20:57:47 +00002153 * we must limit the number of descriptors so that the
2154 * total size of max desc * buf_len is not greater
2155 * than 65535
Alexander Duyckf8212f92009-04-27 22:42:37 +00002156 */
Yi Zou6e455b892009-08-06 13:05:44 +00002157 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Alexander Duycke76678d2009-05-17 20:57:47 +00002158#if (MAX_SKB_FRAGS > 16)
2159 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2160#elif (MAX_SKB_FRAGS > 8)
Alexander Duyckf8212f92009-04-27 22:42:37 +00002161 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Alexander Duycke76678d2009-05-17 20:57:47 +00002162#elif (MAX_SKB_FRAGS > 4)
2163 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002164#else
Alexander Duycke76678d2009-05-17 20:57:47 +00002165 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002166#endif
Alexander Duycke76678d2009-05-17 20:57:47 +00002167 } else {
2168 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2169 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2170 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2171 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2172 else
2173 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2174 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002175 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl);
2176 }
2177 /* Disable RSC for ACK packets */
2178 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
2179 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
2180 }
Auke Kok9a799d72007-09-15 14:07:45 -07002181}
2182
Auke Kok9a799d72007-09-15 14:07:45 -07002183static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2184{
2185 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002186 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002187
2188 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002189 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002190}
2191
2192static void ixgbe_vlan_rx_kill_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
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002197 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2198 ixgbe_irq_disable(adapter);
2199
Auke Kok9a799d72007-09-15 14:07:45 -07002200 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002201
2202 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2203 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002204
2205 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002206 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07002207}
2208
Don Skidmore068c89b2009-01-19 16:54:36 -08002209static void ixgbe_vlan_rx_register(struct net_device *netdev,
2210 struct vlan_group *grp)
2211{
2212 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2213 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002214 int i, j;
Don Skidmore068c89b2009-01-19 16:54:36 -08002215
2216 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2217 ixgbe_irq_disable(adapter);
2218 adapter->vlgrp = grp;
2219
2220 /*
2221 * For a DCB driver, always enable VLAN tag stripping so we can
2222 * still receive traffic from a DCB-enabled host even if we're
2223 * not in DCB mode.
2224 */
2225 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002226 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
2227 ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
Don Skidmore068c89b2009-01-19 16:54:36 -08002228 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2229 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002230 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
2231 ctrl |= IXGBE_VLNCTRL_VFE;
2232 /* enable VLAN tag insert/strip */
2233 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
2234 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2235 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
2236 for (i = 0; i < adapter->num_rx_queues; i++) {
2237 j = adapter->rx_ring[i].reg_idx;
2238 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
2239 ctrl |= IXGBE_RXDCTL_VME;
2240 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
2241 }
Don Skidmore068c89b2009-01-19 16:54:36 -08002242 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002243 ixgbe_vlan_rx_add_vid(netdev, 0);
Don Skidmore068c89b2009-01-19 16:54:36 -08002244
2245 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2246 ixgbe_irq_enable(adapter);
2247}
2248
Auke Kok9a799d72007-09-15 14:07:45 -07002249static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
2250{
2251 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2252
2253 if (adapter->vlgrp) {
2254 u16 vid;
2255 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2256 if (!vlan_group_get_device(adapter->vlgrp, vid))
2257 continue;
2258 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
2259 }
2260 }
2261}
2262
Christopher Leech2c5645c2008-08-26 04:27:02 -07002263static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
2264{
2265 struct dev_mc_list *mc_ptr;
2266 u8 *addr = *mc_addr_ptr;
2267 *vmdq = 0;
2268
2269 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
2270 if (mc_ptr->next)
2271 *mc_addr_ptr = mc_ptr->next->dmi_addr;
2272 else
2273 *mc_addr_ptr = NULL;
2274
2275 return addr;
2276}
2277
Auke Kok9a799d72007-09-15 14:07:45 -07002278/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07002279 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07002280 * @netdev: network interface device structure
2281 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07002282 * The set_rx_method entry point is called whenever the unicast/multicast
2283 * address list or the network interface flags are updated. This routine is
2284 * responsible for configuring the hardware for proper unicast, multicast and
2285 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07002286 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07002287static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07002288{
2289 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2290 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07002291 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002292 u8 *addr_list = NULL;
2293 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002294
2295 /* Check for Promiscuous and All Multicast modes */
2296
2297 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07002298 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07002299
2300 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07002301 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002302 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07002303 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07002304 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002305 if (netdev->flags & IFF_ALLMULTI) {
2306 fctrl |= IXGBE_FCTRL_MPE;
2307 fctrl &= ~IXGBE_FCTRL_UPE;
2308 } else {
2309 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2310 }
Alexander Duyck3d016252008-08-26 18:30:04 -07002311 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002312 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002313 }
2314
2315 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07002316 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07002317
Christopher Leech2c5645c2008-08-26 04:27:02 -07002318 /* reprogram secondary unicast list */
Jiri Pirko31278e72009-06-17 01:12:19 +00002319 hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list);
Auke Kok9a799d72007-09-15 14:07:45 -07002320
Christopher Leech2c5645c2008-08-26 04:27:02 -07002321 /* reprogram multicast list */
2322 addr_count = netdev->mc_count;
2323 if (addr_count)
2324 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002325 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2326 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002327}
2328
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002329static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2330{
2331 int q_idx;
2332 struct ixgbe_q_vector *q_vector;
2333 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2334
2335 /* legacy and MSI only use one vector */
2336 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2337 q_vectors = 1;
2338
2339 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002340 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002341 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002342 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002343 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2344 if (!q_vector->rxr_count || !q_vector->txr_count) {
2345 if (q_vector->txr_count == 1)
2346 napi->poll = &ixgbe_clean_txonly;
2347 else if (q_vector->rxr_count == 1)
2348 napi->poll = &ixgbe_clean_rxonly;
2349 }
2350 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002351
2352 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002353 }
2354}
2355
2356static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2357{
2358 int q_idx;
2359 struct ixgbe_q_vector *q_vector;
2360 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2361
2362 /* legacy and MSI only use one vector */
2363 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2364 q_vectors = 1;
2365
2366 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002367 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002368 napi_disable(&q_vector->napi);
2369 }
2370}
2371
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002372#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002373/*
2374 * ixgbe_configure_dcb - Configure DCB hardware
2375 * @adapter: ixgbe adapter struct
2376 *
2377 * This is called by the driver on open to configure the DCB hardware.
2378 * This is also called by the gennetlink interface when reconfiguring
2379 * the DCB state.
2380 */
2381static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2382{
2383 struct ixgbe_hw *hw = &adapter->hw;
2384 u32 txdctl, vlnctrl;
2385 int i, j;
2386
2387 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2388 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2389 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2390
2391 /* reconfigure the hardware */
2392 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2393
2394 for (i = 0; i < adapter->num_tx_queues; i++) {
2395 j = adapter->tx_ring[i].reg_idx;
2396 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2397 /* PThresh workaround for Tx hang with DFP enabled. */
2398 txdctl |= 32;
2399 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2400 }
2401 /* Enable VLAN tag insert/strip */
2402 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002403 if (hw->mac.type == ixgbe_mac_82598EB) {
2404 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2405 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2406 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2407 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2408 vlnctrl |= IXGBE_VLNCTRL_VFE;
2409 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2410 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2411 for (i = 0; i < adapter->num_rx_queues; i++) {
2412 j = adapter->rx_ring[i].reg_idx;
2413 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2414 vlnctrl |= IXGBE_RXDCTL_VME;
2415 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2416 }
2417 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08002418 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2419}
2420
2421#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002422static void ixgbe_configure(struct ixgbe_adapter *adapter)
2423{
2424 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002425 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002426 int i;
2427
Christopher Leech2c5645c2008-08-26 04:27:02 -07002428 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002429
2430 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002431#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002432 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2433 netif_set_gso_max_size(netdev, 32768);
2434 ixgbe_configure_dcb(adapter);
2435 } else {
2436 netif_set_gso_max_size(netdev, 65536);
2437 }
2438#else
2439 netif_set_gso_max_size(netdev, 65536);
2440#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002441
Yi Zoueacd73f2009-05-13 13:11:06 +00002442#ifdef IXGBE_FCOE
2443 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2444 ixgbe_configure_fcoe(adapter);
2445
2446#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002447 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2448 for (i = 0; i < adapter->num_tx_queues; i++)
2449 adapter->tx_ring[i].atr_sample_rate =
2450 adapter->atr_sample_rate;
2451 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
2452 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
2453 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
2454 }
2455
Auke Kok9a799d72007-09-15 14:07:45 -07002456 ixgbe_configure_tx(adapter);
2457 ixgbe_configure_rx(adapter);
2458 for (i = 0; i < adapter->num_rx_queues; i++)
2459 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002460 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07002461}
2462
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002463static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2464{
2465 switch (hw->phy.type) {
2466 case ixgbe_phy_sfp_avago:
2467 case ixgbe_phy_sfp_ftl:
2468 case ixgbe_phy_sfp_intel:
2469 case ixgbe_phy_sfp_unknown:
2470 case ixgbe_phy_tw_tyco:
2471 case ixgbe_phy_tw_unknown:
2472 return true;
2473 default:
2474 return false;
2475 }
2476}
2477
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002478/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002479 * ixgbe_sfp_link_config - set up SFP+ link
2480 * @adapter: pointer to private adapter struct
2481 **/
2482static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2483{
2484 struct ixgbe_hw *hw = &adapter->hw;
2485
2486 if (hw->phy.multispeed_fiber) {
2487 /*
2488 * In multispeed fiber setups, the device may not have
2489 * had a physical connection when the driver loaded.
2490 * If that's the case, the initial link configuration
2491 * couldn't get the MAC into 10G or 1G mode, so we'll
2492 * never have a link status change interrupt fire.
2493 * We need to try and force an autonegotiation
2494 * session, then bring up link.
2495 */
2496 hw->mac.ops.setup_sfp(hw);
2497 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2498 schedule_work(&adapter->multispeed_fiber_task);
2499 } else {
2500 /*
2501 * Direct Attach Cu and non-multispeed fiber modules
2502 * still need to be configured properly prior to
2503 * attempting link.
2504 */
2505 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2506 schedule_work(&adapter->sfp_config_module_task);
2507 }
2508}
2509
2510/**
2511 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002512 * @hw: pointer to private hardware struct
2513 *
2514 * Returns 0 on success, negative on failure
2515 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002516static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002517{
2518 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00002519 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002520 u32 ret = IXGBE_ERR_LINK_SETUP;
2521
2522 if (hw->mac.ops.check_link)
2523 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2524
2525 if (ret)
2526 goto link_cfg_out;
2527
2528 if (hw->mac.ops.get_link_capabilities)
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00002529 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002530 if (ret)
2531 goto link_cfg_out;
2532
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00002533 if (hw->mac.ops.setup_link)
2534 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002535link_cfg_out:
2536 return ret;
2537}
2538
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002539#define IXGBE_MAX_RX_DESC_POLL 10
2540static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2541 int rxr)
2542{
2543 int j = adapter->rx_ring[rxr].reg_idx;
2544 int k;
2545
2546 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2547 if (IXGBE_READ_REG(&adapter->hw,
2548 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2549 break;
2550 else
2551 msleep(1);
2552 }
2553 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2554 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2555 "not set within the polling period\n", rxr);
2556 }
2557 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2558 (adapter->rx_ring[rxr].count - 1));
2559}
2560
Auke Kok9a799d72007-09-15 14:07:45 -07002561static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2562{
2563 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07002564 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002565 int i, j = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002566 int num_rx_rings = adapter->num_rx_queues;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002567 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002568 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002569 u32 txdctl, rxdctl, mhadd;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002570 u32 dmatxctl;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002571 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002572
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002573 ixgbe_get_hw_control(adapter);
2574
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002575 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2576 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002577 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2578 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002579 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002580 } else {
2581 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002582 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002583 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002584 /* XXX: to interrupt immediately for EICS writes, enable this */
2585 /* gpie |= IXGBE_GPIE_EIMEN; */
2586 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2587 }
2588
2589 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2590 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2591 * specifically only auto mask tx and rx interrupts */
2592 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002593 }
2594
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002595 /* Enable fan failure interrupt if media type is copper */
2596 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2597 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2598 gpie |= IXGBE_SDP1_GPIEN;
2599 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2600 }
2601
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002602 if (hw->mac.type == ixgbe_mac_82599EB) {
2603 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2604 gpie |= IXGBE_SDP1_GPIEN;
2605 gpie |= IXGBE_SDP2_GPIEN;
2606 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2607 }
2608
Yi Zou63f39bd2009-05-17 12:34:35 +00002609#ifdef IXGBE_FCOE
2610 /* adjust max frame to be able to do baby jumbo for FCoE */
Yi Zouf34c5c82009-08-14 12:42:17 +00002611 if ((netdev->features & NETIF_F_FCOE_MTU) &&
Yi Zou63f39bd2009-05-17 12:34:35 +00002612 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
2613 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
2614
2615#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07002616 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002617 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2618 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2619 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2620
2621 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2622 }
2623
2624 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002625 j = adapter->tx_ring[i].reg_idx;
2626 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002627 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2628 txdctl |= (8 << 16);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002629 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2630 }
2631
2632 if (hw->mac.type == ixgbe_mac_82599EB) {
2633 /* DMATXCTL.EN must be set after all Tx queue config is done */
2634 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2635 dmatxctl |= IXGBE_DMATXCTL_TE;
2636 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2637 }
2638 for (i = 0; i < adapter->num_tx_queues; i++) {
2639 j = adapter->tx_ring[i].reg_idx;
2640 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Auke Kok9a799d72007-09-15 14:07:45 -07002641 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002642 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002643 }
2644
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002645 for (i = 0; i < num_rx_rings; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002646 j = adapter->rx_ring[i].reg_idx;
2647 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2648 /* enable PTHRESH=32 descriptors (half the internal cache)
2649 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2650 * this also removes a pesky rx_no_buffer_count increment */
2651 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002652 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002653 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002654 if (hw->mac.type == ixgbe_mac_82599EB)
2655 ixgbe_rx_desc_queue_enable(adapter, i);
Auke Kok9a799d72007-09-15 14:07:45 -07002656 }
2657 /* enable all receives */
2658 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002659 if (hw->mac.type == ixgbe_mac_82598EB)
2660 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2661 else
2662 rxdctl |= IXGBE_RXCTRL_RXEN;
2663 hw->mac.ops.enable_rx_dma(hw, rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002664
2665 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2666 ixgbe_configure_msix(adapter);
2667 else
2668 ixgbe_configure_msi_and_legacy(adapter);
2669
2670 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002671 ixgbe_napi_enable_all(adapter);
2672
2673 /* clear any pending interrupts, may auto mask */
2674 IXGBE_READ_REG(hw, IXGBE_EICR);
2675
Auke Kok9a799d72007-09-15 14:07:45 -07002676 ixgbe_irq_enable(adapter);
2677
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002678 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00002679 * If this adapter has a fan, check to see if we had a failure
2680 * before we enabled the interrupt.
2681 */
2682 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2683 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2684 if (esdp & IXGBE_ESDP_SDP1)
2685 DPRINTK(DRV, CRIT,
2686 "Fan has stopped, replace the adapter\n");
2687 }
2688
2689 /*
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002690 * For hot-pluggable SFP+ devices, a new SFP+ module may have
Don Skidmore19343de2009-07-02 12:50:31 +00002691 * arrived before interrupts were enabled but after probe. Such
2692 * devices wouldn't have their type identified yet. We need to
2693 * kick off the SFP+ module setup first, then try to bring up link.
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002694 * If we're not hot-pluggable SFP+, we just need to configure link
2695 * and bring it up.
2696 */
Don Skidmore19343de2009-07-02 12:50:31 +00002697 if (hw->phy.type == ixgbe_phy_unknown) {
2698 err = hw->phy.ops.identify(hw);
2699 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore5da43c12009-07-02 12:50:52 +00002700 /*
2701 * Take the device down and schedule the sfp tasklet
2702 * which will unregister_netdev and log it.
2703 */
Don Skidmore19343de2009-07-02 12:50:31 +00002704 ixgbe_down(adapter);
Don Skidmore5da43c12009-07-02 12:50:52 +00002705 schedule_work(&adapter->sfp_config_module_task);
Don Skidmore19343de2009-07-02 12:50:31 +00002706 return err;
2707 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002708 }
2709
2710 if (ixgbe_is_sfp(hw)) {
2711 ixgbe_sfp_link_config(adapter);
2712 } else {
2713 err = ixgbe_non_sfp_link_config(hw);
2714 if (err)
2715 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2716 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002717
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002718 for (i = 0; i < adapter->num_tx_queues; i++)
2719 set_bit(__IXGBE_FDIR_INIT_DONE,
2720 &(adapter->tx_ring[i].reinit_state));
2721
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002722 /* enable transmits */
2723 netif_tx_start_all_queues(netdev);
2724
Auke Kok9a799d72007-09-15 14:07:45 -07002725 /* bring the link up in the watchdog, this could race with our first
2726 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002727 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2728 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002729 mod_timer(&adapter->watchdog_timer, jiffies);
2730 return 0;
2731}
2732
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002733void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2734{
2735 WARN_ON(in_interrupt());
2736 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2737 msleep(1);
2738 ixgbe_down(adapter);
2739 ixgbe_up(adapter);
2740 clear_bit(__IXGBE_RESETTING, &adapter->state);
2741}
2742
Auke Kok9a799d72007-09-15 14:07:45 -07002743int ixgbe_up(struct ixgbe_adapter *adapter)
2744{
2745 /* hardware has been reset, we need to reload some things */
2746 ixgbe_configure(adapter);
2747
2748 return ixgbe_up_complete(adapter);
2749}
2750
2751void ixgbe_reset(struct ixgbe_adapter *adapter)
2752{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002753 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07002754 int err;
2755
2756 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002757 switch (err) {
2758 case 0:
2759 case IXGBE_ERR_SFP_NOT_PRESENT:
2760 break;
2761 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
2762 dev_err(&adapter->pdev->dev, "master disable timed out\n");
2763 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00002764 case IXGBE_ERR_EEPROM_VERSION:
2765 /* We are running on a pre-production device, log a warning */
2766 dev_warn(&adapter->pdev->dev, "This device is a pre-production "
2767 "adapter/LOM. Please be aware there may be issues "
2768 "associated with your hardware. If you are "
2769 "experiencing problems please contact your Intel or "
2770 "hardware representative who provided you with this "
2771 "hardware.\n");
2772 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002773 default:
2774 dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err);
2775 }
Auke Kok9a799d72007-09-15 14:07:45 -07002776
2777 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002778 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002779}
2780
Auke Kok9a799d72007-09-15 14:07:45 -07002781/**
2782 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2783 * @adapter: board private structure
2784 * @rx_ring: ring to free buffers from
2785 **/
2786static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002787 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002788{
2789 struct pci_dev *pdev = adapter->pdev;
2790 unsigned long size;
2791 unsigned int i;
2792
2793 /* Free all the Rx ring sk_buffs */
2794
2795 for (i = 0; i < rx_ring->count; i++) {
2796 struct ixgbe_rx_buffer *rx_buffer_info;
2797
2798 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2799 if (rx_buffer_info->dma) {
2800 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002801 rx_ring->rx_buf_len,
2802 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002803 rx_buffer_info->dma = 0;
2804 }
2805 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002806 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002807 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002808 do {
2809 struct sk_buff *this = skb;
2810 skb = skb->prev;
2811 dev_kfree_skb(this);
2812 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002813 }
2814 if (!rx_buffer_info->page)
2815 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00002816 if (rx_buffer_info->page_dma) {
2817 pci_unmap_page(pdev, rx_buffer_info->page_dma,
2818 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
2819 rx_buffer_info->page_dma = 0;
2820 }
Auke Kok9a799d72007-09-15 14:07:45 -07002821 put_page(rx_buffer_info->page);
2822 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002823 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002824 }
2825
2826 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2827 memset(rx_ring->rx_buffer_info, 0, size);
2828
2829 /* Zero out the descriptor ring */
2830 memset(rx_ring->desc, 0, rx_ring->size);
2831
2832 rx_ring->next_to_clean = 0;
2833 rx_ring->next_to_use = 0;
2834
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002835 if (rx_ring->head)
2836 writel(0, adapter->hw.hw_addr + rx_ring->head);
2837 if (rx_ring->tail)
2838 writel(0, adapter->hw.hw_addr + rx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002839}
2840
2841/**
2842 * ixgbe_clean_tx_ring - Free Tx Buffers
2843 * @adapter: board private structure
2844 * @tx_ring: ring to be cleaned
2845 **/
2846static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002847 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002848{
2849 struct ixgbe_tx_buffer *tx_buffer_info;
2850 unsigned long size;
2851 unsigned int i;
2852
2853 /* Free all the Tx ring sk_buffs */
2854
2855 for (i = 0; i < tx_ring->count; i++) {
2856 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2857 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2858 }
2859
2860 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2861 memset(tx_ring->tx_buffer_info, 0, size);
2862
2863 /* Zero out the descriptor ring */
2864 memset(tx_ring->desc, 0, tx_ring->size);
2865
2866 tx_ring->next_to_use = 0;
2867 tx_ring->next_to_clean = 0;
2868
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002869 if (tx_ring->head)
2870 writel(0, adapter->hw.hw_addr + tx_ring->head);
2871 if (tx_ring->tail)
2872 writel(0, adapter->hw.hw_addr + tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002873}
2874
2875/**
Auke Kok9a799d72007-09-15 14:07:45 -07002876 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2877 * @adapter: board private structure
2878 **/
2879static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2880{
2881 int i;
2882
2883 for (i = 0; i < adapter->num_rx_queues; i++)
2884 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2885}
2886
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002887/**
2888 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2889 * @adapter: board private structure
2890 **/
2891static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2892{
2893 int i;
2894
2895 for (i = 0; i < adapter->num_tx_queues; i++)
2896 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2897}
2898
Auke Kok9a799d72007-09-15 14:07:45 -07002899void ixgbe_down(struct ixgbe_adapter *adapter)
2900{
2901 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002902 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002903 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002904 u32 txdctl;
2905 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002906
2907 /* signal that we are down to the interrupt handler */
2908 set_bit(__IXGBE_DOWN, &adapter->state);
2909
2910 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002911 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2912 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002913
2914 netif_tx_disable(netdev);
2915
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002916 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002917 msleep(10);
2918
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002919 netif_tx_stop_all_queues(netdev);
2920
Auke Kok9a799d72007-09-15 14:07:45 -07002921 ixgbe_irq_disable(adapter);
2922
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002923 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002924
Auke Kok9a799d72007-09-15 14:07:45 -07002925 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002926 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002927
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002928 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
2929 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2930 cancel_work_sync(&adapter->fdir_reinit_task);
2931
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002932 /* disable transmits in the hardware now that interrupts are off */
2933 for (i = 0; i < adapter->num_tx_queues; i++) {
2934 j = adapter->tx_ring[i].reg_idx;
2935 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2936 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2937 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2938 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00002939 /* Disable the Tx DMA engine on 82599 */
2940 if (hw->mac.type == ixgbe_mac_82599EB)
2941 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
2942 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
2943 ~IXGBE_DMATXCTL_TE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002944
Auke Kok9a799d72007-09-15 14:07:45 -07002945 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002946
Paul Larson6f4a0e42008-06-24 17:00:56 -07002947 if (!pci_channel_offline(adapter->pdev))
2948 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002949 ixgbe_clean_all_tx_rings(adapter);
2950 ixgbe_clean_all_rx_rings(adapter);
2951
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002952#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002953 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00002954 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002955#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002956}
2957
Auke Kok9a799d72007-09-15 14:07:45 -07002958/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002959 * ixgbe_poll - NAPI Rx polling callback
2960 * @napi: structure for representing this polling device
2961 * @budget: how many packets driver is allowed to clean
2962 *
2963 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002964 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002965static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002966{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002967 struct ixgbe_q_vector *q_vector =
2968 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002969 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002970 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002971
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002972#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002973 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2974 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2975 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2976 }
2977#endif
2978
Alexander Duyckfe49f042009-06-04 16:00:09 +00002979 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002980 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002981
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002982 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002983 work_done = budget;
2984
David S. Miller53e52c72008-01-07 21:06:12 -08002985 /* If budget not fully consumed, exit the polling mode */
2986 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002987 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002988 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002989 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002990 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00002991 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002992 }
Auke Kok9a799d72007-09-15 14:07:45 -07002993 return work_done;
2994}
2995
2996/**
2997 * ixgbe_tx_timeout - Respond to a Tx Hang
2998 * @netdev: network interface device structure
2999 **/
3000static void ixgbe_tx_timeout(struct net_device *netdev)
3001{
3002 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3003
3004 /* Do the reset outside of interrupt context */
3005 schedule_work(&adapter->reset_task);
3006}
3007
3008static void ixgbe_reset_task(struct work_struct *work)
3009{
3010 struct ixgbe_adapter *adapter;
3011 adapter = container_of(work, struct ixgbe_adapter, reset_task);
3012
Alexander Duyck2f90b862008-11-20 20:52:10 -08003013 /* If we're already down or resetting, just bail */
3014 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
3015 test_bit(__IXGBE_RESETTING, &adapter->state))
3016 return;
3017
Auke Kok9a799d72007-09-15 14:07:45 -07003018 adapter->tx_timeout_count++;
3019
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003020 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003021}
3022
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003023#ifdef CONFIG_IXGBE_DCB
3024static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003025{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003026 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003027 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003028
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003029 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
3030 return ret;
3031
3032 f->mask = 0x7 << 3;
3033 adapter->num_rx_queues = f->indices;
3034 adapter->num_tx_queues = f->indices;
3035 ret = true;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003036
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003037 return ret;
3038}
3039#endif
3040
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003041/**
3042 * ixgbe_set_rss_queues: Allocate queues for RSS
3043 * @adapter: board private structure to initialize
3044 *
3045 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
3046 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
3047 *
3048 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003049static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
3050{
3051 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003052 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003053
3054 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003055 f->mask = 0xF;
3056 adapter->num_rx_queues = f->indices;
3057 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003058 ret = true;
3059 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003060 ret = false;
3061 }
3062
3063 return ret;
3064}
3065
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003066/**
3067 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
3068 * @adapter: board private structure to initialize
3069 *
3070 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
3071 * to the original CPU that initiated the Tx session. This runs in addition
3072 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
3073 * Rx load across CPUs using RSS.
3074 *
3075 **/
3076static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
3077{
3078 bool ret = false;
3079 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
3080
3081 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
3082 f_fdir->mask = 0;
3083
3084 /* Flow Director must have RSS enabled */
3085 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3086 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3087 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
3088 adapter->num_tx_queues = f_fdir->indices;
3089 adapter->num_rx_queues = f_fdir->indices;
3090 ret = true;
3091 } else {
3092 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3093 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3094 }
3095 return ret;
3096}
3097
Yi Zou0331a832009-05-17 12:33:52 +00003098#ifdef IXGBE_FCOE
3099/**
3100 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
3101 * @adapter: board private structure to initialize
3102 *
3103 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
3104 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
3105 * rx queues out of the max number of rx queues, instead, it is used as the
3106 * index of the first rx queue used by FCoE.
3107 *
3108 **/
3109static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
3110{
3111 bool ret = false;
3112 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3113
3114 f->indices = min((int)num_online_cpus(), f->indices);
3115 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003116 adapter->num_rx_queues = 1;
3117 adapter->num_tx_queues = 1;
Yi Zou0331a832009-05-17 12:33:52 +00003118#ifdef CONFIG_IXGBE_DCB
3119 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003120 DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n");
Yi Zou0331a832009-05-17 12:33:52 +00003121 ixgbe_set_dcb_queues(adapter);
3122 }
3123#endif
3124 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003125 DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n");
Yi Zou8faa2a72009-07-09 02:29:50 +00003126 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3127 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
3128 ixgbe_set_fdir_queues(adapter);
3129 else
3130 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00003131 }
3132 /* adding FCoE rx rings to the end */
3133 f->mask = adapter->num_rx_queues;
3134 adapter->num_rx_queues += f->indices;
Yi Zou8de8b2e2009-09-03 14:55:50 +00003135 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00003136
3137 ret = true;
3138 }
3139
3140 return ret;
3141}
3142
3143#endif /* IXGBE_FCOE */
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003144/*
3145 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
3146 * @adapter: board private structure to initialize
3147 *
3148 * This is the top level queue allocation routine. The order here is very
3149 * important, starting with the "most" number of features turned on at once,
3150 * and ending with the smallest set of features. This way large combinations
3151 * can be allocated if they're turned on, and smaller combinations are the
3152 * fallthrough conditions.
3153 *
3154 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003155static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
3156{
Yi Zou0331a832009-05-17 12:33:52 +00003157#ifdef IXGBE_FCOE
3158 if (ixgbe_set_fcoe_queues(adapter))
3159 goto done;
3160
3161#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003162#ifdef CONFIG_IXGBE_DCB
3163 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003164 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003165
3166#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003167 if (ixgbe_set_fdir_queues(adapter))
3168 goto done;
3169
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003170 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003171 goto done;
3172
3173 /* fallback to base case */
3174 adapter->num_rx_queues = 1;
3175 adapter->num_tx_queues = 1;
3176
3177done:
3178 /* Notify the stack of the (possibly) reduced Tx Queue count. */
3179 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003180}
3181
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003182static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003183 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003184{
3185 int err, vector_threshold;
3186
3187 /* We'll want at least 3 (vector_threshold):
3188 * 1) TxQ[0] Cleanup
3189 * 2) RxQ[0] Cleanup
3190 * 3) Other (Link Status Change, etc.)
3191 * 4) TCP Timer (optional)
3192 */
3193 vector_threshold = MIN_MSIX_COUNT;
3194
3195 /* The more we get, the more we will assign to Tx/Rx Cleanup
3196 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
3197 * Right now, we simply care about how many we'll get; we'll
3198 * set them up later while requesting irq's.
3199 */
3200 while (vectors >= vector_threshold) {
3201 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003202 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003203 if (!err) /* Success in acquiring all requested vectors. */
3204 break;
3205 else if (err < 0)
3206 vectors = 0; /* Nasty failure, quit now */
3207 else /* err == number of vectors we should try again with */
3208 vectors = err;
3209 }
3210
3211 if (vectors < vector_threshold) {
3212 /* Can't allocate enough MSI-X interrupts? Oh well.
3213 * This just means we'll go with either a single MSI
3214 * vector or fall back to legacy interrupts.
3215 */
3216 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
3217 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3218 kfree(adapter->msix_entries);
3219 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003220 } else {
3221 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08003222 /*
3223 * Adjust for only the vectors we'll use, which is minimum
3224 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
3225 * vectors we were allocated.
3226 */
3227 adapter->num_msix_vectors = min(vectors,
3228 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003229 }
3230}
3231
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003232/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003233 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003234 * @adapter: board private structure to initialize
3235 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003236 * Cache the descriptor ring offsets for RSS to the assigned rings.
3237 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003238 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003239static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003240{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003241 int i;
3242 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003243
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003244 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3245 for (i = 0; i < adapter->num_rx_queues; i++)
3246 adapter->rx_ring[i].reg_idx = i;
3247 for (i = 0; i < adapter->num_tx_queues; i++)
3248 adapter->tx_ring[i].reg_idx = i;
3249 ret = true;
3250 } else {
3251 ret = false;
3252 }
3253
3254 return ret;
3255}
3256
3257#ifdef CONFIG_IXGBE_DCB
3258/**
3259 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
3260 * @adapter: board private structure to initialize
3261 *
3262 * Cache the descriptor ring offsets for DCB to the assigned rings.
3263 *
3264 **/
3265static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
3266{
3267 int i;
3268 bool ret = false;
3269 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
3270
3271 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3272 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08003273 /* the number of queues is assumed to be symmetric */
3274 for (i = 0; i < dcb_i; i++) {
3275 adapter->rx_ring[i].reg_idx = i << 3;
3276 adapter->tx_ring[i].reg_idx = i << 2;
3277 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003278 ret = true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003279 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
PJ Waskiewiczf92ef202009-04-16 15:00:20 +00003280 if (dcb_i == 8) {
3281 /*
3282 * Tx TC0 starts at: descriptor queue 0
3283 * Tx TC1 starts at: descriptor queue 32
3284 * Tx TC2 starts at: descriptor queue 64
3285 * Tx TC3 starts at: descriptor queue 80
3286 * Tx TC4 starts at: descriptor queue 96
3287 * Tx TC5 starts at: descriptor queue 104
3288 * Tx TC6 starts at: descriptor queue 112
3289 * Tx TC7 starts at: descriptor queue 120
3290 *
3291 * Rx TC0-TC7 are offset by 16 queues each
3292 */
3293 for (i = 0; i < 3; i++) {
3294 adapter->tx_ring[i].reg_idx = i << 5;
3295 adapter->rx_ring[i].reg_idx = i << 4;
3296 }
3297 for ( ; i < 5; i++) {
3298 adapter->tx_ring[i].reg_idx =
3299 ((i + 2) << 4);
3300 adapter->rx_ring[i].reg_idx = i << 4;
3301 }
3302 for ( ; i < dcb_i; i++) {
3303 adapter->tx_ring[i].reg_idx =
3304 ((i + 8) << 3);
3305 adapter->rx_ring[i].reg_idx = i << 4;
3306 }
3307
3308 ret = true;
3309 } else if (dcb_i == 4) {
3310 /*
3311 * Tx TC0 starts at: descriptor queue 0
3312 * Tx TC1 starts at: descriptor queue 64
3313 * Tx TC2 starts at: descriptor queue 96
3314 * Tx TC3 starts at: descriptor queue 112
3315 *
3316 * Rx TC0-TC3 are offset by 32 queues each
3317 */
3318 adapter->tx_ring[0].reg_idx = 0;
3319 adapter->tx_ring[1].reg_idx = 64;
3320 adapter->tx_ring[2].reg_idx = 96;
3321 adapter->tx_ring[3].reg_idx = 112;
3322 for (i = 0 ; i < dcb_i; i++)
3323 adapter->rx_ring[i].reg_idx = i << 5;
3324
3325 ret = true;
3326 } else {
3327 ret = false;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003328 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003329 } else {
3330 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003331 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003332 } else {
3333 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003334 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003335
3336 return ret;
3337}
3338#endif
3339
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003340/**
3341 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
3342 * @adapter: board private structure to initialize
3343 *
3344 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
3345 *
3346 **/
3347static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
3348{
3349 int i;
3350 bool ret = false;
3351
3352 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3353 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3354 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
3355 for (i = 0; i < adapter->num_rx_queues; i++)
3356 adapter->rx_ring[i].reg_idx = i;
3357 for (i = 0; i < adapter->num_tx_queues; i++)
3358 adapter->tx_ring[i].reg_idx = i;
3359 ret = true;
3360 }
3361
3362 return ret;
3363}
3364
Yi Zou0331a832009-05-17 12:33:52 +00003365#ifdef IXGBE_FCOE
3366/**
3367 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
3368 * @adapter: board private structure to initialize
3369 *
3370 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
3371 *
3372 */
3373static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
3374{
Yi Zou8de8b2e2009-09-03 14:55:50 +00003375 int i, fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00003376 bool ret = false;
3377 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3378
3379 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3380#ifdef CONFIG_IXGBE_DCB
3381 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003382 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
3383
Yi Zou0331a832009-05-17 12:33:52 +00003384 ixgbe_cache_ring_dcb(adapter);
Yi Zou8de8b2e2009-09-03 14:55:50 +00003385 /* find out queues in TC for FCoE */
3386 fcoe_rx_i = adapter->rx_ring[fcoe->tc].reg_idx + 1;
3387 fcoe_tx_i = adapter->tx_ring[fcoe->tc].reg_idx + 1;
3388 /*
3389 * In 82599, the number of Tx queues for each traffic
3390 * class for both 8-TC and 4-TC modes are:
3391 * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7
3392 * 8 TCs: 32 32 16 16 8 8 8 8
3393 * 4 TCs: 64 64 32 32
3394 * We have max 8 queues for FCoE, where 8 the is
3395 * FCoE redirection table size. If TC for FCoE is
3396 * less than or equal to TC3, we have enough queues
3397 * to add max of 8 queues for FCoE, so we start FCoE
3398 * tx descriptor from the next one, i.e., reg_idx + 1.
3399 * If TC for FCoE is above TC3, implying 8 TC mode,
3400 * and we need 8 for FCoE, we have to take all queues
3401 * in that traffic class for FCoE.
3402 */
3403 if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3))
3404 fcoe_tx_i--;
Yi Zou0331a832009-05-17 12:33:52 +00003405 }
3406#endif /* CONFIG_IXGBE_DCB */
3407 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Yi Zou8faa2a72009-07-09 02:29:50 +00003408 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3409 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
3410 ixgbe_cache_ring_fdir(adapter);
3411 else
3412 ixgbe_cache_ring_rss(adapter);
3413
Yi Zou8de8b2e2009-09-03 14:55:50 +00003414 fcoe_rx_i = f->mask;
3415 fcoe_tx_i = f->mask;
Yi Zou0331a832009-05-17 12:33:52 +00003416 }
Yi Zou8de8b2e2009-09-03 14:55:50 +00003417 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
3418 adapter->rx_ring[f->mask + i].reg_idx = fcoe_rx_i;
3419 adapter->tx_ring[f->mask + i].reg_idx = fcoe_tx_i;
3420 }
Yi Zou0331a832009-05-17 12:33:52 +00003421 ret = true;
3422 }
3423 return ret;
3424}
3425
3426#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003427/**
3428 * ixgbe_cache_ring_register - Descriptor ring to register mapping
3429 * @adapter: board private structure to initialize
3430 *
3431 * Once we know the feature-set enabled for the device, we'll cache
3432 * the register offset the descriptor ring is assigned to.
3433 *
3434 * Note, the order the various feature calls is important. It must start with
3435 * the "most" features enabled at the same time, then trickle down to the
3436 * least amount of features turned on at once.
3437 **/
3438static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
3439{
3440 /* start with default case */
3441 adapter->rx_ring[0].reg_idx = 0;
3442 adapter->tx_ring[0].reg_idx = 0;
3443
Yi Zou0331a832009-05-17 12:33:52 +00003444#ifdef IXGBE_FCOE
3445 if (ixgbe_cache_ring_fcoe(adapter))
3446 return;
3447
3448#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003449#ifdef CONFIG_IXGBE_DCB
3450 if (ixgbe_cache_ring_dcb(adapter))
3451 return;
3452
3453#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003454 if (ixgbe_cache_ring_fdir(adapter))
3455 return;
3456
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003457 if (ixgbe_cache_ring_rss(adapter))
3458 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003459}
3460
Auke Kok9a799d72007-09-15 14:07:45 -07003461/**
3462 * ixgbe_alloc_queues - Allocate memory for all rings
3463 * @adapter: board private structure to initialize
3464 *
3465 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003466 * number of queues at compile-time. The polling_netdev array is
3467 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07003468 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003469static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003470{
3471 int i;
3472
3473 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003474 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07003475 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003476 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07003477
3478 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003479 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003480 if (!adapter->rx_ring)
3481 goto err_rx_ring_allocation;
3482
3483 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003484 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003485 adapter->tx_ring[i].queue_index = i;
3486 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003487
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003488 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003489 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003490 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07003491 }
3492
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003493 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003494
3495 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003496
3497err_rx_ring_allocation:
3498 kfree(adapter->tx_ring);
3499err_tx_ring_allocation:
3500 return -ENOMEM;
3501}
3502
3503/**
3504 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3505 * @adapter: board private structure to initialize
3506 *
3507 * Attempt to configure the interrupts using the best available
3508 * capabilities of the hardware and the kernel.
3509 **/
Al Virofeea6a52008-11-27 15:34:07 -08003510static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003511{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003512 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003513 int err = 0;
3514 int vector, v_budget;
3515
3516 /*
3517 * It's easy to be greedy for MSI-X vectors, but it really
3518 * doesn't do us much good if we have a lot more vectors
3519 * than CPU's. So let's be conservative and only ask for
3520 * (roughly) twice the number of vectors as there are CPU's.
3521 */
3522 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003523 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003524
3525 /*
3526 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003527 * hw.mac->max_msix_vectors vectors. With features
3528 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3529 * descriptor queues supported by our device. Thus, we cap it off in
3530 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003531 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003532 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003533
3534 /* A failure in MSI-X entry allocation isn't fatal, but it does
3535 * mean we disable MSI-X capabilities of the adapter. */
3536 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003537 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003538 if (adapter->msix_entries) {
3539 for (vector = 0; vector < v_budget; vector++)
3540 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003541
Alexander Duyck7a921c92009-05-06 10:43:28 +00003542 ixgbe_acquire_msix_vectors(adapter, v_budget);
3543
3544 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3545 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003546 }
3547
Alexander Duyck7a921c92009-05-06 10:43:28 +00003548 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
3549 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003550 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3551 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3552 adapter->atr_sample_rate = 0;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003553 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003554
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003555 err = pci_enable_msi(adapter->pdev);
3556 if (!err) {
3557 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
3558 } else {
3559 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003560 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003561 /* reset err */
3562 err = 0;
3563 }
3564
3565out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003566 return err;
3567}
3568
Alexander Duyck7a921c92009-05-06 10:43:28 +00003569/**
3570 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
3571 * @adapter: board private structure to initialize
3572 *
3573 * We allocate one q_vector per queue interrupt. If allocation fails we
3574 * return -ENOMEM.
3575 **/
3576static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
3577{
3578 int q_idx, num_q_vectors;
3579 struct ixgbe_q_vector *q_vector;
3580 int napi_vectors;
3581 int (*poll)(struct napi_struct *, int);
3582
3583 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3584 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3585 napi_vectors = adapter->num_rx_queues;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003586 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003587 } else {
3588 num_q_vectors = 1;
3589 napi_vectors = 1;
3590 poll = &ixgbe_poll;
3591 }
3592
3593 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3594 q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL);
3595 if (!q_vector)
3596 goto err_out;
3597 q_vector->adapter = adapter;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003598 q_vector->eitr = adapter->eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00003599 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003600 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003601 adapter->q_vector[q_idx] = q_vector;
3602 }
3603
3604 return 0;
3605
3606err_out:
3607 while (q_idx) {
3608 q_idx--;
3609 q_vector = adapter->q_vector[q_idx];
3610 netif_napi_del(&q_vector->napi);
3611 kfree(q_vector);
3612 adapter->q_vector[q_idx] = NULL;
3613 }
3614 return -ENOMEM;
3615}
3616
3617/**
3618 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
3619 * @adapter: board private structure to initialize
3620 *
3621 * This function frees the memory allocated to the q_vectors. In addition if
3622 * NAPI is enabled it will delete any references to the NAPI struct prior
3623 * to freeing the q_vector.
3624 **/
3625static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
3626{
3627 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003628
Alexander Duyck91281fd2009-06-04 16:00:27 +00003629 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00003630 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003631 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00003632 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003633
3634 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3635 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00003636 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003637 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003638 kfree(q_vector);
3639 }
3640}
3641
Don Skidmore7b25cdb2009-08-25 04:47:32 +00003642static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003643{
3644 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3645 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3646 pci_disable_msix(adapter->pdev);
3647 kfree(adapter->msix_entries);
3648 adapter->msix_entries = NULL;
3649 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
3650 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
3651 pci_disable_msi(adapter->pdev);
3652 }
3653 return;
3654}
3655
3656/**
3657 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3658 * @adapter: board private structure to initialize
3659 *
3660 * We determine which interrupt scheme to use based on...
3661 * - Kernel support (MSI, MSI-X)
3662 * - which can be user-defined (via MODULE_PARAM)
3663 * - Hardware queue count (num_*_queues)
3664 * - defined by miscellaneous hardware support/features (RSS, etc.)
3665 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003666int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003667{
3668 int err;
3669
3670 /* Number of supported queues */
3671 ixgbe_set_num_queues(adapter);
3672
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003673 err = ixgbe_set_interrupt_capability(adapter);
3674 if (err) {
3675 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3676 goto err_set_interrupt;
3677 }
3678
Alexander Duyck7a921c92009-05-06 10:43:28 +00003679 err = ixgbe_alloc_q_vectors(adapter);
3680 if (err) {
3681 DPRINTK(PROBE, ERR, "Unable to allocate memory for queue "
3682 "vectors\n");
3683 goto err_alloc_q_vectors;
3684 }
3685
3686 err = ixgbe_alloc_queues(adapter);
3687 if (err) {
3688 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3689 goto err_alloc_queues;
3690 }
3691
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003692 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003693 "Tx Queue count = %u\n",
3694 (adapter->num_rx_queues > 1) ? "Enabled" :
3695 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003696
3697 set_bit(__IXGBE_DOWN, &adapter->state);
3698
3699 return 0;
3700
Alexander Duyck7a921c92009-05-06 10:43:28 +00003701err_alloc_queues:
3702 ixgbe_free_q_vectors(adapter);
3703err_alloc_q_vectors:
3704 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003705err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00003706 return err;
3707}
3708
3709/**
3710 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
3711 * @adapter: board private structure to clear interrupt scheme on
3712 *
3713 * We go through and clear interrupt specific resources and reset the structure
3714 * to pre-load conditions
3715 **/
3716void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
3717{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003718 kfree(adapter->tx_ring);
3719 kfree(adapter->rx_ring);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003720 adapter->tx_ring = NULL;
3721 adapter->rx_ring = NULL;
3722
3723 ixgbe_free_q_vectors(adapter);
3724 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003725}
3726
3727/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08003728 * ixgbe_sfp_timer - worker thread to find a missing module
3729 * @data: pointer to our adapter struct
3730 **/
3731static void ixgbe_sfp_timer(unsigned long data)
3732{
3733 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3734
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003735 /*
3736 * Do the sfp_timer outside of interrupt context due to the
Donald Skidmorec4900be2008-11-20 21:11:42 -08003737 * delays that sfp+ detection requires
3738 */
3739 schedule_work(&adapter->sfp_task);
3740}
3741
3742/**
3743 * ixgbe_sfp_task - worker thread to find a missing module
3744 * @work: pointer to work_struct containing our data
3745 **/
3746static void ixgbe_sfp_task(struct work_struct *work)
3747{
3748 struct ixgbe_adapter *adapter = container_of(work,
3749 struct ixgbe_adapter,
3750 sfp_task);
3751 struct ixgbe_hw *hw = &adapter->hw;
3752
3753 if ((hw->phy.type == ixgbe_phy_nl) &&
3754 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3755 s32 ret = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00003756 if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
Donald Skidmorec4900be2008-11-20 21:11:42 -08003757 goto reschedule;
3758 ret = hw->phy.ops.reset(hw);
3759 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00003760 dev_err(&adapter->pdev->dev, "failed to initialize "
3761 "because an unsupported SFP+ module type "
3762 "was detected.\n"
3763 "Reload the driver after installing a "
3764 "supported module.\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08003765 unregister_netdev(adapter->netdev);
3766 } else {
3767 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3768 hw->phy.sfp_type);
3769 }
3770 /* don't need this routine any more */
3771 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3772 }
3773 return;
3774reschedule:
3775 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3776 mod_timer(&adapter->sfp_timer,
3777 round_jiffies(jiffies + (2 * HZ)));
3778}
3779
3780/**
Auke Kok9a799d72007-09-15 14:07:45 -07003781 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3782 * @adapter: board private structure to initialize
3783 *
3784 * ixgbe_sw_init initializes the Adapter private data structure.
3785 * Fields are initialized based on PCI device information and
3786 * OS network device settings (MTU size).
3787 **/
3788static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3789{
3790 struct ixgbe_hw *hw = &adapter->hw;
3791 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003792 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003793#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003794 int j;
3795 struct tc_configuration *tc;
3796#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003797
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003798 /* PCI config space info */
3799
3800 hw->vendor_id = pdev->vendor;
3801 hw->device_id = pdev->device;
3802 hw->revision_id = pdev->revision;
3803 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3804 hw->subsystem_device_id = pdev->subsystem_device;
3805
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003806 /* Set capability flags */
3807 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3808 adapter->ring_feature[RING_F_RSS].indices = rss;
3809 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003810 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Don Skidmorebf069c92009-05-07 10:39:54 +00003811 if (hw->mac.type == ixgbe_mac_82598EB) {
3812 if (hw->device_id == IXGBE_DEV_ID_82598AT)
3813 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003814 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Don Skidmorebf069c92009-05-07 10:39:54 +00003815 } else if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003816 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003817 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
3818 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003819 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
3820 adapter->ring_feature[RING_F_FDIR].indices =
3821 IXGBE_MAX_FDIR_INDICES;
3822 adapter->atr_sample_rate = 20;
3823 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00003824#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00003825 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
3826 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
3827 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou6ee16522009-08-31 12:34:28 +00003828 /* Default traffic class to use for FCoE */
3829 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
Yi Zoueacd73f2009-05-13 13:11:06 +00003830#endif /* IXGBE_FCOE */
Alexander Duyckf8212f92009-04-27 22:42:37 +00003831 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003832
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003833#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003834 /* Configure DCB traffic classes */
3835 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3836 tc = &adapter->dcb_cfg.tc_config[j];
3837 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3838 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3839 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3840 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3841 tc->dcb_pfc = pfc_disabled;
3842 }
3843 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3844 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3845 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003846 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003847 adapter->dcb_cfg.round_robin_enable = false;
3848 adapter->dcb_set_bitmap = 0x00;
3849 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3850 adapter->ring_feature[RING_F_DCB].indices);
3851
3852#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003853
3854 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00003855 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00003856 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003857#ifdef CONFIG_DCB
3858 adapter->last_lfc_mode = hw->fc.current_mode;
3859#endif
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07003860 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3861 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3862 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3863 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00003864 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07003865
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07003866 /* enable itr by default in dynamic mode */
3867 adapter->itr_setting = 1;
3868 adapter->eitr_param = 20000;
3869
3870 /* set defaults for eitr in MegaBytes */
3871 adapter->eitr_low = 10;
3872 adapter->eitr_high = 20;
3873
3874 /* set default ring sizes */
3875 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
3876 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
3877
Auke Kok9a799d72007-09-15 14:07:45 -07003878 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003879 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003880 dev_err(&pdev->dev, "EEPROM initialization failed\n");
3881 return -EIO;
3882 }
3883
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003884 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07003885 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
3886
Auke Kok9a799d72007-09-15 14:07:45 -07003887 set_bit(__IXGBE_DOWN, &adapter->state);
3888
3889 return 0;
3890}
3891
3892/**
3893 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3894 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003895 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003896 *
3897 * Return 0 on success, negative on failure
3898 **/
3899int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003900 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003901{
3902 struct pci_dev *pdev = adapter->pdev;
3903 int size;
3904
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003905 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3906 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003907 if (!tx_ring->tx_buffer_info)
3908 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003909 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003910
3911 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08003912 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003913 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003914
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003915 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
3916 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003917 if (!tx_ring->desc)
3918 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07003919
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003920 tx_ring->next_to_use = 0;
3921 tx_ring->next_to_clean = 0;
3922 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07003923 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003924
3925err:
3926 vfree(tx_ring->tx_buffer_info);
3927 tx_ring->tx_buffer_info = NULL;
3928 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
3929 "descriptor ring\n");
3930 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003931}
3932
3933/**
Alexander Duyck69888672008-09-11 20:05:39 -07003934 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
3935 * @adapter: board private structure
3936 *
3937 * If this function returns with an error, then it's possible one or
3938 * more of the rings is populated (while the rest are not). It is the
3939 * callers duty to clean those orphaned rings.
3940 *
3941 * Return 0 on success, negative on failure
3942 **/
3943static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
3944{
3945 int i, err = 0;
3946
3947 for (i = 0; i < adapter->num_tx_queues; i++) {
3948 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
3949 if (!err)
3950 continue;
3951 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
3952 break;
3953 }
3954
3955 return err;
3956}
3957
3958/**
Auke Kok9a799d72007-09-15 14:07:45 -07003959 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
3960 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003961 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003962 *
3963 * Returns 0 on success, negative on failure
3964 **/
3965int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003966 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003967{
3968 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003969 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07003970
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003971 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
3972 rx_ring->rx_buffer_info = vmalloc(size);
3973 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07003974 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003975 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003976 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003977 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003978 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003979
Auke Kok9a799d72007-09-15 14:07:45 -07003980 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003981 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
3982 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003983
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003984 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07003985
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003986 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07003987 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003988 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003989 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003990 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003991 }
3992
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003993 rx_ring->next_to_clean = 0;
3994 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003995
3996 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003997
3998alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003999 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004000}
4001
4002/**
Alexander Duyck69888672008-09-11 20:05:39 -07004003 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4004 * @adapter: board private structure
4005 *
4006 * If this function returns with an error, then it's possible one or
4007 * more of the rings is populated (while the rest are not). It is the
4008 * callers duty to clean those orphaned rings.
4009 *
4010 * Return 0 on success, negative on failure
4011 **/
4012
4013static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4014{
4015 int i, err = 0;
4016
4017 for (i = 0; i < adapter->num_rx_queues; i++) {
4018 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
4019 if (!err)
4020 continue;
4021 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
4022 break;
4023 }
4024
4025 return err;
4026}
4027
4028/**
Auke Kok9a799d72007-09-15 14:07:45 -07004029 * ixgbe_free_tx_resources - Free Tx Resources per Queue
4030 * @adapter: board private structure
4031 * @tx_ring: Tx descriptor ring for a specific queue
4032 *
4033 * Free all transmit software resources
4034 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07004035void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
4036 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004037{
4038 struct pci_dev *pdev = adapter->pdev;
4039
4040 ixgbe_clean_tx_ring(adapter, tx_ring);
4041
4042 vfree(tx_ring->tx_buffer_info);
4043 tx_ring->tx_buffer_info = NULL;
4044
4045 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
4046
4047 tx_ring->desc = NULL;
4048}
4049
4050/**
4051 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4052 * @adapter: board private structure
4053 *
4054 * Free all transmit software resources
4055 **/
4056static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4057{
4058 int i;
4059
4060 for (i = 0; i < adapter->num_tx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004061 if (adapter->tx_ring[i].desc)
4062 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004063}
4064
4065/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004066 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004067 * @adapter: board private structure
4068 * @rx_ring: ring to clean the resources from
4069 *
4070 * Free all receive software resources
4071 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07004072void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
4073 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004074{
4075 struct pci_dev *pdev = adapter->pdev;
4076
4077 ixgbe_clean_rx_ring(adapter, rx_ring);
4078
4079 vfree(rx_ring->rx_buffer_info);
4080 rx_ring->rx_buffer_info = NULL;
4081
4082 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
4083
4084 rx_ring->desc = NULL;
4085}
4086
4087/**
4088 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4089 * @adapter: board private structure
4090 *
4091 * Free all receive software resources
4092 **/
4093static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4094{
4095 int i;
4096
4097 for (i = 0; i < adapter->num_rx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004098 if (adapter->rx_ring[i].desc)
4099 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004100}
4101
4102/**
Auke Kok9a799d72007-09-15 14:07:45 -07004103 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4104 * @netdev: network interface device structure
4105 * @new_mtu: new value for maximum frame size
4106 *
4107 * Returns 0 on success, negative on failure
4108 **/
4109static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4110{
4111 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4112 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4113
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004114 /* MTU < 68 is an error and causes problems on some kernels */
4115 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07004116 return -EINVAL;
4117
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004118 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004119 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004120 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004121 netdev->mtu = new_mtu;
4122
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004123 if (netif_running(netdev))
4124 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004125
4126 return 0;
4127}
4128
4129/**
4130 * ixgbe_open - Called when a network interface is made active
4131 * @netdev: network interface device structure
4132 *
4133 * Returns 0 on success, negative value on failure
4134 *
4135 * The open entry point is called when a network interface is made
4136 * active by the system (IFF_UP). At this point all resources needed
4137 * for transmit and receive operations are allocated, the interrupt
4138 * handler is registered with the OS, the watchdog timer is started,
4139 * and the stack is notified that the interface is ready.
4140 **/
4141static int ixgbe_open(struct net_device *netdev)
4142{
4143 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4144 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004145
Auke Kok4bebfaa2008-02-11 09:26:01 -08004146 /* disallow open during test */
4147 if (test_bit(__IXGBE_TESTING, &adapter->state))
4148 return -EBUSY;
4149
Jesse Brandeburg54386462009-04-17 20:44:27 +00004150 netif_carrier_off(netdev);
4151
Auke Kok9a799d72007-09-15 14:07:45 -07004152 /* allocate transmit descriptors */
4153 err = ixgbe_setup_all_tx_resources(adapter);
4154 if (err)
4155 goto err_setup_tx;
4156
Auke Kok9a799d72007-09-15 14:07:45 -07004157 /* allocate receive descriptors */
4158 err = ixgbe_setup_all_rx_resources(adapter);
4159 if (err)
4160 goto err_setup_rx;
4161
4162 ixgbe_configure(adapter);
4163
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004164 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004165 if (err)
4166 goto err_req_irq;
4167
Auke Kok9a799d72007-09-15 14:07:45 -07004168 err = ixgbe_up_complete(adapter);
4169 if (err)
4170 goto err_up;
4171
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004172 netif_tx_start_all_queues(netdev);
4173
Auke Kok9a799d72007-09-15 14:07:45 -07004174 return 0;
4175
4176err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004177 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004178 ixgbe_free_irq(adapter);
4179err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07004180err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004181 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004182err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004183 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004184 ixgbe_reset(adapter);
4185
4186 return err;
4187}
4188
4189/**
4190 * ixgbe_close - Disables a network interface
4191 * @netdev: network interface device structure
4192 *
4193 * Returns 0, this is not allowed to fail
4194 *
4195 * The close entry point is called when an interface is de-activated
4196 * by the OS. The hardware is still under the drivers control, but
4197 * needs to be disabled. A global MAC reset is issued to stop the
4198 * hardware, and all transmit and receive resources are freed.
4199 **/
4200static int ixgbe_close(struct net_device *netdev)
4201{
4202 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004203
4204 ixgbe_down(adapter);
4205 ixgbe_free_irq(adapter);
4206
4207 ixgbe_free_all_tx_resources(adapter);
4208 ixgbe_free_all_rx_resources(adapter);
4209
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004210 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004211
4212 return 0;
4213}
4214
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004215#ifdef CONFIG_PM
4216static int ixgbe_resume(struct pci_dev *pdev)
4217{
4218 struct net_device *netdev = pci_get_drvdata(pdev);
4219 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4220 u32 err;
4221
4222 pci_set_power_state(pdev, PCI_D0);
4223 pci_restore_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004224
4225 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004226 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07004227 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004228 "suspend\n");
4229 return err;
4230 }
4231 pci_set_master(pdev);
4232
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004233 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004234
4235 err = ixgbe_init_interrupt_scheme(adapter);
4236 if (err) {
4237 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
4238 "device\n");
4239 return err;
4240 }
4241
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004242 ixgbe_reset(adapter);
4243
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00004244 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4245
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004246 if (netif_running(netdev)) {
4247 err = ixgbe_open(adapter->netdev);
4248 if (err)
4249 return err;
4250 }
4251
4252 netif_device_attach(netdev);
4253
4254 return 0;
4255}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004256#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004257
4258static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004259{
4260 struct net_device *netdev = pci_get_drvdata(pdev);
4261 struct ixgbe_adapter *adapter = netdev_priv(netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004262 struct ixgbe_hw *hw = &adapter->hw;
4263 u32 ctrl, fctrl;
4264 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004265#ifdef CONFIG_PM
4266 int retval = 0;
4267#endif
4268
4269 netif_device_detach(netdev);
4270
4271 if (netif_running(netdev)) {
4272 ixgbe_down(adapter);
4273 ixgbe_free_irq(adapter);
4274 ixgbe_free_all_tx_resources(adapter);
4275 ixgbe_free_all_rx_resources(adapter);
4276 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00004277 ixgbe_clear_interrupt_scheme(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004278
4279#ifdef CONFIG_PM
4280 retval = pci_save_state(pdev);
4281 if (retval)
4282 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004283
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004284#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004285 if (wufc) {
4286 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004287
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004288 /* turn on all-multi mode if wake on multicast is enabled */
4289 if (wufc & IXGBE_WUFC_MC) {
4290 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4291 fctrl |= IXGBE_FCTRL_MPE;
4292 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4293 }
4294
4295 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4296 ctrl |= IXGBE_CTRL_GIO_DIS;
4297 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4298
4299 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4300 } else {
4301 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4302 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4303 }
4304
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004305 if (wufc && hw->mac.type == ixgbe_mac_82599EB)
4306 pci_wake_from_d3(pdev, true);
4307 else
4308 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004309
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004310 *enable_wake = !!wufc;
4311
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004312 ixgbe_release_hw_control(adapter);
4313
4314 pci_disable_device(pdev);
4315
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004316 return 0;
4317}
4318
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004319#ifdef CONFIG_PM
4320static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4321{
4322 int retval;
4323 bool wake;
4324
4325 retval = __ixgbe_shutdown(pdev, &wake);
4326 if (retval)
4327 return retval;
4328
4329 if (wake) {
4330 pci_prepare_to_sleep(pdev);
4331 } else {
4332 pci_wake_from_d3(pdev, false);
4333 pci_set_power_state(pdev, PCI_D3hot);
4334 }
4335
4336 return 0;
4337}
4338#endif /* CONFIG_PM */
4339
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004340static void ixgbe_shutdown(struct pci_dev *pdev)
4341{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004342 bool wake;
4343
4344 __ixgbe_shutdown(pdev, &wake);
4345
4346 if (system_state == SYSTEM_POWER_OFF) {
4347 pci_wake_from_d3(pdev, wake);
4348 pci_set_power_state(pdev, PCI_D3hot);
4349 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004350}
4351
4352/**
Auke Kok9a799d72007-09-15 14:07:45 -07004353 * ixgbe_update_stats - Update the board statistics counters.
4354 * @adapter: board private structure
4355 **/
4356void ixgbe_update_stats(struct ixgbe_adapter *adapter)
4357{
4358 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004359 u64 total_mpc = 0;
4360 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004361
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004362 if (hw->mac.type == ixgbe_mac_82599EB) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004363 u64 rsc_count = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004364 for (i = 0; i < 16; i++)
4365 adapter->hw_rx_no_dma_resources +=
4366 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Alexander Duyckf8212f92009-04-27 22:42:37 +00004367 for (i = 0; i < adapter->num_rx_queues; i++)
4368 rsc_count += adapter->rx_ring[i].rsc_count;
4369 adapter->rsc_count = rsc_count;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004370 }
4371
Auke Kok9a799d72007-09-15 14:07:45 -07004372 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004373 for (i = 0; i < 8; i++) {
4374 /* for packet buffers not used, the register should read 0 */
4375 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
4376 missed_rx += mpc;
4377 adapter->stats.mpc[i] += mpc;
4378 total_mpc += adapter->stats.mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004379 if (hw->mac.type == ixgbe_mac_82598EB)
4380 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004381 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
4382 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
4383 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
4384 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004385 if (hw->mac.type == ixgbe_mac_82599EB) {
4386 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4387 IXGBE_PXONRXCNT(i));
4388 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4389 IXGBE_PXOFFRXCNT(i));
4390 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004391 } else {
4392 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4393 IXGBE_PXONRXC(i));
4394 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4395 IXGBE_PXOFFRXC(i));
4396 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004397 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
4398 IXGBE_PXONTXC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004399 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004400 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004401 }
4402 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
4403 /* work around hardware counting issue */
4404 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07004405
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004406 /* 82598 hardware only has a 32 bit counter in the high register */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004407 if (hw->mac.type == ixgbe_mac_82599EB) {
4408 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
4409 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
4410 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
4411 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
4412 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
4413 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
4414 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
4415 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004416 adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
4417 adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00004418#ifdef IXGBE_FCOE
4419 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
4420 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
4421 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
4422 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
4423 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
4424 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
4425#endif /* IXGBE_FCOE */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004426 } else {
4427 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
4428 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
4429 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
4430 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
4431 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
4432 }
Auke Kok9a799d72007-09-15 14:07:45 -07004433 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
4434 adapter->stats.bprc += bprc;
4435 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004436 if (hw->mac.type == ixgbe_mac_82598EB)
4437 adapter->stats.mprc -= bprc;
Auke Kok9a799d72007-09-15 14:07:45 -07004438 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
4439 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
4440 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
4441 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
4442 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
4443 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
4444 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004445 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004446 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
4447 adapter->stats.lxontxc += lxon;
4448 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
4449 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07004450 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4451 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004452 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
4453 /*
4454 * 82598 errata - tx of flow control packets is included in tx counters
4455 */
4456 xon_off_tot = lxon + lxoff;
4457 adapter->stats.gptc -= xon_off_tot;
4458 adapter->stats.mptc -= xon_off_tot;
4459 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07004460 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4461 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
4462 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07004463 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
4464 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004465 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004466 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
4467 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
4468 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
4469 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
4470 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004471 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
4472
4473 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07004474 adapter->net_stats.multicast = adapter->stats.mprc;
4475
4476 /* Rx Errors */
4477 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004478 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07004479 adapter->net_stats.rx_dropped = 0;
4480 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
4481 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004482 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07004483}
4484
4485/**
4486 * ixgbe_watchdog - Timer Call-back
4487 * @data: pointer to adapter cast into an unsigned long
4488 **/
4489static void ixgbe_watchdog(unsigned long data)
4490{
4491 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004492 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004493 u64 eics = 0;
4494 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004495
Alexander Duyckfe49f042009-06-04 16:00:09 +00004496 /*
4497 * Do the watchdog outside of interrupt context due to the lovely
4498 * delays that some of the newer hardware requires
4499 */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004500
Alexander Duyckfe49f042009-06-04 16:00:09 +00004501 if (test_bit(__IXGBE_DOWN, &adapter->state))
4502 goto watchdog_short_circuit;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004503
Alexander Duyckfe49f042009-06-04 16:00:09 +00004504 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
4505 /*
4506 * for legacy and MSI interrupts don't set any bits
4507 * that are enabled for EIAM, because this operation
4508 * would set *both* EIMS and EICS for any bit in EIAM
4509 */
4510 IXGBE_WRITE_REG(hw, IXGBE_EICS,
4511 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
4512 goto watchdog_reschedule;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004513 }
4514
Alexander Duyckfe49f042009-06-04 16:00:09 +00004515 /* get one bit for every active tx/rx interrupt vector */
4516 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
4517 struct ixgbe_q_vector *qv = adapter->q_vector[i];
4518 if (qv->rxr_count || qv->txr_count)
4519 eics |= ((u64)1 << i);
4520 }
4521
4522 /* Cause software interrupt to ensure rx rings are cleaned */
4523 ixgbe_irq_rearm_queues(adapter, eics);
4524
4525watchdog_reschedule:
4526 /* Reset the timer */
4527 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
4528
4529watchdog_short_circuit:
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004530 schedule_work(&adapter->watchdog_task);
4531}
4532
4533/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004534 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
4535 * @work: pointer to work_struct containing our data
4536 **/
4537static void ixgbe_multispeed_fiber_task(struct work_struct *work)
4538{
4539 struct ixgbe_adapter *adapter = container_of(work,
4540 struct ixgbe_adapter,
4541 multispeed_fiber_task);
4542 struct ixgbe_hw *hw = &adapter->hw;
4543 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004544 bool negotiation;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004545
4546 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
Mallikarjuna R Chilakalaa1f25322009-06-30 11:44:36 +00004547 autoneg = hw->phy.autoneg_advertised;
4548 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004549 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
4550 if (hw->mac.ops.setup_link)
4551 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004552 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4553 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
4554}
4555
4556/**
4557 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
4558 * @work: pointer to work_struct containing our data
4559 **/
4560static void ixgbe_sfp_config_module_task(struct work_struct *work)
4561{
4562 struct ixgbe_adapter *adapter = container_of(work,
4563 struct ixgbe_adapter,
4564 sfp_config_module_task);
4565 struct ixgbe_hw *hw = &adapter->hw;
4566 u32 err;
4567
4568 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004569
4570 /* Time for electrical oscillations to settle down */
4571 msleep(100);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004572 err = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004573
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004574 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00004575 dev_err(&adapter->pdev->dev, "failed to initialize because "
4576 "an unsupported SFP+ module type was detected.\n"
4577 "Reload the driver after installing a supported "
4578 "module.\n");
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004579 unregister_netdev(adapter->netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004580 return;
4581 }
4582 hw->mac.ops.setup_sfp(hw);
4583
Tony Breeds8d1c3c02009-04-09 22:29:10 +00004584 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004585 /* This will also work for DA Twinax connections */
4586 schedule_work(&adapter->multispeed_fiber_task);
4587 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
4588}
4589
4590/**
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004591 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
4592 * @work: pointer to work_struct containing our data
4593 **/
4594static void ixgbe_fdir_reinit_task(struct work_struct *work)
4595{
4596 struct ixgbe_adapter *adapter = container_of(work,
4597 struct ixgbe_adapter,
4598 fdir_reinit_task);
4599 struct ixgbe_hw *hw = &adapter->hw;
4600 int i;
4601
4602 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
4603 for (i = 0; i < adapter->num_tx_queues; i++)
4604 set_bit(__IXGBE_FDIR_INIT_DONE,
4605 &(adapter->tx_ring[i].reinit_state));
4606 } else {
4607 DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, "
4608 "ignored adding FDIR ATR filters \n");
4609 }
4610 /* Done FDIR Re-initialization, enable transmits */
4611 netif_tx_start_all_queues(adapter->netdev);
4612}
4613
4614/**
Alexander Duyck69888672008-09-11 20:05:39 -07004615 * ixgbe_watchdog_task - worker thread to bring link up
4616 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004617 **/
4618static void ixgbe_watchdog_task(struct work_struct *work)
4619{
4620 struct ixgbe_adapter *adapter = container_of(work,
4621 struct ixgbe_adapter,
4622 watchdog_task);
4623 struct net_device *netdev = adapter->netdev;
4624 struct ixgbe_hw *hw = &adapter->hw;
4625 u32 link_speed = adapter->link_speed;
4626 bool link_up = adapter->link_up;
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004627 int i;
4628 struct ixgbe_ring *tx_ring;
4629 int some_tx_pending = 0;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004630
4631 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
4632
4633 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4634 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004635 if (link_up) {
4636#ifdef CONFIG_DCB
4637 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4638 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004639 hw->mac.ops.fc_enable(hw, i);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004640 } else {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004641 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004642 }
4643#else
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004644 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004645#endif
4646 }
4647
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004648 if (link_up ||
4649 time_after(jiffies, (adapter->link_check_timeout +
4650 IXGBE_TRY_LINK_TIMEOUT))) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004651 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004652 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004653 }
4654 adapter->link_up = link_up;
4655 adapter->link_speed = link_speed;
4656 }
Auke Kok9a799d72007-09-15 14:07:45 -07004657
4658 if (link_up) {
4659 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004660 bool flow_rx, flow_tx;
4661
4662 if (hw->mac.type == ixgbe_mac_82599EB) {
4663 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4664 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
Peter P Waskiewicz Jr078788b2009-07-16 15:50:32 +00004665 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
4666 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004667 } else {
4668 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4669 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
Peter P Waskiewicz Jr078788b2009-07-16 15:50:32 +00004670 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
4671 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004672 }
4673
Jeff Kirshera46e5342008-11-27 00:22:21 -08004674 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
4675 "Flow Control: %s\n",
4676 netdev->name,
4677 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
4678 "10 Gbps" :
4679 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
4680 "1 Gbps" : "unknown speed")),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004681 ((flow_rx && flow_tx) ? "RX/TX" :
4682 (flow_rx ? "RX" :
4683 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07004684
4685 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004686 } else {
4687 /* Force detection of hung controller */
4688 adapter->detect_tx_hung = true;
4689 }
4690 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004691 adapter->link_up = false;
4692 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004693 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08004694 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
4695 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07004696 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004697 }
4698 }
4699
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004700 if (!netif_carrier_ok(netdev)) {
4701 for (i = 0; i < adapter->num_tx_queues; i++) {
4702 tx_ring = &adapter->tx_ring[i];
4703 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
4704 some_tx_pending = 1;
4705 break;
4706 }
4707 }
4708
4709 if (some_tx_pending) {
4710 /* We've lost link, so the controller stops DMA,
4711 * but we've got queued Tx work that's never going
4712 * to get done, so reset controller to flush Tx.
4713 * (Do the reset outside of interrupt context).
4714 */
4715 schedule_work(&adapter->reset_task);
4716 }
4717 }
4718
Auke Kok9a799d72007-09-15 14:07:45 -07004719 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004720 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07004721}
4722
Auke Kok9a799d72007-09-15 14:07:45 -07004723static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004724 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
4725 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004726{
4727 struct ixgbe_adv_tx_context_desc *context_desc;
4728 unsigned int i;
4729 int err;
4730 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004731 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
4732 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07004733
4734 if (skb_is_gso(skb)) {
4735 if (skb_header_cloned(skb)) {
4736 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4737 if (err)
4738 return err;
4739 }
4740 l4len = tcp_hdrlen(skb);
4741 *hdr_len += l4len;
4742
Al Viro8327d002007-12-10 18:54:12 +00004743 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004744 struct iphdr *iph = ip_hdr(skb);
4745 iph->tot_len = 0;
4746 iph->check = 0;
4747 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004748 iph->daddr, 0,
4749 IPPROTO_TCP,
4750 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004751 adapter->hw_tso_ctxt++;
4752 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
4753 ipv6_hdr(skb)->payload_len = 0;
4754 tcp_hdr(skb)->check =
4755 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004756 &ipv6_hdr(skb)->daddr,
4757 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004758 adapter->hw_tso6_ctxt++;
4759 }
4760
4761 i = tx_ring->next_to_use;
4762
4763 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4764 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4765
4766 /* VLAN MACLEN IPLEN */
4767 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4768 vlan_macip_lens |=
4769 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4770 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004771 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004772 *hdr_len += skb_network_offset(skb);
4773 vlan_macip_lens |=
4774 (skb_transport_header(skb) - skb_network_header(skb));
4775 *hdr_len +=
4776 (skb_transport_header(skb) - skb_network_header(skb));
4777 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4778 context_desc->seqnum_seed = 0;
4779
4780 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004781 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004782 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004783
Al Viro8327d002007-12-10 18:54:12 +00004784 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004785 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4786 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
4787 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4788
4789 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004790 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07004791 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
4792 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004793 /* use index 1 for TSO */
4794 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004795 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4796
4797 tx_buffer_info->time_stamp = jiffies;
4798 tx_buffer_info->next_to_watch = i;
4799
4800 i++;
4801 if (i == tx_ring->count)
4802 i = 0;
4803 tx_ring->next_to_use = i;
4804
4805 return true;
4806 }
4807 return false;
4808}
4809
4810static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004811 struct ixgbe_ring *tx_ring,
4812 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07004813{
4814 struct ixgbe_adv_tx_context_desc *context_desc;
4815 unsigned int i;
4816 struct ixgbe_tx_buffer *tx_buffer_info;
4817 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4818
4819 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4820 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4821 i = tx_ring->next_to_use;
4822 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4823 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4824
4825 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4826 vlan_macip_lens |=
4827 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4828 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004829 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004830 if (skb->ip_summed == CHECKSUM_PARTIAL)
4831 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004832 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07004833
4834 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4835 context_desc->seqnum_seed = 0;
4836
4837 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004838 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004839
4840 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08004841 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004842 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07004843 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08004844 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4845 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004846 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004847 else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
4848 type_tucmd_mlhl |=
4849 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004850 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004851 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08004852 /* XXX what about other V6 headers?? */
4853 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4854 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004855 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004856 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
4857 type_tucmd_mlhl |=
4858 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004859 break;
Auke Kok41825d72008-02-12 15:20:33 -08004860 default:
4861 if (unlikely(net_ratelimit())) {
4862 DPRINTK(PROBE, WARNING,
4863 "partial checksum but proto=%x!\n",
4864 skb->protocol);
4865 }
4866 break;
4867 }
Auke Kok9a799d72007-09-15 14:07:45 -07004868 }
4869
4870 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004871 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07004872 context_desc->mss_l4len_idx = 0;
4873
4874 tx_buffer_info->time_stamp = jiffies;
4875 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004876
Auke Kok9a799d72007-09-15 14:07:45 -07004877 adapter->hw_csum_tx_good++;
4878 i++;
4879 if (i == tx_ring->count)
4880 i = 0;
4881 tx_ring->next_to_use = i;
4882
4883 return true;
4884 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004885
Auke Kok9a799d72007-09-15 14:07:45 -07004886 return false;
4887}
4888
4889static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004890 struct ixgbe_ring *tx_ring,
Yi Zoueacd73f2009-05-13 13:11:06 +00004891 struct sk_buff *skb, u32 tx_flags,
4892 unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07004893{
4894 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00004895 unsigned int len;
4896 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07004897 unsigned int offset = 0, size, count = 0, i;
4898 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
4899 unsigned int f;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004900 dma_addr_t *map;
Auke Kok9a799d72007-09-15 14:07:45 -07004901
4902 i = tx_ring->next_to_use;
4903
Alexander Duyck44df32c2009-03-31 21:34:23 +00004904 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
4905 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
4906 return 0;
4907 }
4908
4909 map = skb_shinfo(skb)->dma_maps;
4910
Yi Zoueacd73f2009-05-13 13:11:06 +00004911 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
4912 /* excluding fcoe_crc_eof for FCoE */
4913 total -= sizeof(struct fcoe_crc_eof);
4914
4915 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07004916 while (len) {
4917 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4918 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4919
4920 tx_buffer_info->length = size;
Eric Dumazet042a53a2009-06-05 04:04:16 +00004921 tx_buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004922 tx_buffer_info->time_stamp = jiffies;
4923 tx_buffer_info->next_to_watch = i;
4924
4925 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00004926 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07004927 offset += size;
4928 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004929
4930 if (len) {
4931 i++;
4932 if (i == tx_ring->count)
4933 i = 0;
4934 }
Auke Kok9a799d72007-09-15 14:07:45 -07004935 }
4936
4937 for (f = 0; f < nr_frags; f++) {
4938 struct skb_frag_struct *frag;
4939
4940 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00004941 len = min((unsigned int)frag->size, total);
Alexander Duyck44df32c2009-03-31 21:34:23 +00004942 offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004943
4944 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00004945 i++;
4946 if (i == tx_ring->count)
4947 i = 0;
4948
Auke Kok9a799d72007-09-15 14:07:45 -07004949 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4950 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4951
4952 tx_buffer_info->length = size;
Eric Dumazet042a53a2009-06-05 04:04:16 +00004953 tx_buffer_info->dma = map[f] + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004954 tx_buffer_info->time_stamp = jiffies;
4955 tx_buffer_info->next_to_watch = i;
4956
4957 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00004958 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07004959 offset += size;
4960 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07004961 }
Yi Zoueacd73f2009-05-13 13:11:06 +00004962 if (total == 0)
4963 break;
Auke Kok9a799d72007-09-15 14:07:45 -07004964 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00004965
Auke Kok9a799d72007-09-15 14:07:45 -07004966 tx_ring->tx_buffer_info[i].skb = skb;
4967 tx_ring->tx_buffer_info[first].next_to_watch = i;
4968
4969 return count;
4970}
4971
4972static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004973 struct ixgbe_ring *tx_ring,
4974 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004975{
4976 union ixgbe_adv_tx_desc *tx_desc = NULL;
4977 struct ixgbe_tx_buffer *tx_buffer_info;
4978 u32 olinfo_status = 0, cmd_type_len = 0;
4979 unsigned int i;
4980 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
4981
4982 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
4983
4984 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
4985
4986 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4987 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
4988
4989 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
4990 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4991
4992 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004993 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004994
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004995 /* use index 1 context for tso */
4996 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004997 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
4998 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004999 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07005000
5001 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
5002 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005003 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07005004
Yi Zoueacd73f2009-05-13 13:11:06 +00005005 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5006 olinfo_status |= IXGBE_ADVTXD_CC;
5007 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
5008 if (tx_flags & IXGBE_TX_FLAGS_FSO)
5009 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
5010 }
5011
Auke Kok9a799d72007-09-15 14:07:45 -07005012 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
5013
5014 i = tx_ring->next_to_use;
5015 while (count--) {
5016 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5017 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
5018 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
5019 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005020 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07005021 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07005022 i++;
5023 if (i == tx_ring->count)
5024 i = 0;
5025 }
5026
5027 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
5028
5029 /*
5030 * Force memory writes to complete before letting h/w
5031 * know there are new descriptors to fetch. (Only
5032 * applicable for weak-ordered memory model archs,
5033 * such as IA-64).
5034 */
5035 wmb();
5036
5037 tx_ring->next_to_use = i;
5038 writel(i, adapter->hw.hw_addr + tx_ring->tail);
5039}
5040
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005041static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
5042 int queue, u32 tx_flags)
5043{
5044 /* Right now, we support IPv4 only */
5045 struct ixgbe_atr_input atr_input;
5046 struct tcphdr *th;
5047 struct udphdr *uh;
5048 struct iphdr *iph = ip_hdr(skb);
5049 struct ethhdr *eth = (struct ethhdr *)skb->data;
5050 u16 vlan_id, src_port, dst_port, flex_bytes;
5051 u32 src_ipv4_addr, dst_ipv4_addr;
5052 u8 l4type = 0;
5053
5054 /* check if we're UDP or TCP */
5055 if (iph->protocol == IPPROTO_TCP) {
5056 th = tcp_hdr(skb);
5057 src_port = th->source;
5058 dst_port = th->dest;
5059 l4type |= IXGBE_ATR_L4TYPE_TCP;
5060 /* l4type IPv4 type is 0, no need to assign */
5061 } else if(iph->protocol == IPPROTO_UDP) {
5062 uh = udp_hdr(skb);
5063 src_port = uh->source;
5064 dst_port = uh->dest;
5065 l4type |= IXGBE_ATR_L4TYPE_UDP;
5066 /* l4type IPv4 type is 0, no need to assign */
5067 } else {
5068 /* Unsupported L4 header, just bail here */
5069 return;
5070 }
5071
5072 memset(&atr_input, 0, sizeof(struct ixgbe_atr_input));
5073
5074 vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >>
5075 IXGBE_TX_FLAGS_VLAN_SHIFT;
5076 src_ipv4_addr = iph->saddr;
5077 dst_ipv4_addr = iph->daddr;
5078 flex_bytes = eth->h_proto;
5079
5080 ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
5081 ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
5082 ixgbe_atr_set_dst_port_82599(&atr_input, src_port);
5083 ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes);
5084 ixgbe_atr_set_l4type_82599(&atr_input, l4type);
5085 /* src and dst are inverted, think how the receiver sees them */
5086 ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr);
5087 ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr);
5088
5089 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
5090 ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue);
5091}
5092
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005093static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005094 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005095{
5096 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5097
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005098 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005099 /* Herbert's original patch had:
5100 * smp_mb__after_netif_stop_queue();
5101 * but since that doesn't exist yet, just open code it. */
5102 smp_mb();
5103
5104 /* We need to check again in a case another CPU has just
5105 * made room available. */
5106 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
5107 return -EBUSY;
5108
5109 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07005110 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005111 ++adapter->restart_queue;
5112 return 0;
5113}
5114
5115static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005116 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005117{
5118 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
5119 return 0;
5120 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
5121}
5122
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005123static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
5124{
5125 struct ixgbe_adapter *adapter = netdev_priv(dev);
5126
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005127 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
5128 return smp_processor_id();
5129
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005130 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
Lucy Liu36e89d72009-08-05 13:06:34 -07005131 return (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) >> 13;
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005132
5133 return skb_tx_hash(dev, skb);
5134}
5135
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005136static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
5137 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07005138{
5139 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5140 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07005141 unsigned int first;
5142 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005143 u8 hdr_len = 0;
5144 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07005145 int count = 0;
5146 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005147
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005148 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
5149 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005150 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5151 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
5152 tx_flags |= (skb->queue_mapping << 13);
5153 }
5154 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5155 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5156 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Lucy Liu60127862009-07-22 14:07:33 +00005157 if (skb->priority != TC_PRIO_CONTROL) {
5158 tx_flags |= (skb->queue_mapping << 13);
5159 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5160 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5161 } else {
5162 skb->queue_mapping =
5163 adapter->ring_feature[RING_F_DCB].indices-1;
5164 }
Auke Kok9a799d72007-09-15 14:07:45 -07005165 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005166
Lucy Liu60127862009-07-22 14:07:33 +00005167 r_idx = skb->queue_mapping;
5168 tx_ring = &adapter->tx_ring[r_idx];
5169
Yi Zoueacd73f2009-05-13 13:11:06 +00005170 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
Yi Zou09ad1cc2009-09-03 14:56:10 +00005171 (skb->protocol == htons(ETH_P_FCOE))) {
Yi Zoueacd73f2009-05-13 13:11:06 +00005172 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Yi Zou09ad1cc2009-09-03 14:56:10 +00005173#ifdef IXGBE_FCOE
5174 r_idx = smp_processor_id();
5175 r_idx &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
5176 r_idx += adapter->ring_feature[RING_F_FCOE].mask;
5177 tx_ring = &adapter->tx_ring[r_idx];
5178#endif
5179 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005180 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005181 if (skb_is_gso(skb) ||
5182 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00005183 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
5184 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07005185 count++;
5186
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005187 count += TXD_USE_COUNT(skb_headlen(skb));
5188 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07005189 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
5190
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005191 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07005192 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07005193 return NETDEV_TX_BUSY;
5194 }
Auke Kok9a799d72007-09-15 14:07:45 -07005195
Auke Kok9a799d72007-09-15 14:07:45 -07005196 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00005197 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5198#ifdef IXGBE_FCOE
5199 /* setup tx offload for FCoE */
5200 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5201 if (tso < 0) {
5202 dev_kfree_skb_any(skb);
5203 return NETDEV_TX_OK;
5204 }
5205 if (tso)
5206 tx_flags |= IXGBE_TX_FLAGS_FSO;
5207#endif /* IXGBE_FCOE */
5208 } else {
5209 if (skb->protocol == htons(ETH_P_IP))
5210 tx_flags |= IXGBE_TX_FLAGS_IPV4;
5211 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5212 if (tso < 0) {
5213 dev_kfree_skb_any(skb);
5214 return NETDEV_TX_OK;
5215 }
5216
5217 if (tso)
5218 tx_flags |= IXGBE_TX_FLAGS_TSO;
5219 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
5220 (skb->ip_summed == CHECKSUM_PARTIAL))
5221 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005222 }
5223
Yi Zoueacd73f2009-05-13 13:11:06 +00005224 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005225 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005226 /* add the ATR filter if ATR is on */
5227 if (tx_ring->atr_sample_rate) {
5228 ++tx_ring->atr_count;
5229 if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) &&
5230 test_bit(__IXGBE_FDIR_INIT_DONE,
5231 &tx_ring->reinit_state)) {
5232 ixgbe_atr(adapter, skb, tx_ring->queue_index,
5233 tx_flags);
5234 tx_ring->atr_count = 0;
5235 }
5236 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00005237 ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
5238 hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005239 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07005240
Alexander Duyck44df32c2009-03-31 21:34:23 +00005241 } else {
5242 dev_kfree_skb_any(skb);
5243 tx_ring->tx_buffer_info[first].time_stamp = 0;
5244 tx_ring->next_to_use = first;
5245 }
Auke Kok9a799d72007-09-15 14:07:45 -07005246
5247 return NETDEV_TX_OK;
5248}
5249
5250/**
5251 * ixgbe_get_stats - Get System Network Statistics
5252 * @netdev: network interface device structure
5253 *
5254 * Returns the address of the device statistics structure.
5255 * The statistics are actually updated from the timer callback.
5256 **/
5257static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
5258{
5259 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5260
5261 /* only return the current stats */
5262 return &adapter->net_stats;
5263}
5264
5265/**
5266 * ixgbe_set_mac - Change the Ethernet Address of the NIC
5267 * @netdev: network interface device structure
5268 * @p: pointer to an address structure
5269 *
5270 * Returns 0 on success, negative on failure
5271 **/
5272static int ixgbe_set_mac(struct net_device *netdev, void *p)
5273{
5274 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005275 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005276 struct sockaddr *addr = p;
5277
5278 if (!is_valid_ether_addr(addr->sa_data))
5279 return -EADDRNOTAVAIL;
5280
5281 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005282 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07005283
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005284 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07005285
5286 return 0;
5287}
5288
Ben Hutchings6b73e102009-04-29 08:08:58 +00005289static int
5290ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
5291{
5292 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5293 struct ixgbe_hw *hw = &adapter->hw;
5294 u16 value;
5295 int rc;
5296
5297 if (prtad != hw->phy.mdio.prtad)
5298 return -EINVAL;
5299 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
5300 if (!rc)
5301 rc = value;
5302 return rc;
5303}
5304
5305static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
5306 u16 addr, u16 value)
5307{
5308 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5309 struct ixgbe_hw *hw = &adapter->hw;
5310
5311 if (prtad != hw->phy.mdio.prtad)
5312 return -EINVAL;
5313 return hw->phy.ops.write_reg(hw, addr, devad, value);
5314}
5315
5316static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
5317{
5318 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5319
5320 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
5321}
5322
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005323/**
5324 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00005325 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005326 * @netdev: network interface device structure
5327 *
5328 * Returns non-zero on failure
5329 **/
5330static int ixgbe_add_sanmac_netdev(struct net_device *dev)
5331{
5332 int err = 0;
5333 struct ixgbe_adapter *adapter = netdev_priv(dev);
5334 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5335
5336 if (is_valid_ether_addr(mac->san_addr)) {
5337 rtnl_lock();
5338 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5339 rtnl_unlock();
5340 }
5341 return err;
5342}
5343
5344/**
5345 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00005346 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005347 * @netdev: network interface device structure
5348 *
5349 * Returns non-zero on failure
5350 **/
5351static int ixgbe_del_sanmac_netdev(struct net_device *dev)
5352{
5353 int err = 0;
5354 struct ixgbe_adapter *adapter = netdev_priv(dev);
5355 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5356
5357 if (is_valid_ether_addr(mac->san_addr)) {
5358 rtnl_lock();
5359 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5360 rtnl_unlock();
5361 }
5362 return err;
5363}
5364
Auke Kok9a799d72007-09-15 14:07:45 -07005365#ifdef CONFIG_NET_POLL_CONTROLLER
5366/*
5367 * Polling 'interrupt' - used by things like netconsole to send skbs
5368 * without having to re-enable interrupts. It's not called while
5369 * the interrupt routine is executing.
5370 */
5371static void ixgbe_netpoll(struct net_device *netdev)
5372{
5373 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00005374 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005375
Auke Kok9a799d72007-09-15 14:07:45 -07005376 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00005377 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5378 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
5379 for (i = 0; i < num_q_vectors; i++) {
5380 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
5381 ixgbe_msix_clean_many(0, q_vector);
5382 }
5383 } else {
5384 ixgbe_intr(adapter->pdev->irq, netdev);
5385 }
Auke Kok9a799d72007-09-15 14:07:45 -07005386 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07005387}
5388#endif
5389
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005390static const struct net_device_ops ixgbe_netdev_ops = {
5391 .ndo_open = ixgbe_open,
5392 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005393 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005394 .ndo_select_queue = ixgbe_select_queue,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005395 .ndo_get_stats = ixgbe_get_stats,
Chris Leeche90d4002009-03-10 16:00:24 +00005396 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005397 .ndo_set_multicast_list = ixgbe_set_rx_mode,
5398 .ndo_validate_addr = eth_validate_addr,
5399 .ndo_set_mac_address = ixgbe_set_mac,
5400 .ndo_change_mtu = ixgbe_change_mtu,
5401 .ndo_tx_timeout = ixgbe_tx_timeout,
5402 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
5403 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
5404 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00005405 .ndo_do_ioctl = ixgbe_ioctl,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005406#ifdef CONFIG_NET_POLL_CONTROLLER
5407 .ndo_poll_controller = ixgbe_netpoll,
5408#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005409#ifdef IXGBE_FCOE
5410 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
5411 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00005412 .ndo_fcoe_enable = ixgbe_fcoe_enable,
5413 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou332d4a72009-05-13 13:11:53 +00005414#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005415};
5416
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005417/**
Auke Kok9a799d72007-09-15 14:07:45 -07005418 * ixgbe_probe - Device Initialization Routine
5419 * @pdev: PCI device information struct
5420 * @ent: entry in ixgbe_pci_tbl
5421 *
5422 * Returns 0 on success, negative on failure
5423 *
5424 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
5425 * The OS initialization, configuring of the adapter private structure,
5426 * and a hardware reset occur.
5427 **/
5428static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005429 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07005430{
5431 struct net_device *netdev;
5432 struct ixgbe_adapter *adapter = NULL;
5433 struct ixgbe_hw *hw;
5434 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07005435 static int cards_found;
5436 int i, err, pci_using_dac;
Yi Zoueacd73f2009-05-13 13:11:06 +00005437#ifdef IXGBE_FCOE
5438 u16 device_caps;
5439#endif
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005440 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07005441
gouji-new9ce77662009-05-06 10:44:45 +00005442 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005443 if (err)
5444 return err;
5445
Yang Hongyang6a355282009-04-06 19:01:13 -07005446 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
5447 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07005448 pci_using_dac = 1;
5449 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07005450 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005451 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -07005452 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005453 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005454 dev_err(&pdev->dev, "No usable DMA "
5455 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005456 goto err_dma;
5457 }
5458 }
5459 pci_using_dac = 0;
5460 }
5461
gouji-new9ce77662009-05-06 10:44:45 +00005462 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
5463 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07005464 if (err) {
gouji-new9ce77662009-05-06 10:44:45 +00005465 dev_err(&pdev->dev,
5466 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07005467 goto err_pci_reg;
5468 }
5469
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005470 err = pci_enable_pcie_error_reporting(pdev);
5471 if (err) {
5472 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
5473 "0x%x\n", err);
5474 /* non-fatal, continue */
5475 }
5476
Auke Kok9a799d72007-09-15 14:07:45 -07005477 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07005478 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005479
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005480 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07005481 if (!netdev) {
5482 err = -ENOMEM;
5483 goto err_alloc_etherdev;
5484 }
5485
Auke Kok9a799d72007-09-15 14:07:45 -07005486 SET_NETDEV_DEV(netdev, &pdev->dev);
5487
5488 pci_set_drvdata(pdev, netdev);
5489 adapter = netdev_priv(netdev);
5490
5491 adapter->netdev = netdev;
5492 adapter->pdev = pdev;
5493 hw = &adapter->hw;
5494 hw->back = adapter;
5495 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
5496
Jeff Kirsher05857982008-09-11 19:57:00 -07005497 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
5498 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07005499 if (!hw->hw_addr) {
5500 err = -EIO;
5501 goto err_ioremap;
5502 }
5503
5504 for (i = 1; i <= 5; i++) {
5505 if (pci_resource_len(pdev, i) == 0)
5506 continue;
5507 }
5508
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005509 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07005510 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005511 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07005512 strcpy(netdev->name, pci_name(pdev));
5513
Auke Kok9a799d72007-09-15 14:07:45 -07005514 adapter->bd_number = cards_found;
5515
Auke Kok9a799d72007-09-15 14:07:45 -07005516 /* Setup hw api */
5517 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005518 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07005519
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005520 /* EEPROM */
5521 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
5522 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
5523 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
5524 if (!(eec & (1 << 8)))
5525 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
5526
5527 /* PHY */
5528 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08005529 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00005530 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
5531 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
5532 hw->phy.mdio.mmds = 0;
5533 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
5534 hw->phy.mdio.dev = netdev;
5535 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
5536 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08005537
5538 /* set up this timer and work struct before calling get_invariants
5539 * which might start the timer
5540 */
5541 init_timer(&adapter->sfp_timer);
5542 adapter->sfp_timer.function = &ixgbe_sfp_timer;
5543 adapter->sfp_timer.data = (unsigned long) adapter;
5544
5545 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005546
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005547 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
5548 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
5549
5550 /* a new SFP+ module arrival, called from GPI SDP2 context */
5551 INIT_WORK(&adapter->sfp_config_module_task,
5552 ixgbe_sfp_config_module_task);
5553
Don Skidmore8ca783a2009-05-26 20:40:47 -07005554 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005555
5556 /* setup the private structure */
5557 err = ixgbe_sw_init(adapter);
5558 if (err)
5559 goto err_sw_init;
5560
Don Skidmorebf069c92009-05-07 10:39:54 +00005561 /*
5562 * If there is a fan on this device and it has failed log the
5563 * failure.
5564 */
5565 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5566 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5567 if (esdp & IXGBE_ESDP_SDP1)
5568 DPRINTK(PROBE, CRIT,
5569 "Fan has stopped, replace the adapter\n");
5570 }
5571
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005572 /* reset_hw fills in the perm_addr as well */
5573 err = hw->mac.ops.reset_hw(hw);
Don Skidmore8ca783a2009-05-26 20:40:47 -07005574 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
5575 hw->mac.type == ixgbe_mac_82598EB) {
5576 /*
5577 * Start a kernel thread to watch for a module to arrive.
5578 * Only do this for 82598, since 82599 will generate
5579 * interrupts on module arrival.
5580 */
5581 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5582 mod_timer(&adapter->sfp_timer,
5583 round_jiffies(jiffies + (2 * HZ)));
5584 err = 0;
5585 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00005586 dev_err(&adapter->pdev->dev, "failed to initialize because "
5587 "an unsupported SFP+ module type was detected.\n"
5588 "Reload the driver after installing a supported "
5589 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005590 goto err_sw_init;
5591 } else if (err) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005592 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
5593 goto err_sw_init;
5594 }
5595
Auke Kok9a799d72007-09-15 14:07:45 -07005596 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005597 NETIF_F_IP_CSUM |
5598 NETIF_F_HW_VLAN_TX |
5599 NETIF_F_HW_VLAN_RX |
5600 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07005601
Jesse Brandeburge9990a92008-08-26 04:27:24 -07005602 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005603 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07005604 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08005605 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005606
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00005607 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
5608 netdev->features |= NETIF_F_SCTP_CSUM;
5609
Jeff Kirsherad31c402008-06-05 04:05:30 -07005610 netdev->vlan_features |= NETIF_F_TSO;
5611 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07005612 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00005613 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005614 netdev->vlan_features |= NETIF_F_SG;
5615
Alexander Duyck2f90b862008-11-20 20:52:10 -08005616 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5617 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
5618
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005619#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005620 netdev->dcbnl_ops = &dcbnl_ops;
5621#endif
5622
Yi Zoueacd73f2009-05-13 13:11:06 +00005623#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005624 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00005625 if (hw->mac.ops.get_device_caps) {
5626 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00005627 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
5628 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00005629 }
5630 }
5631#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005632 if (pci_using_dac)
5633 netdev->features |= NETIF_F_HIGHDMA;
5634
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005635 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00005636 netdev->features |= NETIF_F_LRO;
5637
Auke Kok9a799d72007-09-15 14:07:45 -07005638 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005639 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07005640 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
5641 err = -EIO;
5642 goto err_eeprom;
5643 }
5644
5645 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
5646 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
5647
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005648 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
5649 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005650 err = -EIO;
5651 goto err_eeprom;
5652 }
5653
5654 init_timer(&adapter->watchdog_timer);
5655 adapter->watchdog_timer.function = &ixgbe_watchdog;
5656 adapter->watchdog_timer.data = (unsigned long)adapter;
5657
5658 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005659 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005660
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005661 err = ixgbe_init_interrupt_scheme(adapter);
5662 if (err)
5663 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07005664
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005665 switch (pdev->device) {
5666 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005667 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
5668 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
Peter P Waskiewicz Jrbdf0a552009-06-04 11:09:58 +00005669 /* Enable ACPI wakeup in GRC */
5670 IXGBE_WRITE_REG(hw, IXGBE_GRC,
5671 (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005672 break;
5673 default:
5674 adapter->wol = 0;
5675 break;
5676 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005677 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
5678
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005679 /* pick up the PCI bus settings for reporting later */
5680 hw->mac.ops.get_bus_info(hw);
5681
Auke Kok9a799d72007-09-15 14:07:45 -07005682 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07005683 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005684 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
5685 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
5686 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
5687 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
5688 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005689 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07005690 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005691 ixgbe_read_pba_num_generic(hw, &part_num);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005692 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
5693 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
5694 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
5695 (part_num >> 8), (part_num & 0xff));
5696 else
5697 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
5698 hw->mac.type, hw->phy.type,
5699 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07005700
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005701 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Auke Kok0c254d82008-02-11 09:25:56 -08005702 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005703 "this card is not sufficient for optimal "
5704 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005705 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005706 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005707 }
5708
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08005709 /* save off EEPROM version number */
5710 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
5711
Auke Kok9a799d72007-09-15 14:07:45 -07005712 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005713 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005714
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005715 if (err == IXGBE_ERR_EEPROM_VERSION) {
5716 /* We are running on a pre-production device, log a warning */
5717 dev_warn(&pdev->dev, "This device is a pre-production "
5718 "adapter/LOM. Please be aware there may be issues "
5719 "associated with your hardware. If you are "
5720 "experiencing problems please contact your Intel or "
5721 "hardware representative who provided you with this "
5722 "hardware.\n");
5723 }
Auke Kok9a799d72007-09-15 14:07:45 -07005724 strcpy(netdev->name, "eth%d");
5725 err = register_netdev(netdev);
5726 if (err)
5727 goto err_register;
5728
Jesse Brandeburg54386462009-04-17 20:44:27 +00005729 /* carrier off reporting is important to ethtool even BEFORE open */
5730 netif_carrier_off(netdev);
5731
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005732 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5733 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5734 INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
5735
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005736#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03005737 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005738 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005739 ixgbe_setup_dca(adapter);
5740 }
5741#endif
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005742 /* add san mac addr to netdev */
5743 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005744
5745 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
5746 cards_found++;
5747 return 0;
5748
5749err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005750 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005751 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005752err_sw_init:
5753err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08005754 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5755 del_timer_sync(&adapter->sfp_timer);
5756 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005757 cancel_work_sync(&adapter->multispeed_fiber_task);
5758 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005759 iounmap(hw->hw_addr);
5760err_ioremap:
5761 free_netdev(netdev);
5762err_alloc_etherdev:
gouji-new9ce77662009-05-06 10:44:45 +00005763 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5764 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005765err_pci_reg:
5766err_dma:
5767 pci_disable_device(pdev);
5768 return err;
5769}
5770
5771/**
5772 * ixgbe_remove - Device Removal Routine
5773 * @pdev: PCI device information struct
5774 *
5775 * ixgbe_remove is called by the PCI subsystem to alert the driver
5776 * that it should release a PCI device. The could be caused by a
5777 * Hot-Plug event, or because the driver is going to be removed from
5778 * memory.
5779 **/
5780static void __devexit ixgbe_remove(struct pci_dev *pdev)
5781{
5782 struct net_device *netdev = pci_get_drvdata(pdev);
5783 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005784 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005785
5786 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08005787 /* clear the module not found bit to make sure the worker won't
5788 * reschedule
5789 */
5790 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07005791 del_timer_sync(&adapter->watchdog_timer);
5792
Donald Skidmorec4900be2008-11-20 21:11:42 -08005793 del_timer_sync(&adapter->sfp_timer);
5794 cancel_work_sync(&adapter->watchdog_task);
5795 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005796 cancel_work_sync(&adapter->multispeed_fiber_task);
5797 cancel_work_sync(&adapter->sfp_config_module_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005798 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5799 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5800 cancel_work_sync(&adapter->fdir_reinit_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005801 flush_scheduled_work();
5802
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005803#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005804 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
5805 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
5806 dca_remove_requester(&pdev->dev);
5807 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
5808 }
5809
5810#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005811#ifdef IXGBE_FCOE
5812 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
5813 ixgbe_cleanup_fcoe(adapter);
5814
5815#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005816
5817 /* remove the added san mac */
5818 ixgbe_del_sanmac_netdev(netdev);
5819
Donald Skidmorec4900be2008-11-20 21:11:42 -08005820 if (netdev->reg_state == NETREG_REGISTERED)
5821 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005822
Alexander Duyck7a921c92009-05-06 10:43:28 +00005823 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005824
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005825 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005826
5827 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00005828 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5829 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005830
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005831 DPRINTK(PROBE, INFO, "complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005832
Auke Kok9a799d72007-09-15 14:07:45 -07005833 free_netdev(netdev);
5834
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005835 err = pci_disable_pcie_error_reporting(pdev);
5836 if (err)
5837 dev_err(&pdev->dev,
5838 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
5839
Auke Kok9a799d72007-09-15 14:07:45 -07005840 pci_disable_device(pdev);
5841}
5842
5843/**
5844 * ixgbe_io_error_detected - called when PCI error is detected
5845 * @pdev: Pointer to PCI device
5846 * @state: The current pci connection state
5847 *
5848 * This function is called after a PCI bus error affecting
5849 * this device has been detected.
5850 */
5851static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005852 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07005853{
5854 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005855 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005856
5857 netif_device_detach(netdev);
5858
Breno Leitao3044b8d2009-05-06 10:44:26 +00005859 if (state == pci_channel_io_perm_failure)
5860 return PCI_ERS_RESULT_DISCONNECT;
5861
Auke Kok9a799d72007-09-15 14:07:45 -07005862 if (netif_running(netdev))
5863 ixgbe_down(adapter);
5864 pci_disable_device(pdev);
5865
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005866 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07005867 return PCI_ERS_RESULT_NEED_RESET;
5868}
5869
5870/**
5871 * ixgbe_io_slot_reset - called after the pci bus has been reset.
5872 * @pdev: Pointer to PCI device
5873 *
5874 * Restart the card from scratch, as if from a cold-boot.
5875 */
5876static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
5877{
5878 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005879 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005880 pci_ers_result_t result;
5881 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005882
gouji-new9ce77662009-05-06 10:44:45 +00005883 if (pci_enable_device_mem(pdev)) {
Auke Kok9a799d72007-09-15 14:07:45 -07005884 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005885 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005886 result = PCI_ERS_RESULT_DISCONNECT;
5887 } else {
5888 pci_set_master(pdev);
5889 pci_restore_state(pdev);
5890
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005891 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005892
5893 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00005894 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005895 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07005896 }
Auke Kok9a799d72007-09-15 14:07:45 -07005897
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005898 err = pci_cleanup_aer_uncorrect_error_status(pdev);
5899 if (err) {
5900 dev_err(&pdev->dev,
5901 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
5902 /* non-fatal, continue */
5903 }
Auke Kok9a799d72007-09-15 14:07:45 -07005904
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005905 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07005906}
5907
5908/**
5909 * ixgbe_io_resume - called when traffic can start flowing again.
5910 * @pdev: Pointer to PCI device
5911 *
5912 * This callback is called when the error recovery driver tells us that
5913 * its OK to resume normal operation.
5914 */
5915static void ixgbe_io_resume(struct pci_dev *pdev)
5916{
5917 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005918 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005919
5920 if (netif_running(netdev)) {
5921 if (ixgbe_up(adapter)) {
5922 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
5923 return;
5924 }
5925 }
5926
5927 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005928}
5929
5930static struct pci_error_handlers ixgbe_err_handler = {
5931 .error_detected = ixgbe_io_error_detected,
5932 .slot_reset = ixgbe_io_slot_reset,
5933 .resume = ixgbe_io_resume,
5934};
5935
5936static struct pci_driver ixgbe_driver = {
5937 .name = ixgbe_driver_name,
5938 .id_table = ixgbe_pci_tbl,
5939 .probe = ixgbe_probe,
5940 .remove = __devexit_p(ixgbe_remove),
5941#ifdef CONFIG_PM
5942 .suspend = ixgbe_suspend,
5943 .resume = ixgbe_resume,
5944#endif
5945 .shutdown = ixgbe_shutdown,
5946 .err_handler = &ixgbe_err_handler
5947};
5948
5949/**
5950 * ixgbe_init_module - Driver Registration Routine
5951 *
5952 * ixgbe_init_module is the first routine called when the driver is
5953 * loaded. All it does is register with the PCI subsystem.
5954 **/
5955static int __init ixgbe_init_module(void)
5956{
5957 int ret;
5958 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
5959 ixgbe_driver_string, ixgbe_driver_version);
5960
5961 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
5962
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005963#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005964 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005965#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005966
Auke Kok9a799d72007-09-15 14:07:45 -07005967 ret = pci_register_driver(&ixgbe_driver);
5968 return ret;
5969}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005970
Auke Kok9a799d72007-09-15 14:07:45 -07005971module_init(ixgbe_init_module);
5972
5973/**
5974 * ixgbe_exit_module - Driver Exit Cleanup Routine
5975 *
5976 * ixgbe_exit_module is called just before the driver is removed
5977 * from memory.
5978 **/
5979static void __exit ixgbe_exit_module(void)
5980{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005981#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005982 dca_unregister_notify(&dca_notifier);
5983#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005984 pci_unregister_driver(&ixgbe_driver);
5985}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005986
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005987#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005988static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005989 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005990{
5991 int ret_val;
5992
5993 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005994 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005995
5996 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
5997}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005998
Alexander Duyckb4533682009-03-31 21:32:42 +00005999#endif /* CONFIG_IXGBE_DCA */
6000#ifdef DEBUG
6001/**
6002 * ixgbe_get_hw_dev_name - return device name string
6003 * used by hardware layer to print debugging information
6004 **/
6005char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
6006{
6007 struct ixgbe_adapter *adapter = hw->back;
6008 return adapter->netdev->name;
6009}
6010
6011#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006012module_exit(ixgbe_exit_module);
6013
6014/* ixgbe_main.c */