blob: cf39f5a47037432d3a037d5b37c156f754b7d114 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Peter P Waskiewicz Jr3efac5a2009-02-01 01:19:20 -08004 Copyright(c) 1999 - 2009 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
35#include <linux/ip.h>
36#include <linux/tcp.h>
37#include <linux/ipv6.h>
38#include <net/checksum.h>
39#include <net/ip6_checksum.h>
40#include <linux/ethtool.h>
41#include <linux/if_vlan.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000042#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070043
44#include "ixgbe.h"
45#include "ixgbe_common.h"
46
47char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070048static const char ixgbe_driver_string[] =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070049 "Intel(R) 10 Gigabit PCI Express Network Driver";
Auke Kok9a799d72007-09-15 14:07:45 -070050
Peter P Waskiewicz Jra1c1db32009-06-04 16:02:44 +000051#define DRV_VERSION "2.0.34-k2"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070052const char ixgbe_driver_version[] = DRV_VERSION;
Peter P Waskiewicz Jr3efac5a2009-02-01 01:19:20 -080053static char ixgbe_copyright[] = "Copyright (c) 1999-2009 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070054
55static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070056 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000057 [board_82599] = &ixgbe_82599_info,
Auke Kok9a799d72007-09-15 14:07:45 -070058};
59
60/* ixgbe_pci_tbl - PCI Device ID Table
61 *
62 * Wildcard entries (PCI_ANY_ID) should come last
63 * Last entry must be all 0s
64 *
65 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
66 * Class, Class Mask, private data (not used) }
67 */
68static struct pci_device_id ixgbe_pci_tbl[] = {
Don Skidmore1e336d02009-01-26 20:57:51 -080069 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
70 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070071 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070072 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070073 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070074 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070075 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
76 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070077 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070078 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070079 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
80 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080081 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
82 board_82598 },
83 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
84 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070085 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
86 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080087 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
88 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -080089 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
90 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +000091 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
92 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +000093 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
94 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +000095 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
96 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -070097
98 /* required last entry */
99 {0, }
100};
101MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
102
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400103#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800104static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700105 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800106static struct notifier_block dca_notifier = {
107 .notifier_call = ixgbe_notify_dca,
108 .next = NULL,
109 .priority = 0
110};
111#endif
112
Auke Kok9a799d72007-09-15 14:07:45 -0700113MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
114MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
115MODULE_LICENSE("GPL");
116MODULE_VERSION(DRV_VERSION);
117
118#define DEFAULT_DEBUG_LEVEL_SHIFT 3
119
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800120static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
121{
122 u32 ctrl_ext;
123
124 /* Let firmware take over control of h/w */
125 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
126 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700127 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800128}
129
130static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
131{
132 u32 ctrl_ext;
133
134 /* Let firmware know the driver has taken over */
135 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
136 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700137 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800138}
Auke Kok9a799d72007-09-15 14:07:45 -0700139
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000140/*
141 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
142 * @adapter: pointer to adapter struct
143 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
144 * @queue: queue to map the corresponding interrupt to
145 * @msix_vector: the vector to map to the corresponding queue
146 *
147 */
148static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
149 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700150{
151 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000152 struct ixgbe_hw *hw = &adapter->hw;
153 switch (hw->mac.type) {
154 case ixgbe_mac_82598EB:
155 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
156 if (direction == -1)
157 direction = 0;
158 index = (((direction * 64) + queue) >> 2) & 0x1F;
159 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
160 ivar &= ~(0xFF << (8 * (queue & 0x3)));
161 ivar |= (msix_vector << (8 * (queue & 0x3)));
162 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
163 break;
164 case ixgbe_mac_82599EB:
165 if (direction == -1) {
166 /* other causes */
167 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
168 index = ((queue & 1) * 8);
169 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
170 ivar &= ~(0xFF << index);
171 ivar |= (msix_vector << index);
172 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
173 break;
174 } else {
175 /* tx or rx causes */
176 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
177 index = ((16 * (queue & 1)) + (8 * direction));
178 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
179 ivar &= ~(0xFF << index);
180 ivar |= (msix_vector << index);
181 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
182 break;
183 }
184 default:
185 break;
186 }
Auke Kok9a799d72007-09-15 14:07:45 -0700187}
188
Alexander Duyckfe49f042009-06-04 16:00:09 +0000189static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
190 u64 qmask)
191{
192 u32 mask;
193
194 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
195 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
196 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
197 } else {
198 mask = (qmask & 0xFFFFFFFF);
199 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
200 mask = (qmask >> 32);
201 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
202 }
203}
204
Auke Kok9a799d72007-09-15 14:07:45 -0700205static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700206 struct ixgbe_tx_buffer
207 *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700208{
Alexander Duyck44df32c2009-03-31 21:34:23 +0000209 tx_buffer_info->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700210 if (tx_buffer_info->skb) {
Alexander Duyck44df32c2009-03-31 21:34:23 +0000211 skb_dma_unmap(&adapter->pdev->dev, tx_buffer_info->skb,
212 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700213 dev_kfree_skb_any(tx_buffer_info->skb);
214 tx_buffer_info->skb = NULL;
215 }
Alexander Duyck44df32c2009-03-31 21:34:23 +0000216 tx_buffer_info->time_stamp = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700217 /* tx_buffer_info must be completely set up in the transmit path */
218}
219
220static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700221 struct ixgbe_ring *tx_ring,
222 unsigned int eop)
Auke Kok9a799d72007-09-15 14:07:45 -0700223{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700224 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700225
Auke Kok9a799d72007-09-15 14:07:45 -0700226 /* Detect a transmit hang in hardware, this serializes the
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700227 * check with the clearing of time_stamp and movement of eop */
Auke Kok9a799d72007-09-15 14:07:45 -0700228 adapter->detect_tx_hung = false;
Alexander Duyck44df32c2009-03-31 21:34:23 +0000229 if (tx_ring->tx_buffer_info[eop].time_stamp &&
Auke Kok9a799d72007-09-15 14:07:45 -0700230 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
231 !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) {
232 /* detected Tx unit hang */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700233 union ixgbe_adv_tx_desc *tx_desc;
234 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
Auke Kok9a799d72007-09-15 14:07:45 -0700235 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700236 " Tx Queue <%d>\n"
237 " TDH, TDT <%x>, <%x>\n"
Auke Kok9a799d72007-09-15 14:07:45 -0700238 " next_to_use <%x>\n"
239 " next_to_clean <%x>\n"
240 "tx_buffer_info[next_to_clean]\n"
241 " time_stamp <%lx>\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700242 " jiffies <%lx>\n",
243 tx_ring->queue_index,
Alexander Duyck44df32c2009-03-31 21:34:23 +0000244 IXGBE_READ_REG(hw, tx_ring->head),
245 IXGBE_READ_REG(hw, tx_ring->tail),
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700246 tx_ring->next_to_use, eop,
247 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
Auke Kok9a799d72007-09-15 14:07:45 -0700248 return true;
249 }
250
251 return false;
252}
253
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700254#define IXGBE_MAX_TXD_PWR 14
255#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800256
257/* Tx Descriptors needed, worst case */
258#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
259 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
260#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700261 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800262
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700263static void ixgbe_tx_timeout(struct net_device *netdev);
264
Auke Kok9a799d72007-09-15 14:07:45 -0700265/**
266 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000267 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700268 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700269 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000270static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700271 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700272{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000273 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700274 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800275 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
276 struct ixgbe_tx_buffer *tx_buffer_info;
277 unsigned int i, eop, count = 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700278 unsigned int total_bytes = 0, total_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700279
280 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800281 eop = tx_ring->tx_buffer_info[i].next_to_watch;
282 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
283
284 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000285 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800286 bool cleaned = false;
287 for ( ; !cleaned; count++) {
288 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700289 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
290 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800291 cleaned = (i == eop);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700292 skb = tx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700293
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800294 if (cleaned && skb) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800295 unsigned int segs, bytecount;
Yi Zou3d8fd382009-06-08 14:38:44 +0000296 unsigned int hlen = skb_headlen(skb);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700297
298 /* gso_segs is currently only valid for tcp */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800299 segs = skb_shinfo(skb)->gso_segs ?: 1;
Yi Zou3d8fd382009-06-08 14:38:44 +0000300#ifdef IXGBE_FCOE
301 /* adjust for FCoE Sequence Offload */
302 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
303 && (skb->protocol == htons(ETH_P_FCOE)) &&
304 skb_is_gso(skb)) {
305 hlen = skb_transport_offset(skb) +
306 sizeof(struct fc_frame_header) +
307 sizeof(struct fcoe_crc_eof);
308 segs = DIV_ROUND_UP(skb->len - hlen,
309 skb_shinfo(skb)->gso_size);
310 }
311#endif /* IXGBE_FCOE */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800312 /* multiply data chunks by size of headers */
Yi Zou3d8fd382009-06-08 14:38:44 +0000313 bytecount = ((segs - 1) * hlen) + skb->len;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700314 total_packets += segs;
315 total_bytes += bytecount;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800316 }
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700317
Auke Kok9a799d72007-09-15 14:07:45 -0700318 ixgbe_unmap_and_free_tx_resource(adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700319 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700320
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800321 tx_desc->wb.status = 0;
322
Auke Kok9a799d72007-09-15 14:07:45 -0700323 i++;
324 if (i == tx_ring->count)
325 i = 0;
326 }
327
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800328 eop = tx_ring->tx_buffer_info[i].next_to_watch;
329 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
330 }
331
Auke Kok9a799d72007-09-15 14:07:45 -0700332 tx_ring->next_to_clean = i;
333
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800334#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700335 if (unlikely(count && netif_carrier_ok(netdev) &&
336 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800337 /* Make sure that anybody stopping the queue after this
338 * sees the new next_to_clean.
339 */
340 smp_mb();
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800341 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
342 !test_bit(__IXGBE_DOWN, &adapter->state)) {
343 netif_wake_subqueue(netdev, tx_ring->queue_index);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700344 ++adapter->restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800345 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800346 }
Auke Kok9a799d72007-09-15 14:07:45 -0700347
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700348 if (adapter->detect_tx_hung) {
349 if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
350 /* schedule immediate reset if we believe we hung */
351 DPRINTK(PROBE, INFO,
352 "tx hang %d detected, resetting adapter\n",
353 adapter->tx_timeout_count + 1);
354 ixgbe_tx_timeout(adapter->netdev);
355 }
356 }
Auke Kok9a799d72007-09-15 14:07:45 -0700357
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700358 /* re-arm the interrupt */
Alexander Duyckfe49f042009-06-04 16:00:09 +0000359 if (count >= tx_ring->work_limit)
360 ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -0700361
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700362 tx_ring->total_bytes += total_bytes;
363 tx_ring->total_packets += total_packets;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700364 tx_ring->stats.packets += total_packets;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800365 tx_ring->stats.bytes += total_bytes;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700366 adapter->net_stats.tx_bytes += total_bytes;
367 adapter->net_stats.tx_packets += total_packets;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000368 return (count < tx_ring->work_limit);
Auke Kok9a799d72007-09-15 14:07:45 -0700369}
370
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400371#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800372static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700373 struct ixgbe_ring *rx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800374{
375 u32 rxctrl;
376 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700377 int q = rx_ring - adapter->rx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800378
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700379 if (rx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800380 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000381 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
382 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
383 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
384 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
385 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
386 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
387 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
388 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800389 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
390 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
Don Skidmore15005a32009-01-19 16:54:13 -0800391 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
392 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000393 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800394 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700395 rx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800396 }
397 put_cpu();
398}
399
400static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700401 struct ixgbe_ring *tx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800402{
403 u32 txctrl;
404 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700405 int q = tx_ring - adapter->tx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800406
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700407 if (tx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800408 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000409 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
410 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
411 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
412 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
413 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
414 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
415 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
416 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800417 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
418 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700419 tx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800420 }
421 put_cpu();
422}
423
424static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
425{
426 int i;
427
428 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
429 return;
430
Alexander Duycke35ec122009-05-21 13:07:12 +0000431 /* always use CB2 mode, difference is masked in the CB driver */
432 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
433
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800434 for (i = 0; i < adapter->num_tx_queues; i++) {
435 adapter->tx_ring[i].cpu = -1;
436 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
437 }
438 for (i = 0; i < adapter->num_rx_queues; i++) {
439 adapter->rx_ring[i].cpu = -1;
440 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
441 }
442}
443
444static int __ixgbe_notify_dca(struct device *dev, void *data)
445{
446 struct net_device *netdev = dev_get_drvdata(dev);
447 struct ixgbe_adapter *adapter = netdev_priv(netdev);
448 unsigned long event = *(unsigned long *)data;
449
450 switch (event) {
451 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700452 /* if we're already enabled, don't do it again */
453 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
454 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300455 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700456 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800457 ixgbe_setup_dca(adapter);
458 break;
459 }
460 /* Fall Through since DCA is disabled. */
461 case DCA_PROVIDER_REMOVE:
462 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
463 dca_remove_requester(dev);
464 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
465 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
466 }
467 break;
468 }
469
Denis V. Lunev652f0932008-03-27 14:39:17 +0300470 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800471}
472
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400473#endif /* CONFIG_IXGBE_DCA */
Auke Kok9a799d72007-09-15 14:07:45 -0700474/**
475 * ixgbe_receive_skb - Send a completed packet up the stack
476 * @adapter: board private structure
477 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700478 * @status: hardware indication of status of receive
479 * @rx_ring: rx descriptor ring (for a specific queue) to setup
480 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -0700481 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800482static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700483 struct sk_buff *skb, u8 status,
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000484 struct ixgbe_ring *ring,
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700485 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -0700486{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800487 struct ixgbe_adapter *adapter = q_vector->adapter;
488 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700489 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
490 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -0700491
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000492 skb_record_rx_queue(skb, ring->queue_index);
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000493 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800494 if (adapter->vlgrp && is_vlan && (tag != 0))
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800495 vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700496 else
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800497 napi_gro_receive(napi, skb);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700498 } else {
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000499 if (adapter->vlgrp && is_vlan && (tag != 0))
500 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
501 else
502 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700503 }
504}
505
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800506/**
507 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
508 * @adapter: address of board private structure
509 * @status_err: hardware indication of status of receive
510 * @skb: skb currently being received and modified
511 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700512static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700513 u32 status_err, struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700514{
515 skb->ip_summed = CHECKSUM_NONE;
516
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700517 /* Rx csum disabled */
518 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -0700519 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800520
521 /* if IP and error */
522 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
523 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700524 adapter->hw_csum_rx_error++;
525 return;
526 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800527
528 if (!(status_err & IXGBE_RXD_STAT_L4CS))
529 return;
530
531 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
532 adapter->hw_csum_rx_error++;
533 return;
534 }
535
Auke Kok9a799d72007-09-15 14:07:45 -0700536 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800537 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -0700538 adapter->hw_csum_rx_good++;
539}
540
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000541static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
542 struct ixgbe_ring *rx_ring, u32 val)
543{
544 /*
545 * Force memory writes to complete before letting h/w
546 * know there are new descriptors to fetch. (Only
547 * applicable for weak-ordered memory model archs,
548 * such as IA-64).
549 */
550 wmb();
551 IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
552}
553
Auke Kok9a799d72007-09-15 14:07:45 -0700554/**
555 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
556 * @adapter: address of board private structure
557 **/
558static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700559 struct ixgbe_ring *rx_ring,
560 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700561{
Auke Kok9a799d72007-09-15 14:07:45 -0700562 struct pci_dev *pdev = adapter->pdev;
563 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700564 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700565 unsigned int i;
Auke Kok9a799d72007-09-15 14:07:45 -0700566
567 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700568 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700569
570 while (cleaned_count--) {
571 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
572
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700573 if (!bi->page_dma &&
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700574 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700575 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700576 bi->page = alloc_page(GFP_ATOMIC);
577 if (!bi->page) {
578 adapter->alloc_rx_page_failed++;
579 goto no_buffers;
580 }
581 bi->page_offset = 0;
582 } else {
583 /* use a half page if we're re-using */
584 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700585 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700586
587 bi->page_dma = pci_map_page(pdev, bi->page,
588 bi->page_offset,
589 (PAGE_SIZE / 2),
590 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700591 }
592
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700593 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800594 struct sk_buff *skb;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000595 skb = netdev_alloc_skb(adapter->netdev,
596 (rx_ring->rx_buf_len +
597 NET_IP_ALIGN));
Auke Kok9a799d72007-09-15 14:07:45 -0700598
599 if (!skb) {
600 adapter->alloc_rx_buff_failed++;
601 goto no_buffers;
602 }
603
604 /*
605 * Make buffer alignment 2 beyond a 16 byte boundary
606 * this will result in a 16 byte aligned IP header after
607 * the 14 byte MAC header is removed
608 */
609 skb_reserve(skb, NET_IP_ALIGN);
610
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700611 bi->skb = skb;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000612 bi->dma = pci_map_single(pdev, skb->data,
613 rx_ring->rx_buf_len,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700614 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700615 }
616 /* Refresh the desc even if buffer_addrs didn't change because
617 * each write-back erases this info. */
618 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700619 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
620 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700621 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700622 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700623 }
624
625 i++;
626 if (i == rx_ring->count)
627 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700628 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700629 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700630
Auke Kok9a799d72007-09-15 14:07:45 -0700631no_buffers:
632 if (rx_ring->next_to_use != i) {
633 rx_ring->next_to_use = i;
634 if (i-- == 0)
635 i = (rx_ring->count - 1);
636
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000637 ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700638 }
639}
640
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700641static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
642{
643 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
644}
645
646static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
647{
648 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
649}
650
Alexander Duyckf8212f92009-04-27 22:42:37 +0000651static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
652{
653 return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
654 IXGBE_RXDADV_RSCCNT_MASK) >>
655 IXGBE_RXDADV_RSCCNT_SHIFT;
656}
657
658/**
659 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
660 * @skb: pointer to the last skb in the rsc queue
661 *
662 * This function changes a queue full of hw rsc buffers into a completed
663 * packet. It uses the ->prev pointers to find the first packet and then
664 * turns it into the frag list owner.
665 **/
666static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
667{
668 unsigned int frag_list_size = 0;
669
670 while (skb->prev) {
671 struct sk_buff *prev = skb->prev;
672 frag_list_size += skb->len;
673 skb->prev = NULL;
674 skb = prev;
675 }
676
677 skb_shinfo(skb)->frag_list = skb->next;
678 skb->next = NULL;
679 skb->len += frag_list_size;
680 skb->data_len += frag_list_size;
681 skb->truesize += frag_list_size;
682 return skb;
683}
684
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800685static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700686 struct ixgbe_ring *rx_ring,
687 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700688{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800689 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -0700690 struct pci_dev *pdev = adapter->pdev;
691 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
692 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
693 struct sk_buff *skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000694 unsigned int i, rsc_count = 0;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700695 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700696 u16 hdr_info;
697 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700698 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800699 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +0000700#ifdef IXGBE_FCOE
701 int ddp_bytes = 0;
702#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -0700703
704 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700705 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
706 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
707 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700708
709 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700710 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700711 if (*work_done >= work_to_do)
712 break;
713 (*work_done)++;
714
715 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700716 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
717 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700718 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700719 if (hdr_info & IXGBE_RXDADV_SPH)
720 adapter->rx_hdr_split++;
721 if (len > IXGBE_RX_HDR_SIZE)
722 len = IXGBE_RX_HDR_SIZE;
723 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700724 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700725 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700726 }
Auke Kok9a799d72007-09-15 14:07:45 -0700727
728 cleaned = true;
729 skb = rx_buffer_info->skb;
730 prefetch(skb->data - NET_IP_ALIGN);
731 rx_buffer_info->skb = NULL;
732
Alexander Duyck21fa4e62009-06-04 15:59:49 +0000733 if (rx_buffer_info->dma) {
Auke Kok9a799d72007-09-15 14:07:45 -0700734 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800735 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700736 PCI_DMA_FROMDEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000737 rx_buffer_info->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700738 skb_put(skb, len);
739 }
740
741 if (upper_len) {
742 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700743 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700744 rx_buffer_info->page_dma = 0;
745 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700746 rx_buffer_info->page,
747 rx_buffer_info->page_offset,
748 upper_len);
749
750 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
751 (page_count(rx_buffer_info->page) != 1))
752 rx_buffer_info->page = NULL;
753 else
754 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700755
756 skb->len += upper_len;
757 skb->data_len += upper_len;
758 skb->truesize += upper_len;
759 }
760
761 i++;
762 if (i == rx_ring->count)
763 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700764
765 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
766 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -0700767 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000768
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +0000769 if (adapter->flags & IXGBE_FLAG2_RSC_CAPABLE)
Alexander Duyckf8212f92009-04-27 22:42:37 +0000770 rsc_count = ixgbe_get_rsc_count(rx_desc);
771
772 if (rsc_count) {
773 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
774 IXGBE_RXDADV_NEXTP_SHIFT;
775 next_buffer = &rx_ring->rx_buffer_info[nextp];
776 rx_ring->rsc_count += (rsc_count - 1);
777 } else {
778 next_buffer = &rx_ring->rx_buffer_info[i];
779 }
780
Auke Kok9a799d72007-09-15 14:07:45 -0700781 if (staterr & IXGBE_RXD_STAT_EOP) {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000782 if (skb->prev)
783 skb = ixgbe_transform_rsc_queue(skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700784 rx_ring->stats.packets++;
785 rx_ring->stats.bytes += skb->len;
786 } else {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000787 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
788 rx_buffer_info->skb = next_buffer->skb;
789 rx_buffer_info->dma = next_buffer->dma;
790 next_buffer->skb = skb;
791 next_buffer->dma = 0;
792 } else {
793 skb->next = next_buffer->skb;
794 skb->next->prev = skb;
795 }
Auke Kok9a799d72007-09-15 14:07:45 -0700796 adapter->non_eop_descs++;
797 goto next_desc;
798 }
799
800 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
801 dev_kfree_skb_irq(skb);
802 goto next_desc;
803 }
804
805 ixgbe_rx_checksum(adapter, staterr, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800806
807 /* probably a little skewed due to removing CRC */
808 total_rx_bytes += skb->len;
809 total_rx_packets++;
810
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700811 skb->protocol = eth_type_trans(skb, adapter->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +0000812#ifdef IXGBE_FCOE
813 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +0000814 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
815 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
816 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +0000817 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +0000818 }
Yi Zou332d4a72009-05-13 13:11:53 +0000819#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000820 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700821
822next_desc:
823 rx_desc->wb.upper.status_error = 0;
824
825 /* return some buffers to hardware, one at a time is too slow */
826 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
827 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
828 cleaned_count = 0;
829 }
830
831 /* use prefetched values */
832 rx_desc = next_rxd;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000833 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700834
835 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700836 }
837
Auke Kok9a799d72007-09-15 14:07:45 -0700838 rx_ring->next_to_clean = i;
839 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
840
841 if (cleaned_count)
842 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
843
Yi Zou3d8fd382009-06-08 14:38:44 +0000844#ifdef IXGBE_FCOE
845 /* include DDPed FCoE data */
846 if (ddp_bytes > 0) {
847 unsigned int mss;
848
849 mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) -
850 sizeof(struct fc_frame_header) -
851 sizeof(struct fcoe_crc_eof);
852 if (mss > 512)
853 mss &= ~511;
854 total_rx_bytes += ddp_bytes;
855 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
856 }
857#endif /* IXGBE_FCOE */
858
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800859 rx_ring->total_packets += total_rx_packets;
860 rx_ring->total_bytes += total_rx_bytes;
861 adapter->net_stats.rx_bytes += total_rx_bytes;
862 adapter->net_stats.rx_packets += total_rx_packets;
863
Auke Kok9a799d72007-09-15 14:07:45 -0700864 return cleaned;
865}
866
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800867static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700868/**
869 * ixgbe_configure_msix - Configure MSI-X hardware
870 * @adapter: board private structure
871 *
872 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
873 * interrupts.
874 **/
875static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
876{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800877 struct ixgbe_q_vector *q_vector;
878 int i, j, q_vectors, v_idx, r_idx;
879 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700880
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800881 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
882
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000883 /*
884 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800885 * corresponding register.
886 */
887 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +0000888 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800889 /* XXX for_each_bit(...) */
890 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700891 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800892
893 for (i = 0; i < q_vector->rxr_count; i++) {
894 j = adapter->rx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000895 ixgbe_set_ivar(adapter, 0, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800896 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700897 adapter->num_rx_queues,
898 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800899 }
900 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700901 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800902
903 for (i = 0; i < q_vector->txr_count; i++) {
904 j = adapter->tx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000905 ixgbe_set_ivar(adapter, 1, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800906 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700907 adapter->num_tx_queues,
908 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800909 }
910
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700911 /* if this is a tx only vector halve the interrupt rate */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800912 if (q_vector->txr_count && !q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700913 q_vector->eitr = (adapter->eitr_param >> 1);
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000914 else if (q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700915 /* rx only */
916 q_vector->eitr = adapter->eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800917
Alexander Duyckfe49f042009-06-04 16:00:09 +0000918 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -0700919 }
920
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000921 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
922 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
923 v_idx);
924 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
925 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800926 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -0700927
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700928 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800929 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700930 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800931 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -0700932}
933
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800934enum latency_range {
935 lowest_latency = 0,
936 low_latency = 1,
937 bulk_latency = 2,
938 latency_invalid = 255
939};
940
941/**
942 * ixgbe_update_itr - update the dynamic ITR value based on statistics
943 * @adapter: pointer to adapter
944 * @eitr: eitr setting (ints per sec) to give last timeslice
945 * @itr_setting: current throttle rate in ints/second
946 * @packets: the number of packets during this measurement interval
947 * @bytes: the number of bytes during this measurement interval
948 *
949 * Stores a new ITR value based on packets and byte
950 * counts during the last interrupt. The advantage of per interrupt
951 * computation is faster updates and more accurate ITR for the current
952 * traffic pattern. Constants in this function were computed
953 * based on theoretical maximum wire speed and thresholds were set based
954 * on testing data as well as attempting to minimize response time
955 * while increasing bulk throughput.
956 * this functionality is controlled by the InterruptThrottleRate module
957 * parameter (see ixgbe_param.c)
958 **/
959static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700960 u32 eitr, u8 itr_setting,
961 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800962{
963 unsigned int retval = itr_setting;
964 u32 timepassed_us;
965 u64 bytes_perint;
966
967 if (packets == 0)
968 goto update_itr_done;
969
970
971 /* simple throttlerate management
972 * 0-20MB/s lowest (100000 ints/s)
973 * 20-100MB/s low (20000 ints/s)
974 * 100-1249MB/s bulk (8000 ints/s)
975 */
976 /* what was last interrupt timeslice? */
977 timepassed_us = 1000000/eitr;
978 bytes_perint = bytes / timepassed_us; /* bytes/usec */
979
980 switch (itr_setting) {
981 case lowest_latency:
982 if (bytes_perint > adapter->eitr_low)
983 retval = low_latency;
984 break;
985 case low_latency:
986 if (bytes_perint > adapter->eitr_high)
987 retval = bulk_latency;
988 else if (bytes_perint <= adapter->eitr_low)
989 retval = lowest_latency;
990 break;
991 case bulk_latency:
992 if (bytes_perint <= adapter->eitr_high)
993 retval = low_latency;
994 break;
995 }
996
997update_itr_done:
998 return retval;
999}
1000
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001001/**
1002 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001003 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001004 *
1005 * This function is made to be called by ethtool and by the driver
1006 * when it needs to update EITR registers at runtime. Hardware
1007 * specific quirks/differences are taken care of here.
1008 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001009void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001010{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001011 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001012 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001013 int v_idx = q_vector->v_idx;
1014 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1015
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001016 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1017 /* must write high and low 16 bits to reset counter */
1018 itr_reg |= (itr_reg << 16);
1019 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1020 /*
1021 * set the WDIS bit to not clear the timer bits and cause an
1022 * immediate assertion of the interrupt
1023 */
1024 itr_reg |= IXGBE_EITR_CNT_WDIS;
1025 }
1026 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1027}
1028
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001029static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1030{
1031 struct ixgbe_adapter *adapter = q_vector->adapter;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001032 u32 new_itr;
1033 u8 current_itr, ret_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001034 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001035 struct ixgbe_ring *rx_ring, *tx_ring;
1036
1037 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1038 for (i = 0; i < q_vector->txr_count; i++) {
1039 tx_ring = &(adapter->tx_ring[r_idx]);
1040 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001041 q_vector->tx_itr,
1042 tx_ring->total_packets,
1043 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001044 /* if the result for this queue would decrease interrupt
1045 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001046 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001047 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001048 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001049 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001050 }
1051
1052 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1053 for (i = 0; i < q_vector->rxr_count; i++) {
1054 rx_ring = &(adapter->rx_ring[r_idx]);
1055 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001056 q_vector->rx_itr,
1057 rx_ring->total_packets,
1058 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001059 /* if the result for this queue would decrease interrupt
1060 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001061 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001062 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001063 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001064 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001065 }
1066
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001067 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001068
1069 switch (current_itr) {
1070 /* counts and packets in update_itr are dependent on these numbers */
1071 case lowest_latency:
1072 new_itr = 100000;
1073 break;
1074 case low_latency:
1075 new_itr = 20000; /* aka hwitr = ~200 */
1076 break;
1077 case bulk_latency:
1078 default:
1079 new_itr = 8000;
1080 break;
1081 }
1082
1083 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001084 /* do an exponential smoothing */
1085 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001086
1087 /* save the algorithm value here, not the smoothed one */
1088 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001089
1090 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001091 }
1092
1093 return;
1094}
1095
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001096static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1097{
1098 struct ixgbe_hw *hw = &adapter->hw;
1099
1100 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1101 (eicr & IXGBE_EICR_GPI_SDP1)) {
1102 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
1103 /* write to clear the interrupt */
1104 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1105 }
1106}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001107
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001108static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1109{
1110 struct ixgbe_hw *hw = &adapter->hw;
1111
1112 if (eicr & IXGBE_EICR_GPI_SDP1) {
1113 /* Clear the interrupt */
1114 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1115 schedule_work(&adapter->multispeed_fiber_task);
1116 } else if (eicr & IXGBE_EICR_GPI_SDP2) {
1117 /* Clear the interrupt */
1118 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1119 schedule_work(&adapter->sfp_config_module_task);
1120 } else {
1121 /* Interrupt isn't for us... */
1122 return;
1123 }
1124}
1125
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001126static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1127{
1128 struct ixgbe_hw *hw = &adapter->hw;
1129
1130 adapter->lsc_int++;
1131 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1132 adapter->link_check_timeout = jiffies;
1133 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1134 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1135 schedule_work(&adapter->watchdog_task);
1136 }
1137}
1138
Auke Kok9a799d72007-09-15 14:07:45 -07001139static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1140{
1141 struct net_device *netdev = data;
1142 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1143 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001144 u32 eicr;
1145
1146 /*
1147 * Workaround for Silicon errata. Use clear-by-write instead
1148 * of clear-by-read. Reading with EICS will return the
1149 * interrupt causes without clearing, which later be done
1150 * with the write to EICR.
1151 */
1152 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1153 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001154
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001155 if (eicr & IXGBE_EICR_LSC)
1156 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001157
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001158 if (hw->mac.type == ixgbe_mac_82598EB)
1159 ixgbe_check_fan_failure(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001160
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001161 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001162 ixgbe_check_sfp_event(adapter, eicr);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001163
1164 /* Handle Flow Director Full threshold interrupt */
1165 if (eicr & IXGBE_EICR_FLOW_DIR) {
1166 int i;
1167 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
1168 /* Disable transmits before FDIR Re-initialization */
1169 netif_tx_stop_all_queues(netdev);
1170 for (i = 0; i < adapter->num_tx_queues; i++) {
1171 struct ixgbe_ring *tx_ring =
1172 &adapter->tx_ring[i];
1173 if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE,
1174 &tx_ring->reinit_state))
1175 schedule_work(&adapter->fdir_reinit_task);
1176 }
1177 }
1178 }
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001179 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1180 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -07001181
1182 return IRQ_HANDLED;
1183}
1184
Alexander Duyckfe49f042009-06-04 16:00:09 +00001185static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1186 u64 qmask)
1187{
1188 u32 mask;
1189
1190 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1191 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1192 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1193 } else {
1194 mask = (qmask & 0xFFFFFFFF);
1195 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
1196 mask = (qmask >> 32);
1197 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
1198 }
1199 /* skip the flush */
1200}
1201
1202static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
1203 u64 qmask)
1204{
1205 u32 mask;
1206
1207 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1208 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1209 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
1210 } else {
1211 mask = (qmask & 0xFFFFFFFF);
1212 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
1213 mask = (qmask >> 32);
1214 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
1215 }
1216 /* skip the flush */
1217}
1218
Auke Kok9a799d72007-09-15 14:07:45 -07001219static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1220{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001221 struct ixgbe_q_vector *q_vector = data;
1222 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001223 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001224 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001225
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001226 if (!q_vector->txr_count)
1227 return IRQ_HANDLED;
1228
1229 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1230 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001231 tx_ring = &(adapter->tx_ring[r_idx]);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001232 tx_ring->total_bytes = 0;
1233 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001234 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001235 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001236 }
1237
Alexander Duyck91281fd2009-06-04 16:00:27 +00001238 /* disable interrupts on this vector only */
1239 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1240 napi_schedule(&q_vector->napi);
1241
Auke Kok9a799d72007-09-15 14:07:45 -07001242 return IRQ_HANDLED;
1243}
1244
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001245/**
1246 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1247 * @irq: unused
1248 * @data: pointer to our q_vector struct for this interrupt vector
1249 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001250static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1251{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001252 struct ixgbe_q_vector *q_vector = data;
1253 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001254 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001255 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001256 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001257
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001258 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001259 for (i = 0; i < q_vector->rxr_count; i++) {
1260 rx_ring = &(adapter->rx_ring[r_idx]);
1261 rx_ring->total_bytes = 0;
1262 rx_ring->total_packets = 0;
1263 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1264 r_idx + 1);
1265 }
1266
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001267 if (!q_vector->rxr_count)
1268 return IRQ_HANDLED;
1269
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001270 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001271 rx_ring = &(adapter->rx_ring[r_idx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001272 /* disable interrupts on this vector only */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001273 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
Ben Hutchings288379f2009-01-19 16:43:59 -08001274 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001275
Auke Kok9a799d72007-09-15 14:07:45 -07001276 return IRQ_HANDLED;
1277}
1278
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001279static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1280{
Alexander Duyck91281fd2009-06-04 16:00:27 +00001281 struct ixgbe_q_vector *q_vector = data;
1282 struct ixgbe_adapter *adapter = q_vector->adapter;
1283 struct ixgbe_ring *ring;
1284 int r_idx;
1285 int i;
1286
1287 if (!q_vector->txr_count && !q_vector->rxr_count)
1288 return IRQ_HANDLED;
1289
1290 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1291 for (i = 0; i < q_vector->txr_count; i++) {
1292 ring = &(adapter->tx_ring[r_idx]);
1293 ring->total_bytes = 0;
1294 ring->total_packets = 0;
1295 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1296 r_idx + 1);
1297 }
1298
1299 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1300 for (i = 0; i < q_vector->rxr_count; i++) {
1301 ring = &(adapter->rx_ring[r_idx]);
1302 ring->total_bytes = 0;
1303 ring->total_packets = 0;
1304 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1305 r_idx + 1);
1306 }
1307
1308 /* disable interrupts on this vector only */
1309 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1310 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001311
1312 return IRQ_HANDLED;
1313}
1314
1315/**
1316 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1317 * @napi: napi struct with our devices info in it
1318 * @budget: amount of work driver is allowed to do this pass, in packets
1319 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001320 * This function is optimized for cleaning one queue only on a single
1321 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001322 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001323static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1324{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001325 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001326 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001327 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001328 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001329 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001330 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001331
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001332 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001333 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001334#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001335 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001336 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001337#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001338
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001339 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001340
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001341 /* If all Rx work done, exit the polling mode */
1342 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001343 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001344 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001345 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001346 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001347 ixgbe_irq_enable_queues(adapter,
1348 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07001349 }
1350
1351 return work_done;
1352}
1353
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001354/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00001355 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001356 * @napi: napi struct with our devices info in it
1357 * @budget: amount of work driver is allowed to do this pass, in packets
1358 *
1359 * This function will clean more than one rx queue associated with a
1360 * q_vector.
1361 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00001362static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001363{
1364 struct ixgbe_q_vector *q_vector =
1365 container_of(napi, struct ixgbe_q_vector, napi);
1366 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001367 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001368 int work_done = 0, i;
1369 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001370 bool tx_clean_complete = true;
1371
1372 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1373 for (i = 0; i < q_vector->txr_count; i++) {
1374 ring = &(adapter->tx_ring[r_idx]);
1375#ifdef CONFIG_IXGBE_DCA
1376 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1377 ixgbe_update_tx_dca(adapter, ring);
1378#endif
1379 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
1380 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1381 r_idx + 1);
1382 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001383
1384 /* attempt to distribute budget to each queue fairly, but don't allow
1385 * the budget to go below 1 because we'll exit polling */
1386 budget /= (q_vector->rxr_count ?: 1);
1387 budget = max(budget, 1);
1388 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1389 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck91281fd2009-06-04 16:00:27 +00001390 ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001391#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001392 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck91281fd2009-06-04 16:00:27 +00001393 ixgbe_update_rx_dca(adapter, ring);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001394#endif
Alexander Duyck91281fd2009-06-04 16:00:27 +00001395 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001396 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1397 r_idx + 1);
1398 }
1399
1400 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck91281fd2009-06-04 16:00:27 +00001401 ring = &(adapter->rx_ring[r_idx]);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001402 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001403 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001404 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001405 if (adapter->itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001406 ixgbe_set_itr_msix(q_vector);
1407 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001408 ixgbe_irq_enable_queues(adapter,
1409 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001410 return 0;
1411 }
1412
1413 return work_done;
1414}
Alexander Duyck91281fd2009-06-04 16:00:27 +00001415
1416/**
1417 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
1418 * @napi: napi struct with our devices info in it
1419 * @budget: amount of work driver is allowed to do this pass, in packets
1420 *
1421 * This function is optimized for cleaning one queue only on a single
1422 * q_vector!!!
1423 **/
1424static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
1425{
1426 struct ixgbe_q_vector *q_vector =
1427 container_of(napi, struct ixgbe_q_vector, napi);
1428 struct ixgbe_adapter *adapter = q_vector->adapter;
1429 struct ixgbe_ring *tx_ring = NULL;
1430 int work_done = 0;
1431 long r_idx;
1432
1433 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1434 tx_ring = &(adapter->tx_ring[r_idx]);
1435#ifdef CONFIG_IXGBE_DCA
1436 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1437 ixgbe_update_tx_dca(adapter, tx_ring);
1438#endif
1439
1440 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
1441 work_done = budget;
1442
1443 /* If all Rx work done, exit the polling mode */
1444 if (work_done < budget) {
1445 napi_complete(napi);
1446 if (adapter->itr_setting & 1)
1447 ixgbe_set_itr_msix(q_vector);
1448 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1449 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
1450 }
1451
1452 return work_done;
1453}
1454
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001455static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001456 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001457{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001458 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1459
1460 set_bit(r_idx, q_vector->rxr_idx);
1461 q_vector->rxr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001462}
Auke Kok9a799d72007-09-15 14:07:45 -07001463
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001464static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001465 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001466{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001467 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1468
1469 set_bit(t_idx, q_vector->txr_idx);
1470 q_vector->txr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001471}
Auke Kok9a799d72007-09-15 14:07:45 -07001472
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001473/**
1474 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1475 * @adapter: board private structure to initialize
1476 * @vectors: allotted vector count for descriptor rings
1477 *
1478 * This function maps descriptor rings to the queue-specific vectors
1479 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1480 * one vector per ring/queue, but on a constrained vector budget, we
1481 * group the rings as "efficiently" as possible. You would add new
1482 * mapping configurations in here.
1483 **/
1484static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001485 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001486{
1487 int v_start = 0;
1488 int rxr_idx = 0, txr_idx = 0;
1489 int rxr_remaining = adapter->num_rx_queues;
1490 int txr_remaining = adapter->num_tx_queues;
1491 int i, j;
1492 int rqpv, tqpv;
1493 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001494
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001495 /* No mapping required if MSI-X is disabled. */
1496 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001497 goto out;
1498
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001499 /*
1500 * The ideal configuration...
1501 * We have enough vectors to map one per queue.
1502 */
1503 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1504 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1505 map_vector_to_rxq(adapter, v_start, rxr_idx);
1506
1507 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1508 map_vector_to_txq(adapter, v_start, txr_idx);
1509
1510 goto out;
1511 }
1512
1513 /*
1514 * If we don't have enough vectors for a 1-to-1
1515 * mapping, we'll have to group them so there are
1516 * multiple queues per vector.
1517 */
1518 /* Re-adjusting *qpv takes care of the remainder. */
1519 for (i = v_start; i < vectors; i++) {
1520 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1521 for (j = 0; j < rqpv; j++) {
1522 map_vector_to_rxq(adapter, i, rxr_idx);
1523 rxr_idx++;
1524 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001525 }
Auke Kok9a799d72007-09-15 14:07:45 -07001526 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001527 for (i = v_start; i < vectors; i++) {
1528 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1529 for (j = 0; j < tqpv; j++) {
1530 map_vector_to_txq(adapter, i, txr_idx);
1531 txr_idx++;
1532 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001533 }
Auke Kok9a799d72007-09-15 14:07:45 -07001534 }
1535
Auke Kok9a799d72007-09-15 14:07:45 -07001536out:
Auke Kok9a799d72007-09-15 14:07:45 -07001537 return err;
1538}
1539
1540/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001541 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1542 * @adapter: board private structure
1543 *
1544 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1545 * interrupts from the kernel.
1546 **/
1547static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1548{
1549 struct net_device *netdev = adapter->netdev;
1550 irqreturn_t (*handler)(int, void *);
1551 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001552 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001553
1554 /* Decrement for Other and TCP Timer vectors */
1555 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1556
1557 /* Map the Tx/Rx rings to the vectors we were allotted. */
1558 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1559 if (err)
1560 goto out;
1561
1562#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001563 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1564 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001565 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001566 handler = SET_HANDLER(adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001567
1568 if(handler == &ixgbe_msix_clean_rx) {
1569 sprintf(adapter->name[vector], "%s-%s-%d",
1570 netdev->name, "rx", ri++);
1571 }
1572 else if(handler == &ixgbe_msix_clean_tx) {
1573 sprintf(adapter->name[vector], "%s-%s-%d",
1574 netdev->name, "tx", ti++);
1575 }
1576 else
1577 sprintf(adapter->name[vector], "%s-%s-%d",
1578 netdev->name, "TxRx", vector);
1579
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001580 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001581 handler, 0, adapter->name[vector],
Alexander Duyck7a921c92009-05-06 10:43:28 +00001582 adapter->q_vector[vector]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001583 if (err) {
1584 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001585 "request_irq failed for MSIX interrupt "
1586 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001587 goto free_queue_irqs;
1588 }
1589 }
1590
1591 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1592 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001593 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001594 if (err) {
1595 DPRINTK(PROBE, ERR,
1596 "request_irq for msix_lsc failed: %d\n", err);
1597 goto free_queue_irqs;
1598 }
1599
1600 return 0;
1601
1602free_queue_irqs:
1603 for (i = vector - 1; i >= 0; i--)
1604 free_irq(adapter->msix_entries[--vector].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001605 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001606 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1607 pci_disable_msix(adapter->pdev);
1608 kfree(adapter->msix_entries);
1609 adapter->msix_entries = NULL;
1610out:
1611 return err;
1612}
1613
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001614static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1615{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001616 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001617 u8 current_itr;
1618 u32 new_itr = q_vector->eitr;
1619 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1620 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1621
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001622 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001623 q_vector->tx_itr,
1624 tx_ring->total_packets,
1625 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001626 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001627 q_vector->rx_itr,
1628 rx_ring->total_packets,
1629 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001630
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001631 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001632
1633 switch (current_itr) {
1634 /* counts and packets in update_itr are dependent on these numbers */
1635 case lowest_latency:
1636 new_itr = 100000;
1637 break;
1638 case low_latency:
1639 new_itr = 20000; /* aka hwitr = ~200 */
1640 break;
1641 case bulk_latency:
1642 new_itr = 8000;
1643 break;
1644 default:
1645 break;
1646 }
1647
1648 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001649 /* do an exponential smoothing */
1650 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001651
1652 /* save the algorithm value here, not the smoothed one */
1653 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001654
1655 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001656 }
1657
1658 return;
1659}
1660
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001661/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001662 * ixgbe_irq_enable - Enable default interrupt generation settings
1663 * @adapter: board private structure
1664 **/
1665static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1666{
1667 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00001668
1669 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
David S. Miller6ab33d52008-11-20 16:44:00 -08001670 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1671 mask |= IXGBE_EIMS_GPI_SDP1;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001672 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001673 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001674 mask |= IXGBE_EIMS_GPI_SDP1;
1675 mask |= IXGBE_EIMS_GPI_SDP2;
1676 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001677 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
1678 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
1679 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001680
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001681 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Nelson, Shannon835462f2009-04-27 22:42:54 +00001682 ixgbe_irq_enable_queues(adapter, ~0);
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001683 IXGBE_WRITE_FLUSH(&adapter->hw);
1684}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001685
1686/**
1687 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001688 * @irq: interrupt number
1689 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001690 **/
1691static irqreturn_t ixgbe_intr(int irq, void *data)
1692{
1693 struct net_device *netdev = data;
1694 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1695 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001696 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07001697 u32 eicr;
1698
Don Skidmore54037502009-02-21 15:42:56 -08001699 /*
1700 * Workaround for silicon errata. Mask the interrupts
1701 * before the read of EICR.
1702 */
1703 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1704
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001705 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1706 * therefore no explict interrupt disable is necessary */
1707 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001708 if (!eicr) {
1709 /* shared interrupt alert!
1710 * make sure interrupts are enabled because the read will
1711 * have disabled interrupts due to EIAM */
1712 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001713 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001714 }
Auke Kok9a799d72007-09-15 14:07:45 -07001715
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001716 if (eicr & IXGBE_EICR_LSC)
1717 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001718
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001719 if (hw->mac.type == ixgbe_mac_82599EB)
1720 ixgbe_check_sfp_event(adapter, eicr);
1721
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001722 ixgbe_check_fan_failure(adapter, eicr);
1723
Alexander Duyck7a921c92009-05-06 10:43:28 +00001724 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001725 adapter->tx_ring[0].total_packets = 0;
1726 adapter->tx_ring[0].total_bytes = 0;
1727 adapter->rx_ring[0].total_packets = 0;
1728 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001729 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00001730 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07001731 }
1732
1733 return IRQ_HANDLED;
1734}
1735
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001736static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1737{
1738 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1739
1740 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001741 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001742 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1743 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1744 q_vector->rxr_count = 0;
1745 q_vector->txr_count = 0;
1746 }
1747}
1748
Auke Kok9a799d72007-09-15 14:07:45 -07001749/**
1750 * ixgbe_request_irq - initialize interrupts
1751 * @adapter: board private structure
1752 *
1753 * Attempts to configure interrupts using the best available
1754 * capabilities of the hardware and kernel.
1755 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001756static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001757{
1758 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001759 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001760
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001761 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1762 err = ixgbe_request_msix_irqs(adapter);
1763 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1764 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001765 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001766 } else {
1767 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001768 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001769 }
1770
Auke Kok9a799d72007-09-15 14:07:45 -07001771 if (err)
1772 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1773
Auke Kok9a799d72007-09-15 14:07:45 -07001774 return err;
1775}
1776
1777static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1778{
1779 struct net_device *netdev = adapter->netdev;
1780
1781 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001782 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001783
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001784 q_vectors = adapter->num_msix_vectors;
1785
1786 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001787 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001788
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001789 i--;
1790 for (; i >= 0; i--) {
1791 free_irq(adapter->msix_entries[i].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001792 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001793 }
1794
1795 ixgbe_reset_q_vectors(adapter);
1796 } else {
1797 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001798 }
1799}
1800
1801/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001802 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1803 * @adapter: board private structure
1804 **/
1805static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1806{
Nelson, Shannon835462f2009-04-27 22:42:54 +00001807 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1808 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1809 } else {
1810 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
1811 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001812 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001813 }
1814 IXGBE_WRITE_FLUSH(&adapter->hw);
1815 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1816 int i;
1817 for (i = 0; i < adapter->num_msix_vectors; i++)
1818 synchronize_irq(adapter->msix_entries[i].vector);
1819 } else {
1820 synchronize_irq(adapter->pdev->irq);
1821 }
1822}
1823
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001824/**
Auke Kok9a799d72007-09-15 14:07:45 -07001825 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1826 *
1827 **/
1828static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1829{
Auke Kok9a799d72007-09-15 14:07:45 -07001830 struct ixgbe_hw *hw = &adapter->hw;
1831
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001832 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001833 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001834
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001835 ixgbe_set_ivar(adapter, 0, 0, 0);
1836 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001837
1838 map_vector_to_rxq(adapter, 0, 0);
1839 map_vector_to_txq(adapter, 0, 0);
1840
1841 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001842}
1843
1844/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001845 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001846 * @adapter: board private structure
1847 *
1848 * Configure the Tx unit of the MAC after a reset.
1849 **/
1850static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1851{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001852 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001853 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001854 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001855
1856 /* Setup the HW Tx Head and Tail descriptor pointers */
1857 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001858 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1859 j = ring->reg_idx;
1860 tdba = ring->dma;
1861 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001862 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Yang Hongyang284901a2009-04-06 19:01:15 -07001863 (tdba & DMA_BIT_MASK(32)));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001864 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1865 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1866 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1867 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1868 adapter->tx_ring[i].head = IXGBE_TDH(j);
1869 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1870 /* Disable Tx Head Writeback RO bit, since this hoses
1871 * bookkeeping if things aren't delivered in order.
1872 */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001873 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001874 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001875 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001876 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001877 if (hw->mac.type == ixgbe_mac_82599EB) {
1878 /* We enable 8 traffic classes, DCB only */
1879 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1880 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1881 IXGBE_MTQC_8TC_8TQ));
1882 }
Auke Kok9a799d72007-09-15 14:07:45 -07001883}
1884
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001885#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07001886
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001887static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1888{
1889 struct ixgbe_ring *rx_ring;
1890 u32 srrctl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001891 int queue0 = 0;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001892 unsigned long mask;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001893 struct ixgbe_ring_feature *feature = adapter->ring_feature;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001894
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001895 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Alexander Duyck163de422009-05-07 10:39:16 +00001896 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001897 int dcb_i = feature[RING_F_DCB].indices;
Alexander Duyck163de422009-05-07 10:39:16 +00001898 if (dcb_i == 8)
1899 queue0 = index >> 4;
1900 else if (dcb_i == 4)
1901 queue0 = index >> 5;
1902 else
1903 dev_err(&adapter->pdev->dev, "Invalid DCB "
1904 "configuration\n");
Yi Zou0331a832009-05-17 12:33:52 +00001905#ifdef IXGBE_FCOE
1906 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1907 struct ixgbe_ring_feature *f;
1908
1909 rx_ring = &adapter->rx_ring[queue0];
1910 f = &adapter->ring_feature[RING_F_FCOE];
1911 if ((queue0 == 0) && (index > rx_ring->reg_idx))
1912 queue0 = f->mask + index -
1913 rx_ring->reg_idx - 1;
1914 }
1915#endif /* IXGBE_FCOE */
Alexander Duyck163de422009-05-07 10:39:16 +00001916 } else {
1917 queue0 = index;
1918 }
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001919 } else {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001920 mask = (unsigned long) feature[RING_F_RSS].mask;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001921 queue0 = index & mask;
1922 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001923 }
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001924
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001925 rx_ring = &adapter->rx_ring[queue0];
1926
1927 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1928
1929 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1930 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1931
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001932 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1933 IXGBE_SRRCTL_BSIZEHDR_MASK;
1934
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001935 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001936#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
1937 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1938#else
1939 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1940#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001941 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001942 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001943 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
1944 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001945 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001946 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001947
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001948 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1949}
1950
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001951static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
1952{
1953 u32 mrqc = 0;
1954 int mask;
1955
1956 if (!(adapter->hw.mac.type == ixgbe_mac_82599EB))
1957 return mrqc;
1958
1959 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
1960#ifdef CONFIG_IXGBE_DCB
1961 | IXGBE_FLAG_DCB_ENABLED
1962#endif
1963 );
1964
1965 switch (mask) {
1966 case (IXGBE_FLAG_RSS_ENABLED):
1967 mrqc = IXGBE_MRQC_RSSEN;
1968 break;
1969#ifdef CONFIG_IXGBE_DCB
1970 case (IXGBE_FLAG_DCB_ENABLED):
1971 mrqc = IXGBE_MRQC_RT8TCEN;
1972 break;
1973#endif /* CONFIG_IXGBE_DCB */
1974 default:
1975 break;
1976 }
1977
1978 return mrqc;
1979}
1980
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001981/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001982 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001983 * @adapter: board private structure
1984 *
1985 * Configure the Rx unit of the MAC after a reset.
1986 **/
1987static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1988{
1989 u64 rdba;
1990 struct ixgbe_hw *hw = &adapter->hw;
1991 struct net_device *netdev = adapter->netdev;
1992 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001993 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001994 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001995 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1996 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1997 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001998 u32 fctrl, hlreg0;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001999 u32 reta = 0, mrqc = 0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002000 u32 rdrxctl;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002001 u32 rscctrl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002002 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07002003
2004 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002005 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07002006
Yi Zoueacd73f2009-05-13 13:11:06 +00002007#ifdef IXGBE_FCOE
2008 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2009 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
2010#endif /* IXGBE_FCOE */
2011
Auke Kok9a799d72007-09-15 14:07:45 -07002012 /* Set the RX buffer length according to the mode */
2013 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002014 rx_buf_len = IXGBE_RX_HDR_SIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002015 if (hw->mac.type == ixgbe_mac_82599EB) {
2016 /* PSRTYPE must be initialized in 82599 */
2017 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
2018 IXGBE_PSRTYPE_UDPHDR |
2019 IXGBE_PSRTYPE_IPV4HDR |
Yi Zoudfa12f02009-05-07 10:39:35 +00002020 IXGBE_PSRTYPE_IPV6HDR |
2021 IXGBE_PSRTYPE_L2HDR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002022 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
2023 }
Auke Kok9a799d72007-09-15 14:07:45 -07002024 } else {
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00002025 if (!(adapter->flags & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00002026 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002027 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07002028 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002029 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07002030 }
2031
2032 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
2033 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002034 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002035 fctrl |= IXGBE_FCTRL_PMCF;
Auke Kok9a799d72007-09-15 14:07:45 -07002036 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
2037
2038 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2039 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2040 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
2041 else
2042 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Yi Zou63f39bd2009-05-17 12:34:35 +00002043#ifdef IXGBE_FCOE
2044 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2045 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2046#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002047 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2048
Auke Kok9a799d72007-09-15 14:07:45 -07002049 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
2050 /* disable receives while setting up the descriptors */
2051 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2052 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
2053
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002054 /*
2055 * Setup the HW Rx Head and Tail Descriptor Pointers and
2056 * the Base and Length of the Rx Descriptor Ring
2057 */
Auke Kok9a799d72007-09-15 14:07:45 -07002058 for (i = 0; i < adapter->num_rx_queues; i++) {
2059 rdba = adapter->rx_ring[i].dma;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002060 j = adapter->rx_ring[i].reg_idx;
Yang Hongyang284901a2009-04-06 19:01:15 -07002061 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32)));
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002062 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
2063 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
2064 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
2065 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
2066 adapter->rx_ring[i].head = IXGBE_RDH(j);
2067 adapter->rx_ring[i].tail = IXGBE_RDT(j);
2068 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002069
Yi Zou63f39bd2009-05-17 12:34:35 +00002070#ifdef IXGBE_FCOE
2071 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
2072 struct ixgbe_ring_feature *f;
2073 f = &adapter->ring_feature[RING_F_FCOE];
2074 if ((rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
2075 (i >= f->mask) && (i < f->mask + f->indices))
2076 adapter->rx_ring[i].rx_buf_len =
2077 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2078 }
2079
2080#endif /* IXGBE_FCOE */
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002081 ixgbe_configure_srrctl(adapter, j);
Auke Kok9a799d72007-09-15 14:07:45 -07002082 }
2083
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002084 if (hw->mac.type == ixgbe_mac_82598EB) {
2085 /*
2086 * For VMDq support of different descriptor types or
2087 * buffer sizes through the use of multiple SRRCTL
2088 * registers, RDRXCTL.MVMEN must be set to 1
2089 *
2090 * also, the manual doesn't mention it clearly but DCA hints
2091 * will only use queue 0's tags unless this bit is set. Side
2092 * effects of setting this bit are only that SRRCTL must be
2093 * fully programmed [0..15]
2094 */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002095 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2096 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
2097 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
Alexander Duyck2f90b862008-11-20 20:52:10 -08002098 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002099
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002100 /* Program MRQC for the distribution of queues */
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002101 mrqc = ixgbe_setup_mrqc(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002102
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002103 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07002104 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002105 for (i = 0, j = 0; i < 128; i++, j++) {
2106 if (j == adapter->ring_feature[RING_F_RSS].indices)
2107 j = 0;
2108 /* reta = 4-byte sliding window of
2109 * 0x00..(indices-1)(indices-1)00..etc. */
2110 reta = (reta << 8) | (j * 0x11);
2111 if ((i & 3) == 3)
2112 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07002113 }
2114
2115 /* Fill out hash function seeds */
2116 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002117 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002118
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002119 if (hw->mac.type == ixgbe_mac_82598EB)
2120 mrqc |= IXGBE_MRQC_RSSEN;
Auke Kok9a799d72007-09-15 14:07:45 -07002121 /* Perform hash on these packet types */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002122 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2123 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2124 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
2125 | IXGBE_MRQC_RSS_FIELD_IPV6
2126 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
2127 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07002128 }
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002129 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002130
2131 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2132
2133 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
2134 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
2135 /* Disable indicating checksum in descriptor, enables
2136 * RSS hash */
2137 rxcsum |= IXGBE_RXCSUM_PCSD;
2138 }
2139 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
2140 /* Enable IPv4 payload checksum for UDP fragments
2141 * if PCSD is not set */
2142 rxcsum |= IXGBE_RXCSUM_IPPCSE;
2143 }
2144
2145 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002146
2147 if (hw->mac.type == ixgbe_mac_82599EB) {
2148 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2149 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002150 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002151 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
2152 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002153
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00002154 if (adapter->flags & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002155 /* Enable 82599 HW-RSC */
2156 for (i = 0; i < adapter->num_rx_queues; i++) {
2157 j = adapter->rx_ring[i].reg_idx;
2158 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j));
2159 rscctrl |= IXGBE_RSCCTL_RSCEN;
2160 /*
Alexander Duycke76678d2009-05-17 20:57:47 +00002161 * we must limit the number of descriptors so that the
2162 * total size of max desc * buf_len is not greater
2163 * than 65535
Alexander Duyckf8212f92009-04-27 22:42:37 +00002164 */
Alexander Duycke76678d2009-05-17 20:57:47 +00002165 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
2166#if (MAX_SKB_FRAGS > 16)
2167 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2168#elif (MAX_SKB_FRAGS > 8)
Alexander Duyckf8212f92009-04-27 22:42:37 +00002169 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Alexander Duycke76678d2009-05-17 20:57:47 +00002170#elif (MAX_SKB_FRAGS > 4)
2171 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002172#else
Alexander Duycke76678d2009-05-17 20:57:47 +00002173 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002174#endif
Alexander Duycke76678d2009-05-17 20:57:47 +00002175 } else {
2176 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2177 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2178 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2179 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2180 else
2181 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2182 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002183 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl);
2184 }
2185 /* Disable RSC for ACK packets */
2186 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
2187 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
2188 }
Auke Kok9a799d72007-09-15 14:07:45 -07002189}
2190
Auke Kok9a799d72007-09-15 14:07:45 -07002191static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2192{
2193 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002194 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002195
2196 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002197 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002198}
2199
2200static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2201{
2202 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002203 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002204
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002205 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2206 ixgbe_irq_disable(adapter);
2207
Auke Kok9a799d72007-09-15 14:07:45 -07002208 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002209
2210 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2211 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002212
2213 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002214 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07002215}
2216
Don Skidmore068c89b2009-01-19 16:54:36 -08002217static void ixgbe_vlan_rx_register(struct net_device *netdev,
2218 struct vlan_group *grp)
2219{
2220 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2221 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002222 int i, j;
Don Skidmore068c89b2009-01-19 16:54:36 -08002223
2224 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2225 ixgbe_irq_disable(adapter);
2226 adapter->vlgrp = grp;
2227
2228 /*
2229 * For a DCB driver, always enable VLAN tag stripping so we can
2230 * still receive traffic from a DCB-enabled host even if we're
2231 * not in DCB mode.
2232 */
2233 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002234 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
2235 ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
Don Skidmore068c89b2009-01-19 16:54:36 -08002236 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2237 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002238 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
2239 ctrl |= IXGBE_VLNCTRL_VFE;
2240 /* enable VLAN tag insert/strip */
2241 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
2242 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2243 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
2244 for (i = 0; i < adapter->num_rx_queues; i++) {
2245 j = adapter->rx_ring[i].reg_idx;
2246 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
2247 ctrl |= IXGBE_RXDCTL_VME;
2248 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
2249 }
Don Skidmore068c89b2009-01-19 16:54:36 -08002250 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002251 ixgbe_vlan_rx_add_vid(netdev, 0);
Don Skidmore068c89b2009-01-19 16:54:36 -08002252
2253 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2254 ixgbe_irq_enable(adapter);
2255}
2256
Auke Kok9a799d72007-09-15 14:07:45 -07002257static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
2258{
2259 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2260
2261 if (adapter->vlgrp) {
2262 u16 vid;
2263 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2264 if (!vlan_group_get_device(adapter->vlgrp, vid))
2265 continue;
2266 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
2267 }
2268 }
2269}
2270
Christopher Leech2c5645c2008-08-26 04:27:02 -07002271static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
2272{
2273 struct dev_mc_list *mc_ptr;
2274 u8 *addr = *mc_addr_ptr;
2275 *vmdq = 0;
2276
2277 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
2278 if (mc_ptr->next)
2279 *mc_addr_ptr = mc_ptr->next->dmi_addr;
2280 else
2281 *mc_addr_ptr = NULL;
2282
2283 return addr;
2284}
2285
Auke Kok9a799d72007-09-15 14:07:45 -07002286/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07002287 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07002288 * @netdev: network interface device structure
2289 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07002290 * The set_rx_method entry point is called whenever the unicast/multicast
2291 * address list or the network interface flags are updated. This routine is
2292 * responsible for configuring the hardware for proper unicast, multicast and
2293 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07002294 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07002295static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07002296{
2297 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2298 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07002299 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002300 u8 *addr_list = NULL;
2301 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002302
2303 /* Check for Promiscuous and All Multicast modes */
2304
2305 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07002306 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07002307
2308 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07002309 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002310 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07002311 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07002312 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002313 if (netdev->flags & IFF_ALLMULTI) {
2314 fctrl |= IXGBE_FCTRL_MPE;
2315 fctrl &= ~IXGBE_FCTRL_UPE;
2316 } else {
2317 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2318 }
Alexander Duyck3d016252008-08-26 18:30:04 -07002319 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002320 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002321 }
2322
2323 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07002324 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07002325
Christopher Leech2c5645c2008-08-26 04:27:02 -07002326 /* reprogram secondary unicast list */
Jiri Pirko31278e72009-06-17 01:12:19 +00002327 hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list);
Auke Kok9a799d72007-09-15 14:07:45 -07002328
Christopher Leech2c5645c2008-08-26 04:27:02 -07002329 /* reprogram multicast list */
2330 addr_count = netdev->mc_count;
2331 if (addr_count)
2332 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002333 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2334 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002335}
2336
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002337static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2338{
2339 int q_idx;
2340 struct ixgbe_q_vector *q_vector;
2341 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2342
2343 /* legacy and MSI only use one vector */
2344 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2345 q_vectors = 1;
2346
2347 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002348 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002349 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002350 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002351 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2352 if (!q_vector->rxr_count || !q_vector->txr_count) {
2353 if (q_vector->txr_count == 1)
2354 napi->poll = &ixgbe_clean_txonly;
2355 else if (q_vector->rxr_count == 1)
2356 napi->poll = &ixgbe_clean_rxonly;
2357 }
2358 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002359
2360 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002361 }
2362}
2363
2364static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2365{
2366 int q_idx;
2367 struct ixgbe_q_vector *q_vector;
2368 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2369
2370 /* legacy and MSI only use one vector */
2371 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2372 q_vectors = 1;
2373
2374 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002375 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002376 napi_disable(&q_vector->napi);
2377 }
2378}
2379
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002380#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002381/*
2382 * ixgbe_configure_dcb - Configure DCB hardware
2383 * @adapter: ixgbe adapter struct
2384 *
2385 * This is called by the driver on open to configure the DCB hardware.
2386 * This is also called by the gennetlink interface when reconfiguring
2387 * the DCB state.
2388 */
2389static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2390{
2391 struct ixgbe_hw *hw = &adapter->hw;
2392 u32 txdctl, vlnctrl;
2393 int i, j;
2394
2395 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2396 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2397 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2398
2399 /* reconfigure the hardware */
2400 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2401
2402 for (i = 0; i < adapter->num_tx_queues; i++) {
2403 j = adapter->tx_ring[i].reg_idx;
2404 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2405 /* PThresh workaround for Tx hang with DFP enabled. */
2406 txdctl |= 32;
2407 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2408 }
2409 /* Enable VLAN tag insert/strip */
2410 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002411 if (hw->mac.type == ixgbe_mac_82598EB) {
2412 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2413 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2414 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2415 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2416 vlnctrl |= IXGBE_VLNCTRL_VFE;
2417 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2418 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2419 for (i = 0; i < adapter->num_rx_queues; i++) {
2420 j = adapter->rx_ring[i].reg_idx;
2421 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2422 vlnctrl |= IXGBE_RXDCTL_VME;
2423 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2424 }
2425 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08002426 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2427}
2428
2429#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002430static void ixgbe_configure(struct ixgbe_adapter *adapter)
2431{
2432 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002433 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002434 int i;
2435
Christopher Leech2c5645c2008-08-26 04:27:02 -07002436 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002437
2438 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002439#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002440 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2441 netif_set_gso_max_size(netdev, 32768);
2442 ixgbe_configure_dcb(adapter);
2443 } else {
2444 netif_set_gso_max_size(netdev, 65536);
2445 }
2446#else
2447 netif_set_gso_max_size(netdev, 65536);
2448#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002449
Yi Zoueacd73f2009-05-13 13:11:06 +00002450#ifdef IXGBE_FCOE
2451 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2452 ixgbe_configure_fcoe(adapter);
2453
2454#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002455 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2456 for (i = 0; i < adapter->num_tx_queues; i++)
2457 adapter->tx_ring[i].atr_sample_rate =
2458 adapter->atr_sample_rate;
2459 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
2460 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
2461 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
2462 }
2463
Auke Kok9a799d72007-09-15 14:07:45 -07002464 ixgbe_configure_tx(adapter);
2465 ixgbe_configure_rx(adapter);
2466 for (i = 0; i < adapter->num_rx_queues; i++)
2467 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002468 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07002469}
2470
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002471static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2472{
2473 switch (hw->phy.type) {
2474 case ixgbe_phy_sfp_avago:
2475 case ixgbe_phy_sfp_ftl:
2476 case ixgbe_phy_sfp_intel:
2477 case ixgbe_phy_sfp_unknown:
2478 case ixgbe_phy_tw_tyco:
2479 case ixgbe_phy_tw_unknown:
2480 return true;
2481 default:
2482 return false;
2483 }
2484}
2485
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002486/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002487 * ixgbe_sfp_link_config - set up SFP+ link
2488 * @adapter: pointer to private adapter struct
2489 **/
2490static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2491{
2492 struct ixgbe_hw *hw = &adapter->hw;
2493
2494 if (hw->phy.multispeed_fiber) {
2495 /*
2496 * In multispeed fiber setups, the device may not have
2497 * had a physical connection when the driver loaded.
2498 * If that's the case, the initial link configuration
2499 * couldn't get the MAC into 10G or 1G mode, so we'll
2500 * never have a link status change interrupt fire.
2501 * We need to try and force an autonegotiation
2502 * session, then bring up link.
2503 */
2504 hw->mac.ops.setup_sfp(hw);
2505 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2506 schedule_work(&adapter->multispeed_fiber_task);
2507 } else {
2508 /*
2509 * Direct Attach Cu and non-multispeed fiber modules
2510 * still need to be configured properly prior to
2511 * attempting link.
2512 */
2513 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2514 schedule_work(&adapter->sfp_config_module_task);
2515 }
2516}
2517
2518/**
2519 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002520 * @hw: pointer to private hardware struct
2521 *
2522 * Returns 0 on success, negative on failure
2523 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002524static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002525{
2526 u32 autoneg;
2527 bool link_up = false;
2528 u32 ret = IXGBE_ERR_LINK_SETUP;
2529
2530 if (hw->mac.ops.check_link)
2531 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2532
2533 if (ret)
2534 goto link_cfg_out;
2535
2536 if (hw->mac.ops.get_link_capabilities)
2537 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
2538 &hw->mac.autoneg);
2539 if (ret)
2540 goto link_cfg_out;
2541
2542 if (hw->mac.ops.setup_link_speed)
2543 ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002544link_cfg_out:
2545 return ret;
2546}
2547
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002548#define IXGBE_MAX_RX_DESC_POLL 10
2549static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2550 int rxr)
2551{
2552 int j = adapter->rx_ring[rxr].reg_idx;
2553 int k;
2554
2555 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2556 if (IXGBE_READ_REG(&adapter->hw,
2557 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2558 break;
2559 else
2560 msleep(1);
2561 }
2562 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2563 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2564 "not set within the polling period\n", rxr);
2565 }
2566 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2567 (adapter->rx_ring[rxr].count - 1));
2568}
2569
Auke Kok9a799d72007-09-15 14:07:45 -07002570static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2571{
2572 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07002573 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002574 int i, j = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002575 int num_rx_rings = adapter->num_rx_queues;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002576 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002577 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002578 u32 txdctl, rxdctl, mhadd;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002579 u32 dmatxctl;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002580 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002581
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002582 ixgbe_get_hw_control(adapter);
2583
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002584 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2585 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002586 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2587 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002588 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002589 } else {
2590 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002591 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002592 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002593 /* XXX: to interrupt immediately for EICS writes, enable this */
2594 /* gpie |= IXGBE_GPIE_EIMEN; */
2595 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2596 }
2597
2598 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2599 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2600 * specifically only auto mask tx and rx interrupts */
2601 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002602 }
2603
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002604 /* Enable fan failure interrupt if media type is copper */
2605 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2606 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2607 gpie |= IXGBE_SDP1_GPIEN;
2608 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2609 }
2610
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002611 if (hw->mac.type == ixgbe_mac_82599EB) {
2612 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2613 gpie |= IXGBE_SDP1_GPIEN;
2614 gpie |= IXGBE_SDP2_GPIEN;
2615 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2616 }
2617
Yi Zou63f39bd2009-05-17 12:34:35 +00002618#ifdef IXGBE_FCOE
2619 /* adjust max frame to be able to do baby jumbo for FCoE */
2620 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
2621 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
2622 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
2623
2624#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07002625 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002626 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2627 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2628 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2629
2630 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2631 }
2632
2633 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002634 j = adapter->tx_ring[i].reg_idx;
2635 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002636 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2637 txdctl |= (8 << 16);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002638 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2639 }
2640
2641 if (hw->mac.type == ixgbe_mac_82599EB) {
2642 /* DMATXCTL.EN must be set after all Tx queue config is done */
2643 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2644 dmatxctl |= IXGBE_DMATXCTL_TE;
2645 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2646 }
2647 for (i = 0; i < adapter->num_tx_queues; i++) {
2648 j = adapter->tx_ring[i].reg_idx;
2649 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Auke Kok9a799d72007-09-15 14:07:45 -07002650 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002651 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002652 }
2653
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002654 for (i = 0; i < num_rx_rings; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002655 j = adapter->rx_ring[i].reg_idx;
2656 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2657 /* enable PTHRESH=32 descriptors (half the internal cache)
2658 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2659 * this also removes a pesky rx_no_buffer_count increment */
2660 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002661 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002662 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002663 if (hw->mac.type == ixgbe_mac_82599EB)
2664 ixgbe_rx_desc_queue_enable(adapter, i);
Auke Kok9a799d72007-09-15 14:07:45 -07002665 }
2666 /* enable all receives */
2667 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002668 if (hw->mac.type == ixgbe_mac_82598EB)
2669 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2670 else
2671 rxdctl |= IXGBE_RXCTRL_RXEN;
2672 hw->mac.ops.enable_rx_dma(hw, rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002673
2674 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2675 ixgbe_configure_msix(adapter);
2676 else
2677 ixgbe_configure_msi_and_legacy(adapter);
2678
2679 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002680 ixgbe_napi_enable_all(adapter);
2681
2682 /* clear any pending interrupts, may auto mask */
2683 IXGBE_READ_REG(hw, IXGBE_EICR);
2684
Auke Kok9a799d72007-09-15 14:07:45 -07002685 ixgbe_irq_enable(adapter);
2686
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002687 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00002688 * If this adapter has a fan, check to see if we had a failure
2689 * before we enabled the interrupt.
2690 */
2691 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2692 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2693 if (esdp & IXGBE_ESDP_SDP1)
2694 DPRINTK(DRV, CRIT,
2695 "Fan has stopped, replace the adapter\n");
2696 }
2697
2698 /*
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002699 * For hot-pluggable SFP+ devices, a new SFP+ module may have
Don Skidmore19343de2009-07-02 12:50:31 +00002700 * arrived before interrupts were enabled but after probe. Such
2701 * devices wouldn't have their type identified yet. We need to
2702 * kick off the SFP+ module setup first, then try to bring up link.
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002703 * If we're not hot-pluggable SFP+, we just need to configure link
2704 * and bring it up.
2705 */
Don Skidmore19343de2009-07-02 12:50:31 +00002706 if (hw->phy.type == ixgbe_phy_unknown) {
2707 err = hw->phy.ops.identify(hw);
2708 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2709 dev_err(&adapter->pdev->dev, "failed to initialize "
2710 "because an unsupported SFP+ module type "
2711 "was detected.\n"
2712 "Reload the driver after installing a "
2713 "supported module.\n");
2714 ixgbe_down(adapter);
2715 return err;
2716 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002717 }
2718
2719 if (ixgbe_is_sfp(hw)) {
2720 ixgbe_sfp_link_config(adapter);
2721 } else {
2722 err = ixgbe_non_sfp_link_config(hw);
2723 if (err)
2724 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2725 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002726
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002727 for (i = 0; i < adapter->num_tx_queues; i++)
2728 set_bit(__IXGBE_FDIR_INIT_DONE,
2729 &(adapter->tx_ring[i].reinit_state));
2730
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002731 /* enable transmits */
2732 netif_tx_start_all_queues(netdev);
2733
Auke Kok9a799d72007-09-15 14:07:45 -07002734 /* bring the link up in the watchdog, this could race with our first
2735 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002736 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2737 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002738 mod_timer(&adapter->watchdog_timer, jiffies);
2739 return 0;
2740}
2741
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002742void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2743{
2744 WARN_ON(in_interrupt());
2745 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2746 msleep(1);
2747 ixgbe_down(adapter);
2748 ixgbe_up(adapter);
2749 clear_bit(__IXGBE_RESETTING, &adapter->state);
2750}
2751
Auke Kok9a799d72007-09-15 14:07:45 -07002752int ixgbe_up(struct ixgbe_adapter *adapter)
2753{
2754 /* hardware has been reset, we need to reload some things */
2755 ixgbe_configure(adapter);
2756
2757 return ixgbe_up_complete(adapter);
2758}
2759
2760void ixgbe_reset(struct ixgbe_adapter *adapter)
2761{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002762 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07002763 int err;
2764
2765 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002766 switch (err) {
2767 case 0:
2768 case IXGBE_ERR_SFP_NOT_PRESENT:
2769 break;
2770 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
2771 dev_err(&adapter->pdev->dev, "master disable timed out\n");
2772 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00002773 case IXGBE_ERR_EEPROM_VERSION:
2774 /* We are running on a pre-production device, log a warning */
2775 dev_warn(&adapter->pdev->dev, "This device is a pre-production "
2776 "adapter/LOM. Please be aware there may be issues "
2777 "associated with your hardware. If you are "
2778 "experiencing problems please contact your Intel or "
2779 "hardware representative who provided you with this "
2780 "hardware.\n");
2781 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002782 default:
2783 dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err);
2784 }
Auke Kok9a799d72007-09-15 14:07:45 -07002785
2786 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002787 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002788}
2789
Auke Kok9a799d72007-09-15 14:07:45 -07002790/**
2791 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2792 * @adapter: board private structure
2793 * @rx_ring: ring to free buffers from
2794 **/
2795static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002796 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002797{
2798 struct pci_dev *pdev = adapter->pdev;
2799 unsigned long size;
2800 unsigned int i;
2801
2802 /* Free all the Rx ring sk_buffs */
2803
2804 for (i = 0; i < rx_ring->count; i++) {
2805 struct ixgbe_rx_buffer *rx_buffer_info;
2806
2807 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2808 if (rx_buffer_info->dma) {
2809 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002810 rx_ring->rx_buf_len,
2811 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002812 rx_buffer_info->dma = 0;
2813 }
2814 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002815 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002816 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002817 do {
2818 struct sk_buff *this = skb;
2819 skb = skb->prev;
2820 dev_kfree_skb(this);
2821 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002822 }
2823 if (!rx_buffer_info->page)
2824 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00002825 if (rx_buffer_info->page_dma) {
2826 pci_unmap_page(pdev, rx_buffer_info->page_dma,
2827 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
2828 rx_buffer_info->page_dma = 0;
2829 }
Auke Kok9a799d72007-09-15 14:07:45 -07002830 put_page(rx_buffer_info->page);
2831 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002832 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002833 }
2834
2835 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2836 memset(rx_ring->rx_buffer_info, 0, size);
2837
2838 /* Zero out the descriptor ring */
2839 memset(rx_ring->desc, 0, rx_ring->size);
2840
2841 rx_ring->next_to_clean = 0;
2842 rx_ring->next_to_use = 0;
2843
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002844 if (rx_ring->head)
2845 writel(0, adapter->hw.hw_addr + rx_ring->head);
2846 if (rx_ring->tail)
2847 writel(0, adapter->hw.hw_addr + rx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002848}
2849
2850/**
2851 * ixgbe_clean_tx_ring - Free Tx Buffers
2852 * @adapter: board private structure
2853 * @tx_ring: ring to be cleaned
2854 **/
2855static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002856 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002857{
2858 struct ixgbe_tx_buffer *tx_buffer_info;
2859 unsigned long size;
2860 unsigned int i;
2861
2862 /* Free all the Tx ring sk_buffs */
2863
2864 for (i = 0; i < tx_ring->count; i++) {
2865 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2866 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2867 }
2868
2869 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2870 memset(tx_ring->tx_buffer_info, 0, size);
2871
2872 /* Zero out the descriptor ring */
2873 memset(tx_ring->desc, 0, tx_ring->size);
2874
2875 tx_ring->next_to_use = 0;
2876 tx_ring->next_to_clean = 0;
2877
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002878 if (tx_ring->head)
2879 writel(0, adapter->hw.hw_addr + tx_ring->head);
2880 if (tx_ring->tail)
2881 writel(0, adapter->hw.hw_addr + tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002882}
2883
2884/**
Auke Kok9a799d72007-09-15 14:07:45 -07002885 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2886 * @adapter: board private structure
2887 **/
2888static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2889{
2890 int i;
2891
2892 for (i = 0; i < adapter->num_rx_queues; i++)
2893 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2894}
2895
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002896/**
2897 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2898 * @adapter: board private structure
2899 **/
2900static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2901{
2902 int i;
2903
2904 for (i = 0; i < adapter->num_tx_queues; i++)
2905 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2906}
2907
Auke Kok9a799d72007-09-15 14:07:45 -07002908void ixgbe_down(struct ixgbe_adapter *adapter)
2909{
2910 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002911 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002912 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002913 u32 txdctl;
2914 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002915
2916 /* signal that we are down to the interrupt handler */
2917 set_bit(__IXGBE_DOWN, &adapter->state);
2918
2919 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002920 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2921 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002922
2923 netif_tx_disable(netdev);
2924
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002925 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002926 msleep(10);
2927
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002928 netif_tx_stop_all_queues(netdev);
2929
Auke Kok9a799d72007-09-15 14:07:45 -07002930 ixgbe_irq_disable(adapter);
2931
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002932 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002933
Auke Kok9a799d72007-09-15 14:07:45 -07002934 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002935 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002936
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002937 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
2938 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2939 cancel_work_sync(&adapter->fdir_reinit_task);
2940
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002941 /* disable transmits in the hardware now that interrupts are off */
2942 for (i = 0; i < adapter->num_tx_queues; i++) {
2943 j = adapter->tx_ring[i].reg_idx;
2944 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2945 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2946 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2947 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00002948 /* Disable the Tx DMA engine on 82599 */
2949 if (hw->mac.type == ixgbe_mac_82599EB)
2950 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
2951 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
2952 ~IXGBE_DMATXCTL_TE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002953
Auke Kok9a799d72007-09-15 14:07:45 -07002954 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002955
Paul Larson6f4a0e42008-06-24 17:00:56 -07002956 if (!pci_channel_offline(adapter->pdev))
2957 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002958 ixgbe_clean_all_tx_rings(adapter);
2959 ixgbe_clean_all_rx_rings(adapter);
2960
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002961#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002962 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00002963 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002964#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002965}
2966
Auke Kok9a799d72007-09-15 14:07:45 -07002967/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002968 * ixgbe_poll - NAPI Rx polling callback
2969 * @napi: structure for representing this polling device
2970 * @budget: how many packets driver is allowed to clean
2971 *
2972 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002973 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002974static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002975{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002976 struct ixgbe_q_vector *q_vector =
2977 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002978 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002979 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002980
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002981#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002982 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2983 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2984 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2985 }
2986#endif
2987
Alexander Duyckfe49f042009-06-04 16:00:09 +00002988 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002989 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002990
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002991 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002992 work_done = budget;
2993
David S. Miller53e52c72008-01-07 21:06:12 -08002994 /* If budget not fully consumed, exit the polling mode */
2995 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002996 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002997 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002998 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002999 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00003000 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003001 }
Auke Kok9a799d72007-09-15 14:07:45 -07003002 return work_done;
3003}
3004
3005/**
3006 * ixgbe_tx_timeout - Respond to a Tx Hang
3007 * @netdev: network interface device structure
3008 **/
3009static void ixgbe_tx_timeout(struct net_device *netdev)
3010{
3011 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3012
3013 /* Do the reset outside of interrupt context */
3014 schedule_work(&adapter->reset_task);
3015}
3016
3017static void ixgbe_reset_task(struct work_struct *work)
3018{
3019 struct ixgbe_adapter *adapter;
3020 adapter = container_of(work, struct ixgbe_adapter, reset_task);
3021
Alexander Duyck2f90b862008-11-20 20:52:10 -08003022 /* If we're already down or resetting, just bail */
3023 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
3024 test_bit(__IXGBE_RESETTING, &adapter->state))
3025 return;
3026
Auke Kok9a799d72007-09-15 14:07:45 -07003027 adapter->tx_timeout_count++;
3028
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003029 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003030}
3031
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003032#ifdef CONFIG_IXGBE_DCB
3033static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003034{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003035 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003036 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003037
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003038 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
3039 return ret;
3040
3041 f->mask = 0x7 << 3;
3042 adapter->num_rx_queues = f->indices;
3043 adapter->num_tx_queues = f->indices;
3044 ret = true;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003045
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003046 return ret;
3047}
3048#endif
3049
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003050/**
3051 * ixgbe_set_rss_queues: Allocate queues for RSS
3052 * @adapter: board private structure to initialize
3053 *
3054 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
3055 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
3056 *
3057 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003058static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
3059{
3060 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003061 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003062
3063 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003064 f->mask = 0xF;
3065 adapter->num_rx_queues = f->indices;
3066 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003067 ret = true;
3068 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003069 ret = false;
3070 }
3071
3072 return ret;
3073}
3074
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003075/**
3076 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
3077 * @adapter: board private structure to initialize
3078 *
3079 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
3080 * to the original CPU that initiated the Tx session. This runs in addition
3081 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
3082 * Rx load across CPUs using RSS.
3083 *
3084 **/
3085static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
3086{
3087 bool ret = false;
3088 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
3089
3090 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
3091 f_fdir->mask = 0;
3092
3093 /* Flow Director must have RSS enabled */
3094 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3095 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3096 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
3097 adapter->num_tx_queues = f_fdir->indices;
3098 adapter->num_rx_queues = f_fdir->indices;
3099 ret = true;
3100 } else {
3101 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3102 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3103 }
3104 return ret;
3105}
3106
Yi Zou0331a832009-05-17 12:33:52 +00003107#ifdef IXGBE_FCOE
3108/**
3109 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
3110 * @adapter: board private structure to initialize
3111 *
3112 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
3113 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
3114 * rx queues out of the max number of rx queues, instead, it is used as the
3115 * index of the first rx queue used by FCoE.
3116 *
3117 **/
3118static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
3119{
3120 bool ret = false;
3121 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3122
3123 f->indices = min((int)num_online_cpus(), f->indices);
3124 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3125#ifdef CONFIG_IXGBE_DCB
3126 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3127 DPRINTK(PROBE, INFO, "FCOE enabled with DCB \n");
3128 ixgbe_set_dcb_queues(adapter);
3129 }
3130#endif
3131 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3132 DPRINTK(PROBE, INFO, "FCOE enabled with RSS \n");
3133 ixgbe_set_rss_queues(adapter);
3134 }
3135 /* adding FCoE rx rings to the end */
3136 f->mask = adapter->num_rx_queues;
3137 adapter->num_rx_queues += f->indices;
3138 if (adapter->num_tx_queues == 0)
3139 adapter->num_tx_queues = f->indices;
3140
3141 ret = true;
3142 }
3143
3144 return ret;
3145}
3146
3147#endif /* IXGBE_FCOE */
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003148/*
3149 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
3150 * @adapter: board private structure to initialize
3151 *
3152 * This is the top level queue allocation routine. The order here is very
3153 * important, starting with the "most" number of features turned on at once,
3154 * and ending with the smallest set of features. This way large combinations
3155 * can be allocated if they're turned on, and smaller combinations are the
3156 * fallthrough conditions.
3157 *
3158 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003159static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
3160{
Yi Zou0331a832009-05-17 12:33:52 +00003161#ifdef IXGBE_FCOE
3162 if (ixgbe_set_fcoe_queues(adapter))
3163 goto done;
3164
3165#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003166#ifdef CONFIG_IXGBE_DCB
3167 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003168 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003169
3170#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003171 if (ixgbe_set_fdir_queues(adapter))
3172 goto done;
3173
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003174 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003175 goto done;
3176
3177 /* fallback to base case */
3178 adapter->num_rx_queues = 1;
3179 adapter->num_tx_queues = 1;
3180
3181done:
3182 /* Notify the stack of the (possibly) reduced Tx Queue count. */
3183 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003184}
3185
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003186static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003187 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003188{
3189 int err, vector_threshold;
3190
3191 /* We'll want at least 3 (vector_threshold):
3192 * 1) TxQ[0] Cleanup
3193 * 2) RxQ[0] Cleanup
3194 * 3) Other (Link Status Change, etc.)
3195 * 4) TCP Timer (optional)
3196 */
3197 vector_threshold = MIN_MSIX_COUNT;
3198
3199 /* The more we get, the more we will assign to Tx/Rx Cleanup
3200 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
3201 * Right now, we simply care about how many we'll get; we'll
3202 * set them up later while requesting irq's.
3203 */
3204 while (vectors >= vector_threshold) {
3205 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003206 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003207 if (!err) /* Success in acquiring all requested vectors. */
3208 break;
3209 else if (err < 0)
3210 vectors = 0; /* Nasty failure, quit now */
3211 else /* err == number of vectors we should try again with */
3212 vectors = err;
3213 }
3214
3215 if (vectors < vector_threshold) {
3216 /* Can't allocate enough MSI-X interrupts? Oh well.
3217 * This just means we'll go with either a single MSI
3218 * vector or fall back to legacy interrupts.
3219 */
3220 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
3221 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3222 kfree(adapter->msix_entries);
3223 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003224 } else {
3225 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08003226 /*
3227 * Adjust for only the vectors we'll use, which is minimum
3228 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
3229 * vectors we were allocated.
3230 */
3231 adapter->num_msix_vectors = min(vectors,
3232 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003233 }
3234}
3235
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003236/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003237 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003238 * @adapter: board private structure to initialize
3239 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003240 * Cache the descriptor ring offsets for RSS to the assigned rings.
3241 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003242 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003243static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003244{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003245 int i;
3246 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003247
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003248 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3249 for (i = 0; i < adapter->num_rx_queues; i++)
3250 adapter->rx_ring[i].reg_idx = i;
3251 for (i = 0; i < adapter->num_tx_queues; i++)
3252 adapter->tx_ring[i].reg_idx = i;
3253 ret = true;
3254 } else {
3255 ret = false;
3256 }
3257
3258 return ret;
3259}
3260
3261#ifdef CONFIG_IXGBE_DCB
3262/**
3263 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
3264 * @adapter: board private structure to initialize
3265 *
3266 * Cache the descriptor ring offsets for DCB to the assigned rings.
3267 *
3268 **/
3269static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
3270{
3271 int i;
3272 bool ret = false;
3273 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
3274
3275 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3276 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08003277 /* the number of queues is assumed to be symmetric */
3278 for (i = 0; i < dcb_i; i++) {
3279 adapter->rx_ring[i].reg_idx = i << 3;
3280 adapter->tx_ring[i].reg_idx = i << 2;
3281 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003282 ret = true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003283 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
PJ Waskiewiczf92ef202009-04-16 15:00:20 +00003284 if (dcb_i == 8) {
3285 /*
3286 * Tx TC0 starts at: descriptor queue 0
3287 * Tx TC1 starts at: descriptor queue 32
3288 * Tx TC2 starts at: descriptor queue 64
3289 * Tx TC3 starts at: descriptor queue 80
3290 * Tx TC4 starts at: descriptor queue 96
3291 * Tx TC5 starts at: descriptor queue 104
3292 * Tx TC6 starts at: descriptor queue 112
3293 * Tx TC7 starts at: descriptor queue 120
3294 *
3295 * Rx TC0-TC7 are offset by 16 queues each
3296 */
3297 for (i = 0; i < 3; i++) {
3298 adapter->tx_ring[i].reg_idx = i << 5;
3299 adapter->rx_ring[i].reg_idx = i << 4;
3300 }
3301 for ( ; i < 5; i++) {
3302 adapter->tx_ring[i].reg_idx =
3303 ((i + 2) << 4);
3304 adapter->rx_ring[i].reg_idx = i << 4;
3305 }
3306 for ( ; i < dcb_i; i++) {
3307 adapter->tx_ring[i].reg_idx =
3308 ((i + 8) << 3);
3309 adapter->rx_ring[i].reg_idx = i << 4;
3310 }
3311
3312 ret = true;
3313 } else if (dcb_i == 4) {
3314 /*
3315 * Tx TC0 starts at: descriptor queue 0
3316 * Tx TC1 starts at: descriptor queue 64
3317 * Tx TC2 starts at: descriptor queue 96
3318 * Tx TC3 starts at: descriptor queue 112
3319 *
3320 * Rx TC0-TC3 are offset by 32 queues each
3321 */
3322 adapter->tx_ring[0].reg_idx = 0;
3323 adapter->tx_ring[1].reg_idx = 64;
3324 adapter->tx_ring[2].reg_idx = 96;
3325 adapter->tx_ring[3].reg_idx = 112;
3326 for (i = 0 ; i < dcb_i; i++)
3327 adapter->rx_ring[i].reg_idx = i << 5;
3328
3329 ret = true;
3330 } else {
3331 ret = false;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003332 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003333 } else {
3334 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003335 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003336 } else {
3337 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003338 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003339
3340 return ret;
3341}
3342#endif
3343
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003344/**
3345 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
3346 * @adapter: board private structure to initialize
3347 *
3348 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
3349 *
3350 **/
3351static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
3352{
3353 int i;
3354 bool ret = false;
3355
3356 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3357 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3358 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
3359 for (i = 0; i < adapter->num_rx_queues; i++)
3360 adapter->rx_ring[i].reg_idx = i;
3361 for (i = 0; i < adapter->num_tx_queues; i++)
3362 adapter->tx_ring[i].reg_idx = i;
3363 ret = true;
3364 }
3365
3366 return ret;
3367}
3368
Yi Zou0331a832009-05-17 12:33:52 +00003369#ifdef IXGBE_FCOE
3370/**
3371 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
3372 * @adapter: board private structure to initialize
3373 *
3374 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
3375 *
3376 */
3377static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
3378{
3379 int i, fcoe_i = 0;
3380 bool ret = false;
3381 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3382
3383 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3384#ifdef CONFIG_IXGBE_DCB
3385 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3386 ixgbe_cache_ring_dcb(adapter);
3387 fcoe_i = adapter->rx_ring[0].reg_idx + 1;
3388 }
3389#endif /* CONFIG_IXGBE_DCB */
3390 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3391 ixgbe_cache_ring_rss(adapter);
3392 fcoe_i = f->mask;
3393 }
3394 for (i = 0; i < f->indices; i++, fcoe_i++)
3395 adapter->rx_ring[f->mask + i].reg_idx = fcoe_i;
3396 ret = true;
3397 }
3398 return ret;
3399}
3400
3401#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003402/**
3403 * ixgbe_cache_ring_register - Descriptor ring to register mapping
3404 * @adapter: board private structure to initialize
3405 *
3406 * Once we know the feature-set enabled for the device, we'll cache
3407 * the register offset the descriptor ring is assigned to.
3408 *
3409 * Note, the order the various feature calls is important. It must start with
3410 * the "most" features enabled at the same time, then trickle down to the
3411 * least amount of features turned on at once.
3412 **/
3413static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
3414{
3415 /* start with default case */
3416 adapter->rx_ring[0].reg_idx = 0;
3417 adapter->tx_ring[0].reg_idx = 0;
3418
Yi Zou0331a832009-05-17 12:33:52 +00003419#ifdef IXGBE_FCOE
3420 if (ixgbe_cache_ring_fcoe(adapter))
3421 return;
3422
3423#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003424#ifdef CONFIG_IXGBE_DCB
3425 if (ixgbe_cache_ring_dcb(adapter))
3426 return;
3427
3428#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003429 if (ixgbe_cache_ring_fdir(adapter))
3430 return;
3431
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003432 if (ixgbe_cache_ring_rss(adapter))
3433 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003434}
3435
Auke Kok9a799d72007-09-15 14:07:45 -07003436/**
3437 * ixgbe_alloc_queues - Allocate memory for all rings
3438 * @adapter: board private structure to initialize
3439 *
3440 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003441 * number of queues at compile-time. The polling_netdev array is
3442 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07003443 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003444static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003445{
3446 int i;
3447
3448 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003449 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07003450 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003451 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07003452
3453 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003454 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003455 if (!adapter->rx_ring)
3456 goto err_rx_ring_allocation;
3457
3458 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003459 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003460 adapter->tx_ring[i].queue_index = i;
3461 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003462
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003463 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003464 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003465 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07003466 }
3467
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003468 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003469
3470 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003471
3472err_rx_ring_allocation:
3473 kfree(adapter->tx_ring);
3474err_tx_ring_allocation:
3475 return -ENOMEM;
3476}
3477
3478/**
3479 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3480 * @adapter: board private structure to initialize
3481 *
3482 * Attempt to configure the interrupts using the best available
3483 * capabilities of the hardware and the kernel.
3484 **/
Al Virofeea6a52008-11-27 15:34:07 -08003485static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003486{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003487 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003488 int err = 0;
3489 int vector, v_budget;
3490
3491 /*
3492 * It's easy to be greedy for MSI-X vectors, but it really
3493 * doesn't do us much good if we have a lot more vectors
3494 * than CPU's. So let's be conservative and only ask for
3495 * (roughly) twice the number of vectors as there are CPU's.
3496 */
3497 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003498 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003499
3500 /*
3501 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003502 * hw.mac->max_msix_vectors vectors. With features
3503 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3504 * descriptor queues supported by our device. Thus, we cap it off in
3505 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003506 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003507 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003508
3509 /* A failure in MSI-X entry allocation isn't fatal, but it does
3510 * mean we disable MSI-X capabilities of the adapter. */
3511 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003512 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003513 if (adapter->msix_entries) {
3514 for (vector = 0; vector < v_budget; vector++)
3515 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003516
Alexander Duyck7a921c92009-05-06 10:43:28 +00003517 ixgbe_acquire_msix_vectors(adapter, v_budget);
3518
3519 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3520 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003521 }
3522
Alexander Duyck7a921c92009-05-06 10:43:28 +00003523 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
3524 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003525 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3526 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3527 adapter->atr_sample_rate = 0;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003528 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003529
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003530 err = pci_enable_msi(adapter->pdev);
3531 if (!err) {
3532 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
3533 } else {
3534 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003535 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003536 /* reset err */
3537 err = 0;
3538 }
3539
3540out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003541 return err;
3542}
3543
Alexander Duyck7a921c92009-05-06 10:43:28 +00003544/**
3545 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
3546 * @adapter: board private structure to initialize
3547 *
3548 * We allocate one q_vector per queue interrupt. If allocation fails we
3549 * return -ENOMEM.
3550 **/
3551static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
3552{
3553 int q_idx, num_q_vectors;
3554 struct ixgbe_q_vector *q_vector;
3555 int napi_vectors;
3556 int (*poll)(struct napi_struct *, int);
3557
3558 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3559 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3560 napi_vectors = adapter->num_rx_queues;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003561 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003562 } else {
3563 num_q_vectors = 1;
3564 napi_vectors = 1;
3565 poll = &ixgbe_poll;
3566 }
3567
3568 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3569 q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL);
3570 if (!q_vector)
3571 goto err_out;
3572 q_vector->adapter = adapter;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003573 q_vector->eitr = adapter->eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00003574 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003575 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003576 adapter->q_vector[q_idx] = q_vector;
3577 }
3578
3579 return 0;
3580
3581err_out:
3582 while (q_idx) {
3583 q_idx--;
3584 q_vector = adapter->q_vector[q_idx];
3585 netif_napi_del(&q_vector->napi);
3586 kfree(q_vector);
3587 adapter->q_vector[q_idx] = NULL;
3588 }
3589 return -ENOMEM;
3590}
3591
3592/**
3593 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
3594 * @adapter: board private structure to initialize
3595 *
3596 * This function frees the memory allocated to the q_vectors. In addition if
3597 * NAPI is enabled it will delete any references to the NAPI struct prior
3598 * to freeing the q_vector.
3599 **/
3600static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
3601{
3602 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003603
Alexander Duyck91281fd2009-06-04 16:00:27 +00003604 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00003605 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003606 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00003607 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003608
3609 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3610 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00003611 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003612 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003613 kfree(q_vector);
3614 }
3615}
3616
Alexander Duyck2f90b862008-11-20 20:52:10 -08003617void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003618{
3619 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3620 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3621 pci_disable_msix(adapter->pdev);
3622 kfree(adapter->msix_entries);
3623 adapter->msix_entries = NULL;
3624 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
3625 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
3626 pci_disable_msi(adapter->pdev);
3627 }
3628 return;
3629}
3630
3631/**
3632 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3633 * @adapter: board private structure to initialize
3634 *
3635 * We determine which interrupt scheme to use based on...
3636 * - Kernel support (MSI, MSI-X)
3637 * - which can be user-defined (via MODULE_PARAM)
3638 * - Hardware queue count (num_*_queues)
3639 * - defined by miscellaneous hardware support/features (RSS, etc.)
3640 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003641int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003642{
3643 int err;
3644
3645 /* Number of supported queues */
3646 ixgbe_set_num_queues(adapter);
3647
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003648 err = ixgbe_set_interrupt_capability(adapter);
3649 if (err) {
3650 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3651 goto err_set_interrupt;
3652 }
3653
Alexander Duyck7a921c92009-05-06 10:43:28 +00003654 err = ixgbe_alloc_q_vectors(adapter);
3655 if (err) {
3656 DPRINTK(PROBE, ERR, "Unable to allocate memory for queue "
3657 "vectors\n");
3658 goto err_alloc_q_vectors;
3659 }
3660
3661 err = ixgbe_alloc_queues(adapter);
3662 if (err) {
3663 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3664 goto err_alloc_queues;
3665 }
3666
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003667 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003668 "Tx Queue count = %u\n",
3669 (adapter->num_rx_queues > 1) ? "Enabled" :
3670 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003671
3672 set_bit(__IXGBE_DOWN, &adapter->state);
3673
3674 return 0;
3675
Alexander Duyck7a921c92009-05-06 10:43:28 +00003676err_alloc_queues:
3677 ixgbe_free_q_vectors(adapter);
3678err_alloc_q_vectors:
3679 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003680err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00003681 return err;
3682}
3683
3684/**
3685 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
3686 * @adapter: board private structure to clear interrupt scheme on
3687 *
3688 * We go through and clear interrupt specific resources and reset the structure
3689 * to pre-load conditions
3690 **/
3691void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
3692{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003693 kfree(adapter->tx_ring);
3694 kfree(adapter->rx_ring);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003695 adapter->tx_ring = NULL;
3696 adapter->rx_ring = NULL;
3697
3698 ixgbe_free_q_vectors(adapter);
3699 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003700}
3701
3702/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08003703 * ixgbe_sfp_timer - worker thread to find a missing module
3704 * @data: pointer to our adapter struct
3705 **/
3706static void ixgbe_sfp_timer(unsigned long data)
3707{
3708 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3709
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003710 /*
3711 * Do the sfp_timer outside of interrupt context due to the
Donald Skidmorec4900be2008-11-20 21:11:42 -08003712 * delays that sfp+ detection requires
3713 */
3714 schedule_work(&adapter->sfp_task);
3715}
3716
3717/**
3718 * ixgbe_sfp_task - worker thread to find a missing module
3719 * @work: pointer to work_struct containing our data
3720 **/
3721static void ixgbe_sfp_task(struct work_struct *work)
3722{
3723 struct ixgbe_adapter *adapter = container_of(work,
3724 struct ixgbe_adapter,
3725 sfp_task);
3726 struct ixgbe_hw *hw = &adapter->hw;
3727
3728 if ((hw->phy.type == ixgbe_phy_nl) &&
3729 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3730 s32 ret = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00003731 if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
Donald Skidmorec4900be2008-11-20 21:11:42 -08003732 goto reschedule;
3733 ret = hw->phy.ops.reset(hw);
3734 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00003735 dev_err(&adapter->pdev->dev, "failed to initialize "
3736 "because an unsupported SFP+ module type "
3737 "was detected.\n"
3738 "Reload the driver after installing a "
3739 "supported module.\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08003740 unregister_netdev(adapter->netdev);
3741 } else {
3742 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3743 hw->phy.sfp_type);
3744 }
3745 /* don't need this routine any more */
3746 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3747 }
3748 return;
3749reschedule:
3750 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3751 mod_timer(&adapter->sfp_timer,
3752 round_jiffies(jiffies + (2 * HZ)));
3753}
3754
3755/**
Auke Kok9a799d72007-09-15 14:07:45 -07003756 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3757 * @adapter: board private structure to initialize
3758 *
3759 * ixgbe_sw_init initializes the Adapter private data structure.
3760 * Fields are initialized based on PCI device information and
3761 * OS network device settings (MTU size).
3762 **/
3763static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3764{
3765 struct ixgbe_hw *hw = &adapter->hw;
3766 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003767 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003768#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003769 int j;
3770 struct tc_configuration *tc;
3771#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003772
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003773 /* PCI config space info */
3774
3775 hw->vendor_id = pdev->vendor;
3776 hw->device_id = pdev->device;
3777 hw->revision_id = pdev->revision;
3778 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3779 hw->subsystem_device_id = pdev->subsystem_device;
3780
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003781 /* Set capability flags */
3782 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3783 adapter->ring_feature[RING_F_RSS].indices = rss;
3784 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003785 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Don Skidmorebf069c92009-05-07 10:39:54 +00003786 if (hw->mac.type == ixgbe_mac_82598EB) {
3787 if (hw->device_id == IXGBE_DEV_ID_82598AT)
3788 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003789 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Don Skidmorebf069c92009-05-07 10:39:54 +00003790 } else if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003791 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00003792 adapter->flags |= IXGBE_FLAG2_RSC_CAPABLE;
3793 adapter->flags |= IXGBE_FLAG2_RSC_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003794 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
3795 adapter->ring_feature[RING_F_FDIR].indices =
3796 IXGBE_MAX_FDIR_INDICES;
3797 adapter->atr_sample_rate = 20;
3798 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00003799#ifdef IXGBE_FCOE
3800 adapter->flags |= IXGBE_FLAG_FCOE_ENABLED;
Yi Zou0331a832009-05-17 12:33:52 +00003801 adapter->ring_feature[RING_F_FCOE].indices = IXGBE_FCRETA_SIZE;
Yi Zoueacd73f2009-05-13 13:11:06 +00003802#endif /* IXGBE_FCOE */
Alexander Duyckf8212f92009-04-27 22:42:37 +00003803 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003804
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003805#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003806 /* Configure DCB traffic classes */
3807 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3808 tc = &adapter->dcb_cfg.tc_config[j];
3809 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3810 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3811 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3812 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3813 tc->dcb_pfc = pfc_disabled;
3814 }
3815 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3816 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3817 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003818 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003819 adapter->dcb_cfg.round_robin_enable = false;
3820 adapter->dcb_set_bitmap = 0x00;
3821 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3822 adapter->ring_feature[RING_F_DCB].indices);
3823
3824#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003825
3826 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00003827 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00003828 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003829#ifdef CONFIG_DCB
3830 adapter->last_lfc_mode = hw->fc.current_mode;
3831#endif
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07003832 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3833 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3834 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3835 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00003836 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07003837
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07003838 /* enable itr by default in dynamic mode */
3839 adapter->itr_setting = 1;
3840 adapter->eitr_param = 20000;
3841
3842 /* set defaults for eitr in MegaBytes */
3843 adapter->eitr_low = 10;
3844 adapter->eitr_high = 20;
3845
3846 /* set default ring sizes */
3847 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
3848 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
3849
Auke Kok9a799d72007-09-15 14:07:45 -07003850 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003851 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003852 dev_err(&pdev->dev, "EEPROM initialization failed\n");
3853 return -EIO;
3854 }
3855
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003856 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07003857 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
3858
Auke Kok9a799d72007-09-15 14:07:45 -07003859 set_bit(__IXGBE_DOWN, &adapter->state);
3860
3861 return 0;
3862}
3863
3864/**
3865 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3866 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003867 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003868 *
3869 * Return 0 on success, negative on failure
3870 **/
3871int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003872 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003873{
3874 struct pci_dev *pdev = adapter->pdev;
3875 int size;
3876
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003877 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3878 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003879 if (!tx_ring->tx_buffer_info)
3880 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003881 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003882
3883 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08003884 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003885 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003886
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003887 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
3888 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003889 if (!tx_ring->desc)
3890 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07003891
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003892 tx_ring->next_to_use = 0;
3893 tx_ring->next_to_clean = 0;
3894 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07003895 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003896
3897err:
3898 vfree(tx_ring->tx_buffer_info);
3899 tx_ring->tx_buffer_info = NULL;
3900 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
3901 "descriptor ring\n");
3902 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003903}
3904
3905/**
Alexander Duyck69888672008-09-11 20:05:39 -07003906 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
3907 * @adapter: board private structure
3908 *
3909 * If this function returns with an error, then it's possible one or
3910 * more of the rings is populated (while the rest are not). It is the
3911 * callers duty to clean those orphaned rings.
3912 *
3913 * Return 0 on success, negative on failure
3914 **/
3915static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
3916{
3917 int i, err = 0;
3918
3919 for (i = 0; i < adapter->num_tx_queues; i++) {
3920 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
3921 if (!err)
3922 continue;
3923 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
3924 break;
3925 }
3926
3927 return err;
3928}
3929
3930/**
Auke Kok9a799d72007-09-15 14:07:45 -07003931 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
3932 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003933 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003934 *
3935 * Returns 0 on success, negative on failure
3936 **/
3937int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003938 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003939{
3940 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003941 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07003942
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003943 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
3944 rx_ring->rx_buffer_info = vmalloc(size);
3945 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07003946 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003947 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003948 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003949 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003950 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003951
Auke Kok9a799d72007-09-15 14:07:45 -07003952 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003953 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
3954 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003955
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003956 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07003957
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003958 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07003959 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003960 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003961 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003962 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003963 }
3964
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003965 rx_ring->next_to_clean = 0;
3966 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003967
3968 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003969
3970alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003971 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003972}
3973
3974/**
Alexander Duyck69888672008-09-11 20:05:39 -07003975 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
3976 * @adapter: board private structure
3977 *
3978 * If this function returns with an error, then it's possible one or
3979 * more of the rings is populated (while the rest are not). It is the
3980 * callers duty to clean those orphaned rings.
3981 *
3982 * Return 0 on success, negative on failure
3983 **/
3984
3985static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
3986{
3987 int i, err = 0;
3988
3989 for (i = 0; i < adapter->num_rx_queues; i++) {
3990 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
3991 if (!err)
3992 continue;
3993 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
3994 break;
3995 }
3996
3997 return err;
3998}
3999
4000/**
Auke Kok9a799d72007-09-15 14:07:45 -07004001 * ixgbe_free_tx_resources - Free Tx Resources per Queue
4002 * @adapter: board private structure
4003 * @tx_ring: Tx descriptor ring for a specific queue
4004 *
4005 * Free all transmit software resources
4006 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07004007void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
4008 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004009{
4010 struct pci_dev *pdev = adapter->pdev;
4011
4012 ixgbe_clean_tx_ring(adapter, tx_ring);
4013
4014 vfree(tx_ring->tx_buffer_info);
4015 tx_ring->tx_buffer_info = NULL;
4016
4017 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
4018
4019 tx_ring->desc = NULL;
4020}
4021
4022/**
4023 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4024 * @adapter: board private structure
4025 *
4026 * Free all transmit software resources
4027 **/
4028static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4029{
4030 int i;
4031
4032 for (i = 0; i < adapter->num_tx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004033 if (adapter->tx_ring[i].desc)
4034 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004035}
4036
4037/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004038 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004039 * @adapter: board private structure
4040 * @rx_ring: ring to clean the resources from
4041 *
4042 * Free all receive software resources
4043 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07004044void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
4045 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004046{
4047 struct pci_dev *pdev = adapter->pdev;
4048
4049 ixgbe_clean_rx_ring(adapter, rx_ring);
4050
4051 vfree(rx_ring->rx_buffer_info);
4052 rx_ring->rx_buffer_info = NULL;
4053
4054 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
4055
4056 rx_ring->desc = NULL;
4057}
4058
4059/**
4060 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4061 * @adapter: board private structure
4062 *
4063 * Free all receive software resources
4064 **/
4065static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4066{
4067 int i;
4068
4069 for (i = 0; i < adapter->num_rx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004070 if (adapter->rx_ring[i].desc)
4071 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004072}
4073
4074/**
Auke Kok9a799d72007-09-15 14:07:45 -07004075 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4076 * @netdev: network interface device structure
4077 * @new_mtu: new value for maximum frame size
4078 *
4079 * Returns 0 on success, negative on failure
4080 **/
4081static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4082{
4083 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4084 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4085
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004086 /* MTU < 68 is an error and causes problems on some kernels */
4087 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07004088 return -EINVAL;
4089
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004090 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004091 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004092 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004093 netdev->mtu = new_mtu;
4094
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004095 if (netif_running(netdev))
4096 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004097
4098 return 0;
4099}
4100
4101/**
4102 * ixgbe_open - Called when a network interface is made active
4103 * @netdev: network interface device structure
4104 *
4105 * Returns 0 on success, negative value on failure
4106 *
4107 * The open entry point is called when a network interface is made
4108 * active by the system (IFF_UP). At this point all resources needed
4109 * for transmit and receive operations are allocated, the interrupt
4110 * handler is registered with the OS, the watchdog timer is started,
4111 * and the stack is notified that the interface is ready.
4112 **/
4113static int ixgbe_open(struct net_device *netdev)
4114{
4115 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4116 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004117
Auke Kok4bebfaa2008-02-11 09:26:01 -08004118 /* disallow open during test */
4119 if (test_bit(__IXGBE_TESTING, &adapter->state))
4120 return -EBUSY;
4121
Jesse Brandeburg54386462009-04-17 20:44:27 +00004122 netif_carrier_off(netdev);
4123
Auke Kok9a799d72007-09-15 14:07:45 -07004124 /* allocate transmit descriptors */
4125 err = ixgbe_setup_all_tx_resources(adapter);
4126 if (err)
4127 goto err_setup_tx;
4128
Auke Kok9a799d72007-09-15 14:07:45 -07004129 /* allocate receive descriptors */
4130 err = ixgbe_setup_all_rx_resources(adapter);
4131 if (err)
4132 goto err_setup_rx;
4133
4134 ixgbe_configure(adapter);
4135
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004136 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004137 if (err)
4138 goto err_req_irq;
4139
Auke Kok9a799d72007-09-15 14:07:45 -07004140 err = ixgbe_up_complete(adapter);
4141 if (err)
4142 goto err_up;
4143
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004144 netif_tx_start_all_queues(netdev);
4145
Auke Kok9a799d72007-09-15 14:07:45 -07004146 return 0;
4147
4148err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004149 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004150 ixgbe_free_irq(adapter);
4151err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07004152err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004153 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004154err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004155 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004156 ixgbe_reset(adapter);
4157
4158 return err;
4159}
4160
4161/**
4162 * ixgbe_close - Disables a network interface
4163 * @netdev: network interface device structure
4164 *
4165 * Returns 0, this is not allowed to fail
4166 *
4167 * The close entry point is called when an interface is de-activated
4168 * by the OS. The hardware is still under the drivers control, but
4169 * needs to be disabled. A global MAC reset is issued to stop the
4170 * hardware, and all transmit and receive resources are freed.
4171 **/
4172static int ixgbe_close(struct net_device *netdev)
4173{
4174 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004175
4176 ixgbe_down(adapter);
4177 ixgbe_free_irq(adapter);
4178
4179 ixgbe_free_all_tx_resources(adapter);
4180 ixgbe_free_all_rx_resources(adapter);
4181
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004182 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004183
4184 return 0;
4185}
4186
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004187#ifdef CONFIG_PM
4188static int ixgbe_resume(struct pci_dev *pdev)
4189{
4190 struct net_device *netdev = pci_get_drvdata(pdev);
4191 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4192 u32 err;
4193
4194 pci_set_power_state(pdev, PCI_D0);
4195 pci_restore_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004196
4197 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004198 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07004199 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004200 "suspend\n");
4201 return err;
4202 }
4203 pci_set_master(pdev);
4204
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004205 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004206
4207 err = ixgbe_init_interrupt_scheme(adapter);
4208 if (err) {
4209 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
4210 "device\n");
4211 return err;
4212 }
4213
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004214 ixgbe_reset(adapter);
4215
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00004216 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4217
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004218 if (netif_running(netdev)) {
4219 err = ixgbe_open(adapter->netdev);
4220 if (err)
4221 return err;
4222 }
4223
4224 netif_device_attach(netdev);
4225
4226 return 0;
4227}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004228#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004229
4230static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004231{
4232 struct net_device *netdev = pci_get_drvdata(pdev);
4233 struct ixgbe_adapter *adapter = netdev_priv(netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004234 struct ixgbe_hw *hw = &adapter->hw;
4235 u32 ctrl, fctrl;
4236 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004237#ifdef CONFIG_PM
4238 int retval = 0;
4239#endif
4240
4241 netif_device_detach(netdev);
4242
4243 if (netif_running(netdev)) {
4244 ixgbe_down(adapter);
4245 ixgbe_free_irq(adapter);
4246 ixgbe_free_all_tx_resources(adapter);
4247 ixgbe_free_all_rx_resources(adapter);
4248 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00004249 ixgbe_clear_interrupt_scheme(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004250
4251#ifdef CONFIG_PM
4252 retval = pci_save_state(pdev);
4253 if (retval)
4254 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004255
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004256#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004257 if (wufc) {
4258 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004259
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004260 /* turn on all-multi mode if wake on multicast is enabled */
4261 if (wufc & IXGBE_WUFC_MC) {
4262 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4263 fctrl |= IXGBE_FCTRL_MPE;
4264 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4265 }
4266
4267 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4268 ctrl |= IXGBE_CTRL_GIO_DIS;
4269 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4270
4271 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4272 } else {
4273 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4274 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4275 }
4276
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004277 if (wufc && hw->mac.type == ixgbe_mac_82599EB)
4278 pci_wake_from_d3(pdev, true);
4279 else
4280 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004281
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004282 *enable_wake = !!wufc;
4283
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004284 ixgbe_release_hw_control(adapter);
4285
4286 pci_disable_device(pdev);
4287
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004288 return 0;
4289}
4290
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004291#ifdef CONFIG_PM
4292static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4293{
4294 int retval;
4295 bool wake;
4296
4297 retval = __ixgbe_shutdown(pdev, &wake);
4298 if (retval)
4299 return retval;
4300
4301 if (wake) {
4302 pci_prepare_to_sleep(pdev);
4303 } else {
4304 pci_wake_from_d3(pdev, false);
4305 pci_set_power_state(pdev, PCI_D3hot);
4306 }
4307
4308 return 0;
4309}
4310#endif /* CONFIG_PM */
4311
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004312static void ixgbe_shutdown(struct pci_dev *pdev)
4313{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004314 bool wake;
4315
4316 __ixgbe_shutdown(pdev, &wake);
4317
4318 if (system_state == SYSTEM_POWER_OFF) {
4319 pci_wake_from_d3(pdev, wake);
4320 pci_set_power_state(pdev, PCI_D3hot);
4321 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004322}
4323
4324/**
Auke Kok9a799d72007-09-15 14:07:45 -07004325 * ixgbe_update_stats - Update the board statistics counters.
4326 * @adapter: board private structure
4327 **/
4328void ixgbe_update_stats(struct ixgbe_adapter *adapter)
4329{
4330 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004331 u64 total_mpc = 0;
4332 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004333
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004334 if (hw->mac.type == ixgbe_mac_82599EB) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004335 u64 rsc_count = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004336 for (i = 0; i < 16; i++)
4337 adapter->hw_rx_no_dma_resources +=
4338 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Alexander Duyckf8212f92009-04-27 22:42:37 +00004339 for (i = 0; i < adapter->num_rx_queues; i++)
4340 rsc_count += adapter->rx_ring[i].rsc_count;
4341 adapter->rsc_count = rsc_count;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004342 }
4343
Auke Kok9a799d72007-09-15 14:07:45 -07004344 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004345 for (i = 0; i < 8; i++) {
4346 /* for packet buffers not used, the register should read 0 */
4347 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
4348 missed_rx += mpc;
4349 adapter->stats.mpc[i] += mpc;
4350 total_mpc += adapter->stats.mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004351 if (hw->mac.type == ixgbe_mac_82598EB)
4352 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004353 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
4354 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
4355 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
4356 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004357 if (hw->mac.type == ixgbe_mac_82599EB) {
4358 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4359 IXGBE_PXONRXCNT(i));
4360 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4361 IXGBE_PXOFFRXCNT(i));
4362 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004363 } else {
4364 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4365 IXGBE_PXONRXC(i));
4366 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4367 IXGBE_PXOFFRXC(i));
4368 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004369 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
4370 IXGBE_PXONTXC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004371 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004372 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004373 }
4374 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
4375 /* work around hardware counting issue */
4376 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07004377
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004378 /* 82598 hardware only has a 32 bit counter in the high register */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004379 if (hw->mac.type == ixgbe_mac_82599EB) {
4380 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
4381 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
4382 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
4383 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
4384 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
4385 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
4386 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
4387 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004388 adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
4389 adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00004390#ifdef IXGBE_FCOE
4391 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
4392 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
4393 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
4394 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
4395 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
4396 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
4397#endif /* IXGBE_FCOE */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004398 } else {
4399 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
4400 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
4401 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
4402 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
4403 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
4404 }
Auke Kok9a799d72007-09-15 14:07:45 -07004405 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
4406 adapter->stats.bprc += bprc;
4407 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004408 if (hw->mac.type == ixgbe_mac_82598EB)
4409 adapter->stats.mprc -= bprc;
Auke Kok9a799d72007-09-15 14:07:45 -07004410 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
4411 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
4412 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
4413 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
4414 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
4415 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
4416 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004417 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004418 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
4419 adapter->stats.lxontxc += lxon;
4420 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
4421 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07004422 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4423 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004424 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
4425 /*
4426 * 82598 errata - tx of flow control packets is included in tx counters
4427 */
4428 xon_off_tot = lxon + lxoff;
4429 adapter->stats.gptc -= xon_off_tot;
4430 adapter->stats.mptc -= xon_off_tot;
4431 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07004432 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4433 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
4434 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07004435 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
4436 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004437 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004438 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
4439 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
4440 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
4441 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
4442 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004443 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
4444
4445 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07004446 adapter->net_stats.multicast = adapter->stats.mprc;
4447
4448 /* Rx Errors */
4449 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004450 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07004451 adapter->net_stats.rx_dropped = 0;
4452 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
4453 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004454 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07004455}
4456
4457/**
4458 * ixgbe_watchdog - Timer Call-back
4459 * @data: pointer to adapter cast into an unsigned long
4460 **/
4461static void ixgbe_watchdog(unsigned long data)
4462{
4463 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004464 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004465 u64 eics = 0;
4466 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004467
Alexander Duyckfe49f042009-06-04 16:00:09 +00004468 /*
4469 * Do the watchdog outside of interrupt context due to the lovely
4470 * delays that some of the newer hardware requires
4471 */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004472
Alexander Duyckfe49f042009-06-04 16:00:09 +00004473 if (test_bit(__IXGBE_DOWN, &adapter->state))
4474 goto watchdog_short_circuit;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004475
Alexander Duyckfe49f042009-06-04 16:00:09 +00004476 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
4477 /*
4478 * for legacy and MSI interrupts don't set any bits
4479 * that are enabled for EIAM, because this operation
4480 * would set *both* EIMS and EICS for any bit in EIAM
4481 */
4482 IXGBE_WRITE_REG(hw, IXGBE_EICS,
4483 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
4484 goto watchdog_reschedule;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004485 }
4486
Alexander Duyckfe49f042009-06-04 16:00:09 +00004487 /* get one bit for every active tx/rx interrupt vector */
4488 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
4489 struct ixgbe_q_vector *qv = adapter->q_vector[i];
4490 if (qv->rxr_count || qv->txr_count)
4491 eics |= ((u64)1 << i);
4492 }
4493
4494 /* Cause software interrupt to ensure rx rings are cleaned */
4495 ixgbe_irq_rearm_queues(adapter, eics);
4496
4497watchdog_reschedule:
4498 /* Reset the timer */
4499 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
4500
4501watchdog_short_circuit:
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004502 schedule_work(&adapter->watchdog_task);
4503}
4504
4505/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004506 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
4507 * @work: pointer to work_struct containing our data
4508 **/
4509static void ixgbe_multispeed_fiber_task(struct work_struct *work)
4510{
4511 struct ixgbe_adapter *adapter = container_of(work,
4512 struct ixgbe_adapter,
4513 multispeed_fiber_task);
4514 struct ixgbe_hw *hw = &adapter->hw;
4515 u32 autoneg;
4516
4517 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
Mallikarjuna R Chilakalaa1f25322009-06-30 11:44:36 +00004518 autoneg = hw->phy.autoneg_advertised;
4519 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004520 hw->mac.ops.get_link_capabilities(hw, &autoneg,
4521 &hw->mac.autoneg);
4522 if (hw->mac.ops.setup_link_speed)
4523 hw->mac.ops.setup_link_speed(hw, autoneg, true, true);
4524 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4525 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
4526}
4527
4528/**
4529 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
4530 * @work: pointer to work_struct containing our data
4531 **/
4532static void ixgbe_sfp_config_module_task(struct work_struct *work)
4533{
4534 struct ixgbe_adapter *adapter = container_of(work,
4535 struct ixgbe_adapter,
4536 sfp_config_module_task);
4537 struct ixgbe_hw *hw = &adapter->hw;
4538 u32 err;
4539
4540 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004541
4542 /* Time for electrical oscillations to settle down */
4543 msleep(100);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004544 err = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004545
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004546 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00004547 dev_err(&adapter->pdev->dev, "failed to initialize because "
4548 "an unsupported SFP+ module type was detected.\n"
4549 "Reload the driver after installing a supported "
4550 "module.\n");
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004551 unregister_netdev(adapter->netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004552 return;
4553 }
4554 hw->mac.ops.setup_sfp(hw);
4555
Tony Breeds8d1c3c02009-04-09 22:29:10 +00004556 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004557 /* This will also work for DA Twinax connections */
4558 schedule_work(&adapter->multispeed_fiber_task);
4559 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
4560}
4561
4562/**
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004563 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
4564 * @work: pointer to work_struct containing our data
4565 **/
4566static void ixgbe_fdir_reinit_task(struct work_struct *work)
4567{
4568 struct ixgbe_adapter *adapter = container_of(work,
4569 struct ixgbe_adapter,
4570 fdir_reinit_task);
4571 struct ixgbe_hw *hw = &adapter->hw;
4572 int i;
4573
4574 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
4575 for (i = 0; i < adapter->num_tx_queues; i++)
4576 set_bit(__IXGBE_FDIR_INIT_DONE,
4577 &(adapter->tx_ring[i].reinit_state));
4578 } else {
4579 DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, "
4580 "ignored adding FDIR ATR filters \n");
4581 }
4582 /* Done FDIR Re-initialization, enable transmits */
4583 netif_tx_start_all_queues(adapter->netdev);
4584}
4585
4586/**
Alexander Duyck69888672008-09-11 20:05:39 -07004587 * ixgbe_watchdog_task - worker thread to bring link up
4588 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004589 **/
4590static void ixgbe_watchdog_task(struct work_struct *work)
4591{
4592 struct ixgbe_adapter *adapter = container_of(work,
4593 struct ixgbe_adapter,
4594 watchdog_task);
4595 struct net_device *netdev = adapter->netdev;
4596 struct ixgbe_hw *hw = &adapter->hw;
4597 u32 link_speed = adapter->link_speed;
4598 bool link_up = adapter->link_up;
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004599 int i;
4600 struct ixgbe_ring *tx_ring;
4601 int some_tx_pending = 0;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004602
4603 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
4604
4605 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4606 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004607 if (link_up) {
4608#ifdef CONFIG_DCB
4609 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4610 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004611 hw->mac.ops.fc_enable(hw, i);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004612 } else {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004613 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004614 }
4615#else
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004616 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004617#endif
4618 }
4619
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004620 if (link_up ||
4621 time_after(jiffies, (adapter->link_check_timeout +
4622 IXGBE_TRY_LINK_TIMEOUT))) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004623 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004624 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004625 }
4626 adapter->link_up = link_up;
4627 adapter->link_speed = link_speed;
4628 }
Auke Kok9a799d72007-09-15 14:07:45 -07004629
4630 if (link_up) {
4631 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004632 bool flow_rx, flow_tx;
4633
4634 if (hw->mac.type == ixgbe_mac_82599EB) {
4635 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4636 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
4637 flow_rx = (mflcn & IXGBE_MFLCN_RFCE);
4638 flow_tx = (fccfg & IXGBE_FCCFG_TFCE_802_3X);
4639 } else {
4640 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4641 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
4642 flow_rx = (frctl & IXGBE_FCTRL_RFCE);
4643 flow_tx = (rmcs & IXGBE_RMCS_TFCE_802_3X);
4644 }
4645
Jeff Kirshera46e5342008-11-27 00:22:21 -08004646 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
4647 "Flow Control: %s\n",
4648 netdev->name,
4649 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
4650 "10 Gbps" :
4651 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
4652 "1 Gbps" : "unknown speed")),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004653 ((flow_rx && flow_tx) ? "RX/TX" :
4654 (flow_rx ? "RX" :
4655 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07004656
4657 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004658 } else {
4659 /* Force detection of hung controller */
4660 adapter->detect_tx_hung = true;
4661 }
4662 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004663 adapter->link_up = false;
4664 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004665 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08004666 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
4667 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07004668 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004669 }
4670 }
4671
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004672 if (!netif_carrier_ok(netdev)) {
4673 for (i = 0; i < adapter->num_tx_queues; i++) {
4674 tx_ring = &adapter->tx_ring[i];
4675 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
4676 some_tx_pending = 1;
4677 break;
4678 }
4679 }
4680
4681 if (some_tx_pending) {
4682 /* We've lost link, so the controller stops DMA,
4683 * but we've got queued Tx work that's never going
4684 * to get done, so reset controller to flush Tx.
4685 * (Do the reset outside of interrupt context).
4686 */
4687 schedule_work(&adapter->reset_task);
4688 }
4689 }
4690
Auke Kok9a799d72007-09-15 14:07:45 -07004691 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004692 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07004693}
4694
Auke Kok9a799d72007-09-15 14:07:45 -07004695static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004696 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
4697 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004698{
4699 struct ixgbe_adv_tx_context_desc *context_desc;
4700 unsigned int i;
4701 int err;
4702 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004703 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
4704 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07004705
4706 if (skb_is_gso(skb)) {
4707 if (skb_header_cloned(skb)) {
4708 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4709 if (err)
4710 return err;
4711 }
4712 l4len = tcp_hdrlen(skb);
4713 *hdr_len += l4len;
4714
Al Viro8327d002007-12-10 18:54:12 +00004715 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004716 struct iphdr *iph = ip_hdr(skb);
4717 iph->tot_len = 0;
4718 iph->check = 0;
4719 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004720 iph->daddr, 0,
4721 IPPROTO_TCP,
4722 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004723 adapter->hw_tso_ctxt++;
4724 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
4725 ipv6_hdr(skb)->payload_len = 0;
4726 tcp_hdr(skb)->check =
4727 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004728 &ipv6_hdr(skb)->daddr,
4729 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004730 adapter->hw_tso6_ctxt++;
4731 }
4732
4733 i = tx_ring->next_to_use;
4734
4735 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4736 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4737
4738 /* VLAN MACLEN IPLEN */
4739 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4740 vlan_macip_lens |=
4741 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4742 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004743 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004744 *hdr_len += skb_network_offset(skb);
4745 vlan_macip_lens |=
4746 (skb_transport_header(skb) - skb_network_header(skb));
4747 *hdr_len +=
4748 (skb_transport_header(skb) - skb_network_header(skb));
4749 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4750 context_desc->seqnum_seed = 0;
4751
4752 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004753 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004754 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004755
Al Viro8327d002007-12-10 18:54:12 +00004756 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004757 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4758 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
4759 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4760
4761 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004762 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07004763 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
4764 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004765 /* use index 1 for TSO */
4766 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004767 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4768
4769 tx_buffer_info->time_stamp = jiffies;
4770 tx_buffer_info->next_to_watch = i;
4771
4772 i++;
4773 if (i == tx_ring->count)
4774 i = 0;
4775 tx_ring->next_to_use = i;
4776
4777 return true;
4778 }
4779 return false;
4780}
4781
4782static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004783 struct ixgbe_ring *tx_ring,
4784 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07004785{
4786 struct ixgbe_adv_tx_context_desc *context_desc;
4787 unsigned int i;
4788 struct ixgbe_tx_buffer *tx_buffer_info;
4789 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4790
4791 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4792 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4793 i = tx_ring->next_to_use;
4794 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4795 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4796
4797 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4798 vlan_macip_lens |=
4799 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4800 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004801 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004802 if (skb->ip_summed == CHECKSUM_PARTIAL)
4803 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004804 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07004805
4806 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4807 context_desc->seqnum_seed = 0;
4808
4809 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004810 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004811
4812 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08004813 switch (skb->protocol) {
Harvey Harrison09640e632009-02-01 00:45:17 -08004814 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07004815 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08004816 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4817 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004818 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004819 else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
4820 type_tucmd_mlhl |=
4821 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004822 break;
Harvey Harrison09640e632009-02-01 00:45:17 -08004823 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08004824 /* XXX what about other V6 headers?? */
4825 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4826 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004827 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004828 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
4829 type_tucmd_mlhl |=
4830 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004831 break;
Auke Kok41825d72008-02-12 15:20:33 -08004832 default:
4833 if (unlikely(net_ratelimit())) {
4834 DPRINTK(PROBE, WARNING,
4835 "partial checksum but proto=%x!\n",
4836 skb->protocol);
4837 }
4838 break;
4839 }
Auke Kok9a799d72007-09-15 14:07:45 -07004840 }
4841
4842 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004843 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07004844 context_desc->mss_l4len_idx = 0;
4845
4846 tx_buffer_info->time_stamp = jiffies;
4847 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004848
Auke Kok9a799d72007-09-15 14:07:45 -07004849 adapter->hw_csum_tx_good++;
4850 i++;
4851 if (i == tx_ring->count)
4852 i = 0;
4853 tx_ring->next_to_use = i;
4854
4855 return true;
4856 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004857
Auke Kok9a799d72007-09-15 14:07:45 -07004858 return false;
4859}
4860
4861static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004862 struct ixgbe_ring *tx_ring,
Yi Zoueacd73f2009-05-13 13:11:06 +00004863 struct sk_buff *skb, u32 tx_flags,
4864 unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07004865{
4866 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00004867 unsigned int len;
4868 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07004869 unsigned int offset = 0, size, count = 0, i;
4870 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
4871 unsigned int f;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004872 dma_addr_t *map;
Auke Kok9a799d72007-09-15 14:07:45 -07004873
4874 i = tx_ring->next_to_use;
4875
Alexander Duyck44df32c2009-03-31 21:34:23 +00004876 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
4877 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
4878 return 0;
4879 }
4880
4881 map = skb_shinfo(skb)->dma_maps;
4882
Yi Zoueacd73f2009-05-13 13:11:06 +00004883 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
4884 /* excluding fcoe_crc_eof for FCoE */
4885 total -= sizeof(struct fcoe_crc_eof);
4886
4887 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07004888 while (len) {
4889 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4890 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4891
4892 tx_buffer_info->length = size;
Eric Dumazet042a53a2009-06-05 04:04:16 +00004893 tx_buffer_info->dma = skb_shinfo(skb)->dma_head + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004894 tx_buffer_info->time_stamp = jiffies;
4895 tx_buffer_info->next_to_watch = i;
4896
4897 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00004898 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07004899 offset += size;
4900 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004901
4902 if (len) {
4903 i++;
4904 if (i == tx_ring->count)
4905 i = 0;
4906 }
Auke Kok9a799d72007-09-15 14:07:45 -07004907 }
4908
4909 for (f = 0; f < nr_frags; f++) {
4910 struct skb_frag_struct *frag;
4911
4912 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00004913 len = min((unsigned int)frag->size, total);
Alexander Duyck44df32c2009-03-31 21:34:23 +00004914 offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004915
4916 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00004917 i++;
4918 if (i == tx_ring->count)
4919 i = 0;
4920
Auke Kok9a799d72007-09-15 14:07:45 -07004921 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4922 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4923
4924 tx_buffer_info->length = size;
Eric Dumazet042a53a2009-06-05 04:04:16 +00004925 tx_buffer_info->dma = map[f] + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004926 tx_buffer_info->time_stamp = jiffies;
4927 tx_buffer_info->next_to_watch = i;
4928
4929 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00004930 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07004931 offset += size;
4932 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07004933 }
Yi Zoueacd73f2009-05-13 13:11:06 +00004934 if (total == 0)
4935 break;
Auke Kok9a799d72007-09-15 14:07:45 -07004936 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00004937
Auke Kok9a799d72007-09-15 14:07:45 -07004938 tx_ring->tx_buffer_info[i].skb = skb;
4939 tx_ring->tx_buffer_info[first].next_to_watch = i;
4940
4941 return count;
4942}
4943
4944static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004945 struct ixgbe_ring *tx_ring,
4946 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004947{
4948 union ixgbe_adv_tx_desc *tx_desc = NULL;
4949 struct ixgbe_tx_buffer *tx_buffer_info;
4950 u32 olinfo_status = 0, cmd_type_len = 0;
4951 unsigned int i;
4952 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
4953
4954 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
4955
4956 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
4957
4958 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4959 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
4960
4961 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
4962 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4963
4964 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004965 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004966
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004967 /* use index 1 context for tso */
4968 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004969 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
4970 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004971 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004972
4973 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
4974 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004975 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004976
Yi Zoueacd73f2009-05-13 13:11:06 +00004977 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
4978 olinfo_status |= IXGBE_ADVTXD_CC;
4979 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
4980 if (tx_flags & IXGBE_TX_FLAGS_FSO)
4981 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4982 }
4983
Auke Kok9a799d72007-09-15 14:07:45 -07004984 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
4985
4986 i = tx_ring->next_to_use;
4987 while (count--) {
4988 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4989 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
4990 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
4991 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004992 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07004993 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07004994 i++;
4995 if (i == tx_ring->count)
4996 i = 0;
4997 }
4998
4999 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
5000
5001 /*
5002 * Force memory writes to complete before letting h/w
5003 * know there are new descriptors to fetch. (Only
5004 * applicable for weak-ordered memory model archs,
5005 * such as IA-64).
5006 */
5007 wmb();
5008
5009 tx_ring->next_to_use = i;
5010 writel(i, adapter->hw.hw_addr + tx_ring->tail);
5011}
5012
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005013static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
5014 int queue, u32 tx_flags)
5015{
5016 /* Right now, we support IPv4 only */
5017 struct ixgbe_atr_input atr_input;
5018 struct tcphdr *th;
5019 struct udphdr *uh;
5020 struct iphdr *iph = ip_hdr(skb);
5021 struct ethhdr *eth = (struct ethhdr *)skb->data;
5022 u16 vlan_id, src_port, dst_port, flex_bytes;
5023 u32 src_ipv4_addr, dst_ipv4_addr;
5024 u8 l4type = 0;
5025
5026 /* check if we're UDP or TCP */
5027 if (iph->protocol == IPPROTO_TCP) {
5028 th = tcp_hdr(skb);
5029 src_port = th->source;
5030 dst_port = th->dest;
5031 l4type |= IXGBE_ATR_L4TYPE_TCP;
5032 /* l4type IPv4 type is 0, no need to assign */
5033 } else if(iph->protocol == IPPROTO_UDP) {
5034 uh = udp_hdr(skb);
5035 src_port = uh->source;
5036 dst_port = uh->dest;
5037 l4type |= IXGBE_ATR_L4TYPE_UDP;
5038 /* l4type IPv4 type is 0, no need to assign */
5039 } else {
5040 /* Unsupported L4 header, just bail here */
5041 return;
5042 }
5043
5044 memset(&atr_input, 0, sizeof(struct ixgbe_atr_input));
5045
5046 vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >>
5047 IXGBE_TX_FLAGS_VLAN_SHIFT;
5048 src_ipv4_addr = iph->saddr;
5049 dst_ipv4_addr = iph->daddr;
5050 flex_bytes = eth->h_proto;
5051
5052 ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
5053 ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
5054 ixgbe_atr_set_dst_port_82599(&atr_input, src_port);
5055 ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes);
5056 ixgbe_atr_set_l4type_82599(&atr_input, l4type);
5057 /* src and dst are inverted, think how the receiver sees them */
5058 ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr);
5059 ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr);
5060
5061 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
5062 ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue);
5063}
5064
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005065static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005066 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005067{
5068 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5069
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005070 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005071 /* Herbert's original patch had:
5072 * smp_mb__after_netif_stop_queue();
5073 * but since that doesn't exist yet, just open code it. */
5074 smp_mb();
5075
5076 /* We need to check again in a case another CPU has just
5077 * made room available. */
5078 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
5079 return -EBUSY;
5080
5081 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07005082 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005083 ++adapter->restart_queue;
5084 return 0;
5085}
5086
5087static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005088 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005089{
5090 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
5091 return 0;
5092 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
5093}
5094
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005095static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
5096{
5097 struct ixgbe_adapter *adapter = netdev_priv(dev);
5098
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005099 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
5100 return smp_processor_id();
5101
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005102 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5103 return 0; /* All traffic should default to class 0 */
5104
5105 return skb_tx_hash(dev, skb);
5106}
5107
Auke Kok9a799d72007-09-15 14:07:45 -07005108static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
5109{
5110 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5111 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07005112 unsigned int first;
5113 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005114 u8 hdr_len = 0;
5115 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07005116 int count = 0;
5117 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005118
Wu Fengguang95615d92009-04-14 21:53:48 -07005119 r_idx = skb->queue_mapping;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005120 tx_ring = &adapter->tx_ring[r_idx];
Auke Kok9a799d72007-09-15 14:07:45 -07005121
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005122 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
5123 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005124 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5125 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
5126 tx_flags |= (skb->queue_mapping << 13);
5127 }
5128 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5129 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5130 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5131 tx_flags |= (skb->queue_mapping << 13);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005132 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5133 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07005134 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005135
5136 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
5137 (skb->protocol == htons(ETH_P_FCOE)))
5138 tx_flags |= IXGBE_TX_FLAGS_FCOE;
5139
5140 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005141 if (skb_is_gso(skb) ||
5142 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00005143 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
5144 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07005145 count++;
5146
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005147 count += TXD_USE_COUNT(skb_headlen(skb));
5148 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07005149 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
5150
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005151 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07005152 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07005153 return NETDEV_TX_BUSY;
5154 }
Auke Kok9a799d72007-09-15 14:07:45 -07005155
Auke Kok9a799d72007-09-15 14:07:45 -07005156 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00005157 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5158#ifdef IXGBE_FCOE
5159 /* setup tx offload for FCoE */
5160 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5161 if (tso < 0) {
5162 dev_kfree_skb_any(skb);
5163 return NETDEV_TX_OK;
5164 }
5165 if (tso)
5166 tx_flags |= IXGBE_TX_FLAGS_FSO;
5167#endif /* IXGBE_FCOE */
5168 } else {
5169 if (skb->protocol == htons(ETH_P_IP))
5170 tx_flags |= IXGBE_TX_FLAGS_IPV4;
5171 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5172 if (tso < 0) {
5173 dev_kfree_skb_any(skb);
5174 return NETDEV_TX_OK;
5175 }
5176
5177 if (tso)
5178 tx_flags |= IXGBE_TX_FLAGS_TSO;
5179 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
5180 (skb->ip_summed == CHECKSUM_PARTIAL))
5181 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005182 }
5183
Yi Zoueacd73f2009-05-13 13:11:06 +00005184 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005185 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005186 /* add the ATR filter if ATR is on */
5187 if (tx_ring->atr_sample_rate) {
5188 ++tx_ring->atr_count;
5189 if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) &&
5190 test_bit(__IXGBE_FDIR_INIT_DONE,
5191 &tx_ring->reinit_state)) {
5192 ixgbe_atr(adapter, skb, tx_ring->queue_index,
5193 tx_flags);
5194 tx_ring->atr_count = 0;
5195 }
5196 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00005197 ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
5198 hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005199 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07005200
Alexander Duyck44df32c2009-03-31 21:34:23 +00005201 } else {
5202 dev_kfree_skb_any(skb);
5203 tx_ring->tx_buffer_info[first].time_stamp = 0;
5204 tx_ring->next_to_use = first;
5205 }
Auke Kok9a799d72007-09-15 14:07:45 -07005206
5207 return NETDEV_TX_OK;
5208}
5209
5210/**
5211 * ixgbe_get_stats - Get System Network Statistics
5212 * @netdev: network interface device structure
5213 *
5214 * Returns the address of the device statistics structure.
5215 * The statistics are actually updated from the timer callback.
5216 **/
5217static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
5218{
5219 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5220
5221 /* only return the current stats */
5222 return &adapter->net_stats;
5223}
5224
5225/**
5226 * ixgbe_set_mac - Change the Ethernet Address of the NIC
5227 * @netdev: network interface device structure
5228 * @p: pointer to an address structure
5229 *
5230 * Returns 0 on success, negative on failure
5231 **/
5232static int ixgbe_set_mac(struct net_device *netdev, void *p)
5233{
5234 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005235 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005236 struct sockaddr *addr = p;
5237
5238 if (!is_valid_ether_addr(addr->sa_data))
5239 return -EADDRNOTAVAIL;
5240
5241 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005242 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07005243
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005244 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07005245
5246 return 0;
5247}
5248
Ben Hutchings6b73e102009-04-29 08:08:58 +00005249static int
5250ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
5251{
5252 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5253 struct ixgbe_hw *hw = &adapter->hw;
5254 u16 value;
5255 int rc;
5256
5257 if (prtad != hw->phy.mdio.prtad)
5258 return -EINVAL;
5259 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
5260 if (!rc)
5261 rc = value;
5262 return rc;
5263}
5264
5265static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
5266 u16 addr, u16 value)
5267{
5268 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5269 struct ixgbe_hw *hw = &adapter->hw;
5270
5271 if (prtad != hw->phy.mdio.prtad)
5272 return -EINVAL;
5273 return hw->phy.ops.write_reg(hw, addr, devad, value);
5274}
5275
5276static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
5277{
5278 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5279
5280 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
5281}
5282
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005283/**
5284 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00005285 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005286 * @netdev: network interface device structure
5287 *
5288 * Returns non-zero on failure
5289 **/
5290static int ixgbe_add_sanmac_netdev(struct net_device *dev)
5291{
5292 int err = 0;
5293 struct ixgbe_adapter *adapter = netdev_priv(dev);
5294 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5295
5296 if (is_valid_ether_addr(mac->san_addr)) {
5297 rtnl_lock();
5298 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5299 rtnl_unlock();
5300 }
5301 return err;
5302}
5303
5304/**
5305 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00005306 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005307 * @netdev: network interface device structure
5308 *
5309 * Returns non-zero on failure
5310 **/
5311static int ixgbe_del_sanmac_netdev(struct net_device *dev)
5312{
5313 int err = 0;
5314 struct ixgbe_adapter *adapter = netdev_priv(dev);
5315 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5316
5317 if (is_valid_ether_addr(mac->san_addr)) {
5318 rtnl_lock();
5319 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5320 rtnl_unlock();
5321 }
5322 return err;
5323}
5324
Auke Kok9a799d72007-09-15 14:07:45 -07005325#ifdef CONFIG_NET_POLL_CONTROLLER
5326/*
5327 * Polling 'interrupt' - used by things like netconsole to send skbs
5328 * without having to re-enable interrupts. It's not called while
5329 * the interrupt routine is executing.
5330 */
5331static void ixgbe_netpoll(struct net_device *netdev)
5332{
5333 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5334
5335 disable_irq(adapter->pdev->irq);
5336 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
5337 ixgbe_intr(adapter->pdev->irq, netdev);
5338 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
5339 enable_irq(adapter->pdev->irq);
5340}
5341#endif
5342
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005343static const struct net_device_ops ixgbe_netdev_ops = {
5344 .ndo_open = ixgbe_open,
5345 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005346 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005347 .ndo_select_queue = ixgbe_select_queue,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005348 .ndo_get_stats = ixgbe_get_stats,
Chris Leeche90d4002009-03-10 16:00:24 +00005349 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005350 .ndo_set_multicast_list = ixgbe_set_rx_mode,
5351 .ndo_validate_addr = eth_validate_addr,
5352 .ndo_set_mac_address = ixgbe_set_mac,
5353 .ndo_change_mtu = ixgbe_change_mtu,
5354 .ndo_tx_timeout = ixgbe_tx_timeout,
5355 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
5356 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
5357 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00005358 .ndo_do_ioctl = ixgbe_ioctl,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005359#ifdef CONFIG_NET_POLL_CONTROLLER
5360 .ndo_poll_controller = ixgbe_netpoll,
5361#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005362#ifdef IXGBE_FCOE
5363 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
5364 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
5365#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005366};
5367
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005368/**
Auke Kok9a799d72007-09-15 14:07:45 -07005369 * ixgbe_probe - Device Initialization Routine
5370 * @pdev: PCI device information struct
5371 * @ent: entry in ixgbe_pci_tbl
5372 *
5373 * Returns 0 on success, negative on failure
5374 *
5375 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
5376 * The OS initialization, configuring of the adapter private structure,
5377 * and a hardware reset occur.
5378 **/
5379static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005380 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07005381{
5382 struct net_device *netdev;
5383 struct ixgbe_adapter *adapter = NULL;
5384 struct ixgbe_hw *hw;
5385 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07005386 static int cards_found;
5387 int i, err, pci_using_dac;
Yi Zoueacd73f2009-05-13 13:11:06 +00005388#ifdef IXGBE_FCOE
5389 u16 device_caps;
5390#endif
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005391 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07005392
gouji-new9ce77662009-05-06 10:44:45 +00005393 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005394 if (err)
5395 return err;
5396
Yang Hongyang6a355282009-04-06 19:01:13 -07005397 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
5398 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07005399 pci_using_dac = 1;
5400 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07005401 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005402 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -07005403 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005404 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005405 dev_err(&pdev->dev, "No usable DMA "
5406 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005407 goto err_dma;
5408 }
5409 }
5410 pci_using_dac = 0;
5411 }
5412
gouji-new9ce77662009-05-06 10:44:45 +00005413 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
5414 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07005415 if (err) {
gouji-new9ce77662009-05-06 10:44:45 +00005416 dev_err(&pdev->dev,
5417 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07005418 goto err_pci_reg;
5419 }
5420
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005421 err = pci_enable_pcie_error_reporting(pdev);
5422 if (err) {
5423 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
5424 "0x%x\n", err);
5425 /* non-fatal, continue */
5426 }
5427
Auke Kok9a799d72007-09-15 14:07:45 -07005428 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07005429 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005430
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005431 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07005432 if (!netdev) {
5433 err = -ENOMEM;
5434 goto err_alloc_etherdev;
5435 }
5436
Auke Kok9a799d72007-09-15 14:07:45 -07005437 SET_NETDEV_DEV(netdev, &pdev->dev);
5438
5439 pci_set_drvdata(pdev, netdev);
5440 adapter = netdev_priv(netdev);
5441
5442 adapter->netdev = netdev;
5443 adapter->pdev = pdev;
5444 hw = &adapter->hw;
5445 hw->back = adapter;
5446 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
5447
Jeff Kirsher05857982008-09-11 19:57:00 -07005448 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
5449 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07005450 if (!hw->hw_addr) {
5451 err = -EIO;
5452 goto err_ioremap;
5453 }
5454
5455 for (i = 1; i <= 5; i++) {
5456 if (pci_resource_len(pdev, i) == 0)
5457 continue;
5458 }
5459
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005460 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07005461 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005462 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07005463 strcpy(netdev->name, pci_name(pdev));
5464
Auke Kok9a799d72007-09-15 14:07:45 -07005465 adapter->bd_number = cards_found;
5466
Auke Kok9a799d72007-09-15 14:07:45 -07005467 /* Setup hw api */
5468 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005469 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07005470
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005471 /* EEPROM */
5472 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
5473 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
5474 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
5475 if (!(eec & (1 << 8)))
5476 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
5477
5478 /* PHY */
5479 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08005480 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00005481 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
5482 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
5483 hw->phy.mdio.mmds = 0;
5484 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
5485 hw->phy.mdio.dev = netdev;
5486 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
5487 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08005488
5489 /* set up this timer and work struct before calling get_invariants
5490 * which might start the timer
5491 */
5492 init_timer(&adapter->sfp_timer);
5493 adapter->sfp_timer.function = &ixgbe_sfp_timer;
5494 adapter->sfp_timer.data = (unsigned long) adapter;
5495
5496 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005497
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005498 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
5499 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
5500
5501 /* a new SFP+ module arrival, called from GPI SDP2 context */
5502 INIT_WORK(&adapter->sfp_config_module_task,
5503 ixgbe_sfp_config_module_task);
5504
Don Skidmore8ca783a2009-05-26 20:40:47 -07005505 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005506
5507 /* setup the private structure */
5508 err = ixgbe_sw_init(adapter);
5509 if (err)
5510 goto err_sw_init;
5511
Don Skidmorebf069c92009-05-07 10:39:54 +00005512 /*
5513 * If there is a fan on this device and it has failed log the
5514 * failure.
5515 */
5516 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5517 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5518 if (esdp & IXGBE_ESDP_SDP1)
5519 DPRINTK(PROBE, CRIT,
5520 "Fan has stopped, replace the adapter\n");
5521 }
5522
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005523 /* reset_hw fills in the perm_addr as well */
5524 err = hw->mac.ops.reset_hw(hw);
Don Skidmore8ca783a2009-05-26 20:40:47 -07005525 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
5526 hw->mac.type == ixgbe_mac_82598EB) {
5527 /*
5528 * Start a kernel thread to watch for a module to arrive.
5529 * Only do this for 82598, since 82599 will generate
5530 * interrupts on module arrival.
5531 */
5532 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5533 mod_timer(&adapter->sfp_timer,
5534 round_jiffies(jiffies + (2 * HZ)));
5535 err = 0;
5536 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00005537 dev_err(&adapter->pdev->dev, "failed to initialize because "
5538 "an unsupported SFP+ module type was detected.\n"
5539 "Reload the driver after installing a supported "
5540 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005541 goto err_sw_init;
5542 } else if (err) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005543 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
5544 goto err_sw_init;
5545 }
5546
Auke Kok9a799d72007-09-15 14:07:45 -07005547 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005548 NETIF_F_IP_CSUM |
5549 NETIF_F_HW_VLAN_TX |
5550 NETIF_F_HW_VLAN_RX |
5551 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07005552
Jesse Brandeburge9990a92008-08-26 04:27:24 -07005553 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005554 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07005555 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08005556 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005557
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00005558 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
5559 netdev->features |= NETIF_F_SCTP_CSUM;
5560
Jeff Kirsherad31c402008-06-05 04:05:30 -07005561 netdev->vlan_features |= NETIF_F_TSO;
5562 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07005563 netdev->vlan_features |= NETIF_F_IP_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005564 netdev->vlan_features |= NETIF_F_SG;
5565
Alexander Duyck2f90b862008-11-20 20:52:10 -08005566 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5567 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
5568
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005569#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005570 netdev->dcbnl_ops = &dcbnl_ops;
5571#endif
5572
Yi Zoueacd73f2009-05-13 13:11:06 +00005573#ifdef IXGBE_FCOE
5574 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
5575 if (hw->mac.ops.get_device_caps) {
5576 hw->mac.ops.get_device_caps(hw, &device_caps);
5577 if (!(device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)) {
5578 netdev->features |= NETIF_F_FCOE_CRC;
5579 netdev->features |= NETIF_F_FSO;
Yi Zou332d4a72009-05-13 13:11:53 +00005580 netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005581 DPRINTK(DRV, INFO, "FCoE enabled, "
5582 "disabling Flow Director\n");
5583 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
5584 adapter->flags &=
5585 ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
5586 adapter->atr_sample_rate = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00005587 } else {
5588 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5589 }
5590 }
5591 }
5592#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005593 if (pci_using_dac)
5594 netdev->features |= NETIF_F_HIGHDMA;
5595
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00005596 if (adapter->flags & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00005597 netdev->features |= NETIF_F_LRO;
5598
Auke Kok9a799d72007-09-15 14:07:45 -07005599 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005600 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07005601 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
5602 err = -EIO;
5603 goto err_eeprom;
5604 }
5605
5606 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
5607 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
5608
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005609 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
5610 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005611 err = -EIO;
5612 goto err_eeprom;
5613 }
5614
5615 init_timer(&adapter->watchdog_timer);
5616 adapter->watchdog_timer.function = &ixgbe_watchdog;
5617 adapter->watchdog_timer.data = (unsigned long)adapter;
5618
5619 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005620 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005621
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005622 err = ixgbe_init_interrupt_scheme(adapter);
5623 if (err)
5624 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07005625
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005626 switch (pdev->device) {
5627 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005628 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
5629 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
Peter P Waskiewicz Jrbdf0a552009-06-04 11:09:58 +00005630 /* Enable ACPI wakeup in GRC */
5631 IXGBE_WRITE_REG(hw, IXGBE_GRC,
5632 (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005633 break;
5634 default:
5635 adapter->wol = 0;
5636 break;
5637 }
5638 device_init_wakeup(&adapter->pdev->dev, true);
5639 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
5640
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005641 /* pick up the PCI bus settings for reporting later */
5642 hw->mac.ops.get_bus_info(hw);
5643
Auke Kok9a799d72007-09-15 14:07:45 -07005644 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07005645 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005646 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
5647 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
5648 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
5649 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
5650 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005651 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07005652 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005653 ixgbe_read_pba_num_generic(hw, &part_num);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005654 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
5655 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
5656 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
5657 (part_num >> 8), (part_num & 0xff));
5658 else
5659 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
5660 hw->mac.type, hw->phy.type,
5661 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07005662
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005663 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Auke Kok0c254d82008-02-11 09:25:56 -08005664 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005665 "this card is not sufficient for optimal "
5666 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005667 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005668 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005669 }
5670
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08005671 /* save off EEPROM version number */
5672 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
5673
Auke Kok9a799d72007-09-15 14:07:45 -07005674 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005675 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005676
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005677 if (err == IXGBE_ERR_EEPROM_VERSION) {
5678 /* We are running on a pre-production device, log a warning */
5679 dev_warn(&pdev->dev, "This device is a pre-production "
5680 "adapter/LOM. Please be aware there may be issues "
5681 "associated with your hardware. If you are "
5682 "experiencing problems please contact your Intel or "
5683 "hardware representative who provided you with this "
5684 "hardware.\n");
5685 }
Auke Kok9a799d72007-09-15 14:07:45 -07005686 strcpy(netdev->name, "eth%d");
5687 err = register_netdev(netdev);
5688 if (err)
5689 goto err_register;
5690
Jesse Brandeburg54386462009-04-17 20:44:27 +00005691 /* carrier off reporting is important to ethtool even BEFORE open */
5692 netif_carrier_off(netdev);
5693
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005694 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5695 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5696 INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
5697
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005698#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03005699 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005700 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005701 ixgbe_setup_dca(adapter);
5702 }
5703#endif
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005704 /* add san mac addr to netdev */
5705 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005706
5707 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
5708 cards_found++;
5709 return 0;
5710
5711err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005712 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005713 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005714err_sw_init:
5715err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08005716 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5717 del_timer_sync(&adapter->sfp_timer);
5718 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005719 cancel_work_sync(&adapter->multispeed_fiber_task);
5720 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005721 iounmap(hw->hw_addr);
5722err_ioremap:
5723 free_netdev(netdev);
5724err_alloc_etherdev:
gouji-new9ce77662009-05-06 10:44:45 +00005725 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5726 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005727err_pci_reg:
5728err_dma:
5729 pci_disable_device(pdev);
5730 return err;
5731}
5732
5733/**
5734 * ixgbe_remove - Device Removal Routine
5735 * @pdev: PCI device information struct
5736 *
5737 * ixgbe_remove is called by the PCI subsystem to alert the driver
5738 * that it should release a PCI device. The could be caused by a
5739 * Hot-Plug event, or because the driver is going to be removed from
5740 * memory.
5741 **/
5742static void __devexit ixgbe_remove(struct pci_dev *pdev)
5743{
5744 struct net_device *netdev = pci_get_drvdata(pdev);
5745 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005746 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005747
5748 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08005749 /* clear the module not found bit to make sure the worker won't
5750 * reschedule
5751 */
5752 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07005753 del_timer_sync(&adapter->watchdog_timer);
5754
Donald Skidmorec4900be2008-11-20 21:11:42 -08005755 del_timer_sync(&adapter->sfp_timer);
5756 cancel_work_sync(&adapter->watchdog_task);
5757 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005758 cancel_work_sync(&adapter->multispeed_fiber_task);
5759 cancel_work_sync(&adapter->sfp_config_module_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005760 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5761 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5762 cancel_work_sync(&adapter->fdir_reinit_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005763 flush_scheduled_work();
5764
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005765#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005766 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
5767 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
5768 dca_remove_requester(&pdev->dev);
5769 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
5770 }
5771
5772#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005773#ifdef IXGBE_FCOE
5774 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
5775 ixgbe_cleanup_fcoe(adapter);
5776
5777#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005778
5779 /* remove the added san mac */
5780 ixgbe_del_sanmac_netdev(netdev);
5781
Donald Skidmorec4900be2008-11-20 21:11:42 -08005782 if (netdev->reg_state == NETREG_REGISTERED)
5783 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005784
Alexander Duyck7a921c92009-05-06 10:43:28 +00005785 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005786
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005787 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005788
5789 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00005790 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5791 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005792
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005793 DPRINTK(PROBE, INFO, "complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005794
Auke Kok9a799d72007-09-15 14:07:45 -07005795 free_netdev(netdev);
5796
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005797 err = pci_disable_pcie_error_reporting(pdev);
5798 if (err)
5799 dev_err(&pdev->dev,
5800 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
5801
Auke Kok9a799d72007-09-15 14:07:45 -07005802 pci_disable_device(pdev);
5803}
5804
5805/**
5806 * ixgbe_io_error_detected - called when PCI error is detected
5807 * @pdev: Pointer to PCI device
5808 * @state: The current pci connection state
5809 *
5810 * This function is called after a PCI bus error affecting
5811 * this device has been detected.
5812 */
5813static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005814 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07005815{
5816 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005817 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005818
5819 netif_device_detach(netdev);
5820
Breno Leitao3044b8d2009-05-06 10:44:26 +00005821 if (state == pci_channel_io_perm_failure)
5822 return PCI_ERS_RESULT_DISCONNECT;
5823
Auke Kok9a799d72007-09-15 14:07:45 -07005824 if (netif_running(netdev))
5825 ixgbe_down(adapter);
5826 pci_disable_device(pdev);
5827
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005828 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07005829 return PCI_ERS_RESULT_NEED_RESET;
5830}
5831
5832/**
5833 * ixgbe_io_slot_reset - called after the pci bus has been reset.
5834 * @pdev: Pointer to PCI device
5835 *
5836 * Restart the card from scratch, as if from a cold-boot.
5837 */
5838static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
5839{
5840 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005841 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005842 pci_ers_result_t result;
5843 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005844
gouji-new9ce77662009-05-06 10:44:45 +00005845 if (pci_enable_device_mem(pdev)) {
Auke Kok9a799d72007-09-15 14:07:45 -07005846 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005847 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005848 result = PCI_ERS_RESULT_DISCONNECT;
5849 } else {
5850 pci_set_master(pdev);
5851 pci_restore_state(pdev);
5852
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005853 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005854
5855 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00005856 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005857 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07005858 }
Auke Kok9a799d72007-09-15 14:07:45 -07005859
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005860 err = pci_cleanup_aer_uncorrect_error_status(pdev);
5861 if (err) {
5862 dev_err(&pdev->dev,
5863 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
5864 /* non-fatal, continue */
5865 }
Auke Kok9a799d72007-09-15 14:07:45 -07005866
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005867 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07005868}
5869
5870/**
5871 * ixgbe_io_resume - called when traffic can start flowing again.
5872 * @pdev: Pointer to PCI device
5873 *
5874 * This callback is called when the error recovery driver tells us that
5875 * its OK to resume normal operation.
5876 */
5877static void ixgbe_io_resume(struct pci_dev *pdev)
5878{
5879 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005880 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005881
5882 if (netif_running(netdev)) {
5883 if (ixgbe_up(adapter)) {
5884 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
5885 return;
5886 }
5887 }
5888
5889 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005890}
5891
5892static struct pci_error_handlers ixgbe_err_handler = {
5893 .error_detected = ixgbe_io_error_detected,
5894 .slot_reset = ixgbe_io_slot_reset,
5895 .resume = ixgbe_io_resume,
5896};
5897
5898static struct pci_driver ixgbe_driver = {
5899 .name = ixgbe_driver_name,
5900 .id_table = ixgbe_pci_tbl,
5901 .probe = ixgbe_probe,
5902 .remove = __devexit_p(ixgbe_remove),
5903#ifdef CONFIG_PM
5904 .suspend = ixgbe_suspend,
5905 .resume = ixgbe_resume,
5906#endif
5907 .shutdown = ixgbe_shutdown,
5908 .err_handler = &ixgbe_err_handler
5909};
5910
5911/**
5912 * ixgbe_init_module - Driver Registration Routine
5913 *
5914 * ixgbe_init_module is the first routine called when the driver is
5915 * loaded. All it does is register with the PCI subsystem.
5916 **/
5917static int __init ixgbe_init_module(void)
5918{
5919 int ret;
5920 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
5921 ixgbe_driver_string, ixgbe_driver_version);
5922
5923 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
5924
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005925#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005926 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005927#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005928
Auke Kok9a799d72007-09-15 14:07:45 -07005929 ret = pci_register_driver(&ixgbe_driver);
5930 return ret;
5931}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005932
Auke Kok9a799d72007-09-15 14:07:45 -07005933module_init(ixgbe_init_module);
5934
5935/**
5936 * ixgbe_exit_module - Driver Exit Cleanup Routine
5937 *
5938 * ixgbe_exit_module is called just before the driver is removed
5939 * from memory.
5940 **/
5941static void __exit ixgbe_exit_module(void)
5942{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005943#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005944 dca_unregister_notify(&dca_notifier);
5945#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005946 pci_unregister_driver(&ixgbe_driver);
5947}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005948
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005949#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005950static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005951 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005952{
5953 int ret_val;
5954
5955 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005956 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005957
5958 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
5959}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005960
Alexander Duyckb4533682009-03-31 21:32:42 +00005961#endif /* CONFIG_IXGBE_DCA */
5962#ifdef DEBUG
5963/**
5964 * ixgbe_get_hw_dev_name - return device name string
5965 * used by hardware layer to print debugging information
5966 **/
5967char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
5968{
5969 struct ixgbe_adapter *adapter = hw->back;
5970 return adapter->netdev->name;
5971}
5972
5973#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005974module_exit(ixgbe_exit_module);
5975
5976/* ixgbe_main.c */