blob: 2553173a16c4f09e5cde5893174d9df77c5f74b1 [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 Jrba988982009-05-17 20:58:21 +000051#define DRV_VERSION "2.0.24-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;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700296
297 /* gso_segs is currently only valid for tcp */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800298 segs = skb_shinfo(skb)->gso_segs ?: 1;
299 /* multiply data chunks by size of headers */
300 bytecount = ((segs - 1) * skb_headlen(skb)) +
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700301 skb->len;
302 total_packets += segs;
303 total_bytes += bytecount;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800304 }
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700305
Auke Kok9a799d72007-09-15 14:07:45 -0700306 ixgbe_unmap_and_free_tx_resource(adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700307 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700308
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800309 tx_desc->wb.status = 0;
310
Auke Kok9a799d72007-09-15 14:07:45 -0700311 i++;
312 if (i == tx_ring->count)
313 i = 0;
314 }
315
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800316 eop = tx_ring->tx_buffer_info[i].next_to_watch;
317 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
318 }
319
Auke Kok9a799d72007-09-15 14:07:45 -0700320 tx_ring->next_to_clean = i;
321
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800322#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700323 if (unlikely(count && netif_carrier_ok(netdev) &&
324 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800325 /* Make sure that anybody stopping the queue after this
326 * sees the new next_to_clean.
327 */
328 smp_mb();
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800329 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
330 !test_bit(__IXGBE_DOWN, &adapter->state)) {
331 netif_wake_subqueue(netdev, tx_ring->queue_index);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700332 ++adapter->restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800333 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800334 }
Auke Kok9a799d72007-09-15 14:07:45 -0700335
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700336 if (adapter->detect_tx_hung) {
337 if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
338 /* schedule immediate reset if we believe we hung */
339 DPRINTK(PROBE, INFO,
340 "tx hang %d detected, resetting adapter\n",
341 adapter->tx_timeout_count + 1);
342 ixgbe_tx_timeout(adapter->netdev);
343 }
344 }
Auke Kok9a799d72007-09-15 14:07:45 -0700345
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700346 /* re-arm the interrupt */
Alexander Duyckfe49f042009-06-04 16:00:09 +0000347 if (count >= tx_ring->work_limit)
348 ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -0700349
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700350 tx_ring->total_bytes += total_bytes;
351 tx_ring->total_packets += total_packets;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700352 tx_ring->stats.packets += total_packets;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800353 tx_ring->stats.bytes += total_bytes;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700354 adapter->net_stats.tx_bytes += total_bytes;
355 adapter->net_stats.tx_packets += total_packets;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000356 return (count < tx_ring->work_limit);
Auke Kok9a799d72007-09-15 14:07:45 -0700357}
358
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400359#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800360static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700361 struct ixgbe_ring *rx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800362{
363 u32 rxctrl;
364 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700365 int q = rx_ring - adapter->rx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800366
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700367 if (rx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800368 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000369 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
370 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
371 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
372 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
373 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
374 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
375 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
376 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800377 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
378 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
Don Skidmore15005a32009-01-19 16:54:13 -0800379 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
380 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000381 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800382 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700383 rx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800384 }
385 put_cpu();
386}
387
388static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700389 struct ixgbe_ring *tx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800390{
391 u32 txctrl;
392 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700393 int q = tx_ring - adapter->tx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800394
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700395 if (tx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800396 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000397 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
398 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
399 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
400 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
401 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
402 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
403 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
404 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800405 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
406 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700407 tx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800408 }
409 put_cpu();
410}
411
412static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
413{
414 int i;
415
416 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
417 return;
418
Alexander Duycke35ec122009-05-21 13:07:12 +0000419 /* always use CB2 mode, difference is masked in the CB driver */
420 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
421
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800422 for (i = 0; i < adapter->num_tx_queues; i++) {
423 adapter->tx_ring[i].cpu = -1;
424 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
425 }
426 for (i = 0; i < adapter->num_rx_queues; i++) {
427 adapter->rx_ring[i].cpu = -1;
428 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
429 }
430}
431
432static int __ixgbe_notify_dca(struct device *dev, void *data)
433{
434 struct net_device *netdev = dev_get_drvdata(dev);
435 struct ixgbe_adapter *adapter = netdev_priv(netdev);
436 unsigned long event = *(unsigned long *)data;
437
438 switch (event) {
439 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700440 /* if we're already enabled, don't do it again */
441 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
442 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300443 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700444 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800445 ixgbe_setup_dca(adapter);
446 break;
447 }
448 /* Fall Through since DCA is disabled. */
449 case DCA_PROVIDER_REMOVE:
450 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
451 dca_remove_requester(dev);
452 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
453 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
454 }
455 break;
456 }
457
Denis V. Lunev652f0932008-03-27 14:39:17 +0300458 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800459}
460
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400461#endif /* CONFIG_IXGBE_DCA */
Auke Kok9a799d72007-09-15 14:07:45 -0700462/**
463 * ixgbe_receive_skb - Send a completed packet up the stack
464 * @adapter: board private structure
465 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700466 * @status: hardware indication of status of receive
467 * @rx_ring: rx descriptor ring (for a specific queue) to setup
468 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -0700469 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800470static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700471 struct sk_buff *skb, u8 status,
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000472 struct ixgbe_ring *ring,
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700473 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -0700474{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800475 struct ixgbe_adapter *adapter = q_vector->adapter;
476 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700477 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
478 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -0700479
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000480 skb_record_rx_queue(skb, ring->queue_index);
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000481 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800482 if (adapter->vlgrp && is_vlan && (tag != 0))
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800483 vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700484 else
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800485 napi_gro_receive(napi, skb);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700486 } else {
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000487 if (adapter->vlgrp && is_vlan && (tag != 0))
488 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
489 else
490 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700491 }
492}
493
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800494/**
495 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
496 * @adapter: address of board private structure
497 * @status_err: hardware indication of status of receive
498 * @skb: skb currently being received and modified
499 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700500static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700501 u32 status_err, struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700502{
503 skb->ip_summed = CHECKSUM_NONE;
504
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700505 /* Rx csum disabled */
506 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -0700507 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800508
509 /* if IP and error */
510 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
511 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700512 adapter->hw_csum_rx_error++;
513 return;
514 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800515
516 if (!(status_err & IXGBE_RXD_STAT_L4CS))
517 return;
518
519 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
520 adapter->hw_csum_rx_error++;
521 return;
522 }
523
Auke Kok9a799d72007-09-15 14:07:45 -0700524 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800525 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -0700526 adapter->hw_csum_rx_good++;
527}
528
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000529static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
530 struct ixgbe_ring *rx_ring, u32 val)
531{
532 /*
533 * Force memory writes to complete before letting h/w
534 * know there are new descriptors to fetch. (Only
535 * applicable for weak-ordered memory model archs,
536 * such as IA-64).
537 */
538 wmb();
539 IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
540}
541
Auke Kok9a799d72007-09-15 14:07:45 -0700542/**
543 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
544 * @adapter: address of board private structure
545 **/
546static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700547 struct ixgbe_ring *rx_ring,
548 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700549{
Auke Kok9a799d72007-09-15 14:07:45 -0700550 struct pci_dev *pdev = adapter->pdev;
551 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700552 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700553 unsigned int i;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000554 unsigned int bufsz = rx_ring->rx_buf_len + NET_IP_ALIGN;
Auke Kok9a799d72007-09-15 14:07:45 -0700555
556 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700557 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700558
559 while (cleaned_count--) {
560 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
561
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700562 if (!bi->page_dma &&
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700563 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700564 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700565 bi->page = alloc_page(GFP_ATOMIC);
566 if (!bi->page) {
567 adapter->alloc_rx_page_failed++;
568 goto no_buffers;
569 }
570 bi->page_offset = 0;
571 } else {
572 /* use a half page if we're re-using */
573 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700574 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700575
576 bi->page_dma = pci_map_page(pdev, bi->page,
577 bi->page_offset,
578 (PAGE_SIZE / 2),
579 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700580 }
581
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700582 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800583 struct sk_buff *skb;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000584 skb = netdev_alloc_skb(adapter->netdev, bufsz);
Auke Kok9a799d72007-09-15 14:07:45 -0700585
586 if (!skb) {
587 adapter->alloc_rx_buff_failed++;
588 goto no_buffers;
589 }
590
591 /*
592 * Make buffer alignment 2 beyond a 16 byte boundary
593 * this will result in a 16 byte aligned IP header after
594 * the 14 byte MAC header is removed
595 */
596 skb_reserve(skb, NET_IP_ALIGN);
597
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700598 bi->skb = skb;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000599 bi->dma = pci_map_single(pdev, skb->data, bufsz,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700600 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700601 }
602 /* Refresh the desc even if buffer_addrs didn't change because
603 * each write-back erases this info. */
604 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700605 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
606 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700607 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700608 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700609 }
610
611 i++;
612 if (i == rx_ring->count)
613 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700614 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700615 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700616
Auke Kok9a799d72007-09-15 14:07:45 -0700617no_buffers:
618 if (rx_ring->next_to_use != i) {
619 rx_ring->next_to_use = i;
620 if (i-- == 0)
621 i = (rx_ring->count - 1);
622
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000623 ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700624 }
625}
626
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700627static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
628{
629 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
630}
631
632static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
633{
634 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
635}
636
Alexander Duyckf8212f92009-04-27 22:42:37 +0000637static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
638{
639 return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
640 IXGBE_RXDADV_RSCCNT_MASK) >>
641 IXGBE_RXDADV_RSCCNT_SHIFT;
642}
643
644/**
645 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
646 * @skb: pointer to the last skb in the rsc queue
647 *
648 * This function changes a queue full of hw rsc buffers into a completed
649 * packet. It uses the ->prev pointers to find the first packet and then
650 * turns it into the frag list owner.
651 **/
652static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
653{
654 unsigned int frag_list_size = 0;
655
656 while (skb->prev) {
657 struct sk_buff *prev = skb->prev;
658 frag_list_size += skb->len;
659 skb->prev = NULL;
660 skb = prev;
661 }
662
663 skb_shinfo(skb)->frag_list = skb->next;
664 skb->next = NULL;
665 skb->len += frag_list_size;
666 skb->data_len += frag_list_size;
667 skb->truesize += frag_list_size;
668 return skb;
669}
670
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800671static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700672 struct ixgbe_ring *rx_ring,
673 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700674{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800675 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -0700676 struct pci_dev *pdev = adapter->pdev;
677 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
678 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
679 struct sk_buff *skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000680 unsigned int i, rsc_count = 0;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700681 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700682 u16 hdr_info;
683 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700684 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800685 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700686
687 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700688 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
689 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
690 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700691
692 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700693 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700694 if (*work_done >= work_to_do)
695 break;
696 (*work_done)++;
697
698 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700699 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
700 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700701 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700702 if (hdr_info & IXGBE_RXDADV_SPH)
703 adapter->rx_hdr_split++;
704 if (len > IXGBE_RX_HDR_SIZE)
705 len = IXGBE_RX_HDR_SIZE;
706 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700707 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700708 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700709 }
Auke Kok9a799d72007-09-15 14:07:45 -0700710
711 cleaned = true;
712 skb = rx_buffer_info->skb;
713 prefetch(skb->data - NET_IP_ALIGN);
714 rx_buffer_info->skb = NULL;
715
Alexander Duyck21fa4e62009-06-04 15:59:49 +0000716 if (rx_buffer_info->dma) {
Auke Kok9a799d72007-09-15 14:07:45 -0700717 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800718 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700719 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700720 skb_put(skb, len);
721 }
722
723 if (upper_len) {
724 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700725 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700726 rx_buffer_info->page_dma = 0;
727 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700728 rx_buffer_info->page,
729 rx_buffer_info->page_offset,
730 upper_len);
731
732 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
733 (page_count(rx_buffer_info->page) != 1))
734 rx_buffer_info->page = NULL;
735 else
736 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700737
738 skb->len += upper_len;
739 skb->data_len += upper_len;
740 skb->truesize += upper_len;
741 }
742
743 i++;
744 if (i == rx_ring->count)
745 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700746
747 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
748 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -0700749 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000750
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +0000751 if (adapter->flags & IXGBE_FLAG2_RSC_CAPABLE)
Alexander Duyckf8212f92009-04-27 22:42:37 +0000752 rsc_count = ixgbe_get_rsc_count(rx_desc);
753
754 if (rsc_count) {
755 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
756 IXGBE_RXDADV_NEXTP_SHIFT;
757 next_buffer = &rx_ring->rx_buffer_info[nextp];
758 rx_ring->rsc_count += (rsc_count - 1);
759 } else {
760 next_buffer = &rx_ring->rx_buffer_info[i];
761 }
762
Auke Kok9a799d72007-09-15 14:07:45 -0700763 if (staterr & IXGBE_RXD_STAT_EOP) {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000764 if (skb->prev)
765 skb = ixgbe_transform_rsc_queue(skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700766 rx_ring->stats.packets++;
767 rx_ring->stats.bytes += skb->len;
768 } else {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000769 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
770 rx_buffer_info->skb = next_buffer->skb;
771 rx_buffer_info->dma = next_buffer->dma;
772 next_buffer->skb = skb;
773 next_buffer->dma = 0;
774 } else {
775 skb->next = next_buffer->skb;
776 skb->next->prev = skb;
777 }
Auke Kok9a799d72007-09-15 14:07:45 -0700778 adapter->non_eop_descs++;
779 goto next_desc;
780 }
781
782 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
783 dev_kfree_skb_irq(skb);
784 goto next_desc;
785 }
786
787 ixgbe_rx_checksum(adapter, staterr, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800788
789 /* probably a little skewed due to removing CRC */
790 total_rx_bytes += skb->len;
791 total_rx_packets++;
792
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700793 skb->protocol = eth_type_trans(skb, adapter->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +0000794#ifdef IXGBE_FCOE
795 /* if ddp, not passing to ULD unless for FCP_RSP or error */
796 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
797 if (!ixgbe_fcoe_ddp(adapter, rx_desc, skb))
798 goto next_desc;
799#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000800 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700801
802next_desc:
803 rx_desc->wb.upper.status_error = 0;
804
805 /* return some buffers to hardware, one at a time is too slow */
806 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
807 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
808 cleaned_count = 0;
809 }
810
811 /* use prefetched values */
812 rx_desc = next_rxd;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000813 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700814
815 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700816 }
817
Auke Kok9a799d72007-09-15 14:07:45 -0700818 rx_ring->next_to_clean = i;
819 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
820
821 if (cleaned_count)
822 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
823
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800824 rx_ring->total_packets += total_rx_packets;
825 rx_ring->total_bytes += total_rx_bytes;
826 adapter->net_stats.rx_bytes += total_rx_bytes;
827 adapter->net_stats.rx_packets += total_rx_packets;
828
Auke Kok9a799d72007-09-15 14:07:45 -0700829 return cleaned;
830}
831
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800832static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700833/**
834 * ixgbe_configure_msix - Configure MSI-X hardware
835 * @adapter: board private structure
836 *
837 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
838 * interrupts.
839 **/
840static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
841{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800842 struct ixgbe_q_vector *q_vector;
843 int i, j, q_vectors, v_idx, r_idx;
844 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700845
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800846 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
847
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000848 /*
849 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800850 * corresponding register.
851 */
852 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +0000853 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800854 /* XXX for_each_bit(...) */
855 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700856 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800857
858 for (i = 0; i < q_vector->rxr_count; i++) {
859 j = adapter->rx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000860 ixgbe_set_ivar(adapter, 0, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800861 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700862 adapter->num_rx_queues,
863 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800864 }
865 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700866 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800867
868 for (i = 0; i < q_vector->txr_count; i++) {
869 j = adapter->tx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000870 ixgbe_set_ivar(adapter, 1, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800871 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700872 adapter->num_tx_queues,
873 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800874 }
875
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700876 /* if this is a tx only vector halve the interrupt rate */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800877 if (q_vector->txr_count && !q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700878 q_vector->eitr = (adapter->eitr_param >> 1);
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000879 else if (q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700880 /* rx only */
881 q_vector->eitr = adapter->eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800882
Alexander Duyckfe49f042009-06-04 16:00:09 +0000883 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -0700884 }
885
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000886 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
887 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
888 v_idx);
889 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
890 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800891 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -0700892
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700893 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800894 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700895 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800896 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -0700897}
898
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800899enum latency_range {
900 lowest_latency = 0,
901 low_latency = 1,
902 bulk_latency = 2,
903 latency_invalid = 255
904};
905
906/**
907 * ixgbe_update_itr - update the dynamic ITR value based on statistics
908 * @adapter: pointer to adapter
909 * @eitr: eitr setting (ints per sec) to give last timeslice
910 * @itr_setting: current throttle rate in ints/second
911 * @packets: the number of packets during this measurement interval
912 * @bytes: the number of bytes during this measurement interval
913 *
914 * Stores a new ITR value based on packets and byte
915 * counts during the last interrupt. The advantage of per interrupt
916 * computation is faster updates and more accurate ITR for the current
917 * traffic pattern. Constants in this function were computed
918 * based on theoretical maximum wire speed and thresholds were set based
919 * on testing data as well as attempting to minimize response time
920 * while increasing bulk throughput.
921 * this functionality is controlled by the InterruptThrottleRate module
922 * parameter (see ixgbe_param.c)
923 **/
924static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700925 u32 eitr, u8 itr_setting,
926 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800927{
928 unsigned int retval = itr_setting;
929 u32 timepassed_us;
930 u64 bytes_perint;
931
932 if (packets == 0)
933 goto update_itr_done;
934
935
936 /* simple throttlerate management
937 * 0-20MB/s lowest (100000 ints/s)
938 * 20-100MB/s low (20000 ints/s)
939 * 100-1249MB/s bulk (8000 ints/s)
940 */
941 /* what was last interrupt timeslice? */
942 timepassed_us = 1000000/eitr;
943 bytes_perint = bytes / timepassed_us; /* bytes/usec */
944
945 switch (itr_setting) {
946 case lowest_latency:
947 if (bytes_perint > adapter->eitr_low)
948 retval = low_latency;
949 break;
950 case low_latency:
951 if (bytes_perint > adapter->eitr_high)
952 retval = bulk_latency;
953 else if (bytes_perint <= adapter->eitr_low)
954 retval = lowest_latency;
955 break;
956 case bulk_latency:
957 if (bytes_perint <= adapter->eitr_high)
958 retval = low_latency;
959 break;
960 }
961
962update_itr_done:
963 return retval;
964}
965
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000966/**
967 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +0000968 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000969 *
970 * This function is made to be called by ethtool and by the driver
971 * when it needs to update EITR registers at runtime. Hardware
972 * specific quirks/differences are taken care of here.
973 */
Alexander Duyckfe49f042009-06-04 16:00:09 +0000974void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000975{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000976 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000977 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000978 int v_idx = q_vector->v_idx;
979 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
980
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000981 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
982 /* must write high and low 16 bits to reset counter */
983 itr_reg |= (itr_reg << 16);
984 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
985 /*
986 * set the WDIS bit to not clear the timer bits and cause an
987 * immediate assertion of the interrupt
988 */
989 itr_reg |= IXGBE_EITR_CNT_WDIS;
990 }
991 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
992}
993
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800994static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
995{
996 struct ixgbe_adapter *adapter = q_vector->adapter;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800997 u32 new_itr;
998 u8 current_itr, ret_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000999 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001000 struct ixgbe_ring *rx_ring, *tx_ring;
1001
1002 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1003 for (i = 0; i < q_vector->txr_count; i++) {
1004 tx_ring = &(adapter->tx_ring[r_idx]);
1005 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001006 q_vector->tx_itr,
1007 tx_ring->total_packets,
1008 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001009 /* if the result for this queue would decrease interrupt
1010 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001011 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001012 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001013 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001014 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001015 }
1016
1017 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1018 for (i = 0; i < q_vector->rxr_count; i++) {
1019 rx_ring = &(adapter->rx_ring[r_idx]);
1020 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001021 q_vector->rx_itr,
1022 rx_ring->total_packets,
1023 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001024 /* if the result for this queue would decrease interrupt
1025 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001026 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001027 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001028 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001029 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001030 }
1031
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001032 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001033
1034 switch (current_itr) {
1035 /* counts and packets in update_itr are dependent on these numbers */
1036 case lowest_latency:
1037 new_itr = 100000;
1038 break;
1039 case low_latency:
1040 new_itr = 20000; /* aka hwitr = ~200 */
1041 break;
1042 case bulk_latency:
1043 default:
1044 new_itr = 8000;
1045 break;
1046 }
1047
1048 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001049 /* do an exponential smoothing */
1050 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001051
1052 /* save the algorithm value here, not the smoothed one */
1053 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001054
1055 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001056 }
1057
1058 return;
1059}
1060
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001061static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1062{
1063 struct ixgbe_hw *hw = &adapter->hw;
1064
1065 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1066 (eicr & IXGBE_EICR_GPI_SDP1)) {
1067 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
1068 /* write to clear the interrupt */
1069 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1070 }
1071}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001072
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001073static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1074{
1075 struct ixgbe_hw *hw = &adapter->hw;
1076
1077 if (eicr & IXGBE_EICR_GPI_SDP1) {
1078 /* Clear the interrupt */
1079 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1080 schedule_work(&adapter->multispeed_fiber_task);
1081 } else if (eicr & IXGBE_EICR_GPI_SDP2) {
1082 /* Clear the interrupt */
1083 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1084 schedule_work(&adapter->sfp_config_module_task);
1085 } else {
1086 /* Interrupt isn't for us... */
1087 return;
1088 }
1089}
1090
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001091static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1092{
1093 struct ixgbe_hw *hw = &adapter->hw;
1094
1095 adapter->lsc_int++;
1096 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1097 adapter->link_check_timeout = jiffies;
1098 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1099 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1100 schedule_work(&adapter->watchdog_task);
1101 }
1102}
1103
Auke Kok9a799d72007-09-15 14:07:45 -07001104static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1105{
1106 struct net_device *netdev = data;
1107 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1108 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001109 u32 eicr;
1110
1111 /*
1112 * Workaround for Silicon errata. Use clear-by-write instead
1113 * of clear-by-read. Reading with EICS will return the
1114 * interrupt causes without clearing, which later be done
1115 * with the write to EICR.
1116 */
1117 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1118 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001119
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001120 if (eicr & IXGBE_EICR_LSC)
1121 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001122
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001123 if (hw->mac.type == ixgbe_mac_82598EB)
1124 ixgbe_check_fan_failure(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001125
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001126 if (hw->mac.type == ixgbe_mac_82599EB)
1127 ixgbe_check_sfp_event(adapter, eicr);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001128 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1129 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -07001130
1131 return IRQ_HANDLED;
1132}
1133
Alexander Duyckfe49f042009-06-04 16:00:09 +00001134static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1135 u64 qmask)
1136{
1137 u32 mask;
1138
1139 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1140 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1141 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1142 } else {
1143 mask = (qmask & 0xFFFFFFFF);
1144 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
1145 mask = (qmask >> 32);
1146 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
1147 }
1148 /* skip the flush */
1149}
1150
1151static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
1152 u64 qmask)
1153{
1154 u32 mask;
1155
1156 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1157 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1158 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
1159 } else {
1160 mask = (qmask & 0xFFFFFFFF);
1161 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
1162 mask = (qmask >> 32);
1163 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
1164 }
1165 /* skip the flush */
1166}
1167
Auke Kok9a799d72007-09-15 14:07:45 -07001168static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1169{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001170 struct ixgbe_q_vector *q_vector = data;
1171 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001172 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001173 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001174
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001175 if (!q_vector->txr_count)
1176 return IRQ_HANDLED;
1177
1178 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1179 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001180 tx_ring = &(adapter->tx_ring[r_idx]);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001181 tx_ring->total_bytes = 0;
1182 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001183 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001184 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001185 }
1186
Alexander Duyck91281fd2009-06-04 16:00:27 +00001187 /* disable interrupts on this vector only */
1188 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1189 napi_schedule(&q_vector->napi);
1190
Auke Kok9a799d72007-09-15 14:07:45 -07001191 return IRQ_HANDLED;
1192}
1193
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001194/**
1195 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1196 * @irq: unused
1197 * @data: pointer to our q_vector struct for this interrupt vector
1198 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001199static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1200{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001201 struct ixgbe_q_vector *q_vector = data;
1202 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001203 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001204 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001205 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001206
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001207 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001208 for (i = 0; i < q_vector->rxr_count; i++) {
1209 rx_ring = &(adapter->rx_ring[r_idx]);
1210 rx_ring->total_bytes = 0;
1211 rx_ring->total_packets = 0;
1212 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1213 r_idx + 1);
1214 }
1215
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001216 if (!q_vector->rxr_count)
1217 return IRQ_HANDLED;
1218
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001219 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001220 rx_ring = &(adapter->rx_ring[r_idx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001221 /* disable interrupts on this vector only */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001222 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
Ben Hutchings288379f2009-01-19 16:43:59 -08001223 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001224
Auke Kok9a799d72007-09-15 14:07:45 -07001225 return IRQ_HANDLED;
1226}
1227
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001228static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1229{
Alexander Duyck91281fd2009-06-04 16:00:27 +00001230 struct ixgbe_q_vector *q_vector = data;
1231 struct ixgbe_adapter *adapter = q_vector->adapter;
1232 struct ixgbe_ring *ring;
1233 int r_idx;
1234 int i;
1235
1236 if (!q_vector->txr_count && !q_vector->rxr_count)
1237 return IRQ_HANDLED;
1238
1239 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1240 for (i = 0; i < q_vector->txr_count; i++) {
1241 ring = &(adapter->tx_ring[r_idx]);
1242 ring->total_bytes = 0;
1243 ring->total_packets = 0;
1244 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1245 r_idx + 1);
1246 }
1247
1248 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1249 for (i = 0; i < q_vector->rxr_count; i++) {
1250 ring = &(adapter->rx_ring[r_idx]);
1251 ring->total_bytes = 0;
1252 ring->total_packets = 0;
1253 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1254 r_idx + 1);
1255 }
1256
1257 /* disable interrupts on this vector only */
1258 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1259 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001260
1261 return IRQ_HANDLED;
1262}
1263
1264/**
1265 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1266 * @napi: napi struct with our devices info in it
1267 * @budget: amount of work driver is allowed to do this pass, in packets
1268 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001269 * This function is optimized for cleaning one queue only on a single
1270 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001271 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001272static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1273{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001274 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001275 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001276 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001277 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001278 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001279 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001280
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001281 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001282 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001283#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001284 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001285 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001286#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001287
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001288 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001289
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001290 /* If all Rx work done, exit the polling mode */
1291 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001292 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001293 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001294 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001295 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001296 ixgbe_irq_enable_queues(adapter,
1297 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07001298 }
1299
1300 return work_done;
1301}
1302
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001303/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00001304 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001305 * @napi: napi struct with our devices info in it
1306 * @budget: amount of work driver is allowed to do this pass, in packets
1307 *
1308 * This function will clean more than one rx queue associated with a
1309 * q_vector.
1310 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00001311static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001312{
1313 struct ixgbe_q_vector *q_vector =
1314 container_of(napi, struct ixgbe_q_vector, napi);
1315 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001316 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001317 int work_done = 0, i;
1318 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001319 bool tx_clean_complete = true;
1320
1321 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1322 for (i = 0; i < q_vector->txr_count; i++) {
1323 ring = &(adapter->tx_ring[r_idx]);
1324#ifdef CONFIG_IXGBE_DCA
1325 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1326 ixgbe_update_tx_dca(adapter, ring);
1327#endif
1328 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
1329 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1330 r_idx + 1);
1331 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001332
1333 /* attempt to distribute budget to each queue fairly, but don't allow
1334 * the budget to go below 1 because we'll exit polling */
1335 budget /= (q_vector->rxr_count ?: 1);
1336 budget = max(budget, 1);
1337 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1338 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck91281fd2009-06-04 16:00:27 +00001339 ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001340#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001341 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck91281fd2009-06-04 16:00:27 +00001342 ixgbe_update_rx_dca(adapter, ring);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001343#endif
Alexander Duyck91281fd2009-06-04 16:00:27 +00001344 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001345 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1346 r_idx + 1);
1347 }
1348
1349 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck91281fd2009-06-04 16:00:27 +00001350 ring = &(adapter->rx_ring[r_idx]);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001351 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001352 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001353 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001354 if (adapter->itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001355 ixgbe_set_itr_msix(q_vector);
1356 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001357 ixgbe_irq_enable_queues(adapter,
1358 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001359 return 0;
1360 }
1361
1362 return work_done;
1363}
Alexander Duyck91281fd2009-06-04 16:00:27 +00001364
1365/**
1366 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
1367 * @napi: napi struct with our devices info in it
1368 * @budget: amount of work driver is allowed to do this pass, in packets
1369 *
1370 * This function is optimized for cleaning one queue only on a single
1371 * q_vector!!!
1372 **/
1373static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
1374{
1375 struct ixgbe_q_vector *q_vector =
1376 container_of(napi, struct ixgbe_q_vector, napi);
1377 struct ixgbe_adapter *adapter = q_vector->adapter;
1378 struct ixgbe_ring *tx_ring = NULL;
1379 int work_done = 0;
1380 long r_idx;
1381
1382 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1383 tx_ring = &(adapter->tx_ring[r_idx]);
1384#ifdef CONFIG_IXGBE_DCA
1385 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1386 ixgbe_update_tx_dca(adapter, tx_ring);
1387#endif
1388
1389 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
1390 work_done = budget;
1391
1392 /* If all Rx work done, exit the polling mode */
1393 if (work_done < budget) {
1394 napi_complete(napi);
1395 if (adapter->itr_setting & 1)
1396 ixgbe_set_itr_msix(q_vector);
1397 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1398 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
1399 }
1400
1401 return work_done;
1402}
1403
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001404static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001405 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001406{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001407 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1408
1409 set_bit(r_idx, q_vector->rxr_idx);
1410 q_vector->rxr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001411}
Auke Kok9a799d72007-09-15 14:07:45 -07001412
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001413static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001414 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001415{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001416 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1417
1418 set_bit(t_idx, q_vector->txr_idx);
1419 q_vector->txr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001420}
Auke Kok9a799d72007-09-15 14:07:45 -07001421
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001422/**
1423 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1424 * @adapter: board private structure to initialize
1425 * @vectors: allotted vector count for descriptor rings
1426 *
1427 * This function maps descriptor rings to the queue-specific vectors
1428 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1429 * one vector per ring/queue, but on a constrained vector budget, we
1430 * group the rings as "efficiently" as possible. You would add new
1431 * mapping configurations in here.
1432 **/
1433static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001434 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001435{
1436 int v_start = 0;
1437 int rxr_idx = 0, txr_idx = 0;
1438 int rxr_remaining = adapter->num_rx_queues;
1439 int txr_remaining = adapter->num_tx_queues;
1440 int i, j;
1441 int rqpv, tqpv;
1442 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001443
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001444 /* No mapping required if MSI-X is disabled. */
1445 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001446 goto out;
1447
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001448 /*
1449 * The ideal configuration...
1450 * We have enough vectors to map one per queue.
1451 */
1452 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1453 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1454 map_vector_to_rxq(adapter, v_start, rxr_idx);
1455
1456 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1457 map_vector_to_txq(adapter, v_start, txr_idx);
1458
1459 goto out;
1460 }
1461
1462 /*
1463 * If we don't have enough vectors for a 1-to-1
1464 * mapping, we'll have to group them so there are
1465 * multiple queues per vector.
1466 */
1467 /* Re-adjusting *qpv takes care of the remainder. */
1468 for (i = v_start; i < vectors; i++) {
1469 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1470 for (j = 0; j < rqpv; j++) {
1471 map_vector_to_rxq(adapter, i, rxr_idx);
1472 rxr_idx++;
1473 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001474 }
Auke Kok9a799d72007-09-15 14:07:45 -07001475 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001476 for (i = v_start; i < vectors; i++) {
1477 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1478 for (j = 0; j < tqpv; j++) {
1479 map_vector_to_txq(adapter, i, txr_idx);
1480 txr_idx++;
1481 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001482 }
Auke Kok9a799d72007-09-15 14:07:45 -07001483 }
1484
Auke Kok9a799d72007-09-15 14:07:45 -07001485out:
Auke Kok9a799d72007-09-15 14:07:45 -07001486 return err;
1487}
1488
1489/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001490 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1491 * @adapter: board private structure
1492 *
1493 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1494 * interrupts from the kernel.
1495 **/
1496static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1497{
1498 struct net_device *netdev = adapter->netdev;
1499 irqreturn_t (*handler)(int, void *);
1500 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001501 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001502
1503 /* Decrement for Other and TCP Timer vectors */
1504 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1505
1506 /* Map the Tx/Rx rings to the vectors we were allotted. */
1507 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1508 if (err)
1509 goto out;
1510
1511#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001512 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1513 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001514 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001515 handler = SET_HANDLER(adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001516
1517 if(handler == &ixgbe_msix_clean_rx) {
1518 sprintf(adapter->name[vector], "%s-%s-%d",
1519 netdev->name, "rx", ri++);
1520 }
1521 else if(handler == &ixgbe_msix_clean_tx) {
1522 sprintf(adapter->name[vector], "%s-%s-%d",
1523 netdev->name, "tx", ti++);
1524 }
1525 else
1526 sprintf(adapter->name[vector], "%s-%s-%d",
1527 netdev->name, "TxRx", vector);
1528
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001529 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001530 handler, 0, adapter->name[vector],
Alexander Duyck7a921c92009-05-06 10:43:28 +00001531 adapter->q_vector[vector]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001532 if (err) {
1533 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001534 "request_irq failed for MSIX interrupt "
1535 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001536 goto free_queue_irqs;
1537 }
1538 }
1539
1540 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1541 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001542 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001543 if (err) {
1544 DPRINTK(PROBE, ERR,
1545 "request_irq for msix_lsc failed: %d\n", err);
1546 goto free_queue_irqs;
1547 }
1548
1549 return 0;
1550
1551free_queue_irqs:
1552 for (i = vector - 1; i >= 0; i--)
1553 free_irq(adapter->msix_entries[--vector].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001554 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001555 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1556 pci_disable_msix(adapter->pdev);
1557 kfree(adapter->msix_entries);
1558 adapter->msix_entries = NULL;
1559out:
1560 return err;
1561}
1562
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001563static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1564{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001565 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001566 u8 current_itr;
1567 u32 new_itr = q_vector->eitr;
1568 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1569 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1570
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001571 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001572 q_vector->tx_itr,
1573 tx_ring->total_packets,
1574 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001575 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001576 q_vector->rx_itr,
1577 rx_ring->total_packets,
1578 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001579
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001580 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001581
1582 switch (current_itr) {
1583 /* counts and packets in update_itr are dependent on these numbers */
1584 case lowest_latency:
1585 new_itr = 100000;
1586 break;
1587 case low_latency:
1588 new_itr = 20000; /* aka hwitr = ~200 */
1589 break;
1590 case bulk_latency:
1591 new_itr = 8000;
1592 break;
1593 default:
1594 break;
1595 }
1596
1597 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001598 /* do an exponential smoothing */
1599 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001600
1601 /* save the algorithm value here, not the smoothed one */
1602 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001603
1604 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001605 }
1606
1607 return;
1608}
1609
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001610/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001611 * ixgbe_irq_enable - Enable default interrupt generation settings
1612 * @adapter: board private structure
1613 **/
1614static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1615{
1616 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00001617
1618 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
David S. Miller6ab33d52008-11-20 16:44:00 -08001619 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1620 mask |= IXGBE_EIMS_GPI_SDP1;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001621 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001622 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001623 mask |= IXGBE_EIMS_GPI_SDP1;
1624 mask |= IXGBE_EIMS_GPI_SDP2;
1625 }
1626
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001627 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Nelson, Shannon835462f2009-04-27 22:42:54 +00001628 ixgbe_irq_enable_queues(adapter, ~0);
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001629 IXGBE_WRITE_FLUSH(&adapter->hw);
1630}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001631
1632/**
1633 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001634 * @irq: interrupt number
1635 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001636 **/
1637static irqreturn_t ixgbe_intr(int irq, void *data)
1638{
1639 struct net_device *netdev = data;
1640 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1641 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001642 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07001643 u32 eicr;
1644
Don Skidmore54037502009-02-21 15:42:56 -08001645 /*
1646 * Workaround for silicon errata. Mask the interrupts
1647 * before the read of EICR.
1648 */
1649 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1650
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001651 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1652 * therefore no explict interrupt disable is necessary */
1653 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001654 if (!eicr) {
1655 /* shared interrupt alert!
1656 * make sure interrupts are enabled because the read will
1657 * have disabled interrupts due to EIAM */
1658 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001659 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001660 }
Auke Kok9a799d72007-09-15 14:07:45 -07001661
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001662 if (eicr & IXGBE_EICR_LSC)
1663 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001664
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001665 if (hw->mac.type == ixgbe_mac_82599EB)
1666 ixgbe_check_sfp_event(adapter, eicr);
1667
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001668 ixgbe_check_fan_failure(adapter, eicr);
1669
Alexander Duyck7a921c92009-05-06 10:43:28 +00001670 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001671 adapter->tx_ring[0].total_packets = 0;
1672 adapter->tx_ring[0].total_bytes = 0;
1673 adapter->rx_ring[0].total_packets = 0;
1674 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001675 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00001676 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07001677 }
1678
1679 return IRQ_HANDLED;
1680}
1681
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001682static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1683{
1684 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1685
1686 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001687 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001688 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1689 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1690 q_vector->rxr_count = 0;
1691 q_vector->txr_count = 0;
1692 }
1693}
1694
Auke Kok9a799d72007-09-15 14:07:45 -07001695/**
1696 * ixgbe_request_irq - initialize interrupts
1697 * @adapter: board private structure
1698 *
1699 * Attempts to configure interrupts using the best available
1700 * capabilities of the hardware and kernel.
1701 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001702static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001703{
1704 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001705 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001706
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001707 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1708 err = ixgbe_request_msix_irqs(adapter);
1709 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1710 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001711 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001712 } else {
1713 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001714 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001715 }
1716
Auke Kok9a799d72007-09-15 14:07:45 -07001717 if (err)
1718 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1719
Auke Kok9a799d72007-09-15 14:07:45 -07001720 return err;
1721}
1722
1723static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1724{
1725 struct net_device *netdev = adapter->netdev;
1726
1727 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001728 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001729
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001730 q_vectors = adapter->num_msix_vectors;
1731
1732 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001733 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001734
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001735 i--;
1736 for (; i >= 0; i--) {
1737 free_irq(adapter->msix_entries[i].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001738 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001739 }
1740
1741 ixgbe_reset_q_vectors(adapter);
1742 } else {
1743 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001744 }
1745}
1746
1747/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001748 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1749 * @adapter: board private structure
1750 **/
1751static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1752{
Nelson, Shannon835462f2009-04-27 22:42:54 +00001753 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1754 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1755 } else {
1756 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
1757 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001758 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001759 }
1760 IXGBE_WRITE_FLUSH(&adapter->hw);
1761 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1762 int i;
1763 for (i = 0; i < adapter->num_msix_vectors; i++)
1764 synchronize_irq(adapter->msix_entries[i].vector);
1765 } else {
1766 synchronize_irq(adapter->pdev->irq);
1767 }
1768}
1769
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001770/**
Auke Kok9a799d72007-09-15 14:07:45 -07001771 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1772 *
1773 **/
1774static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1775{
Auke Kok9a799d72007-09-15 14:07:45 -07001776 struct ixgbe_hw *hw = &adapter->hw;
1777
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001778 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001779 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001780
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001781 ixgbe_set_ivar(adapter, 0, 0, 0);
1782 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001783
1784 map_vector_to_rxq(adapter, 0, 0);
1785 map_vector_to_txq(adapter, 0, 0);
1786
1787 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001788}
1789
1790/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001791 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001792 * @adapter: board private structure
1793 *
1794 * Configure the Tx unit of the MAC after a reset.
1795 **/
1796static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1797{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001798 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001799 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001800 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001801
1802 /* Setup the HW Tx Head and Tail descriptor pointers */
1803 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001804 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1805 j = ring->reg_idx;
1806 tdba = ring->dma;
1807 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001808 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Yang Hongyang284901a2009-04-06 19:01:15 -07001809 (tdba & DMA_BIT_MASK(32)));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001810 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1811 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1812 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1813 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1814 adapter->tx_ring[i].head = IXGBE_TDH(j);
1815 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1816 /* Disable Tx Head Writeback RO bit, since this hoses
1817 * bookkeeping if things aren't delivered in order.
1818 */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001819 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001820 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001821 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001822 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001823 if (hw->mac.type == ixgbe_mac_82599EB) {
1824 /* We enable 8 traffic classes, DCB only */
1825 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1826 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1827 IXGBE_MTQC_8TC_8TQ));
1828 }
Auke Kok9a799d72007-09-15 14:07:45 -07001829}
1830
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001831#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07001832
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001833static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1834{
1835 struct ixgbe_ring *rx_ring;
1836 u32 srrctl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001837 int queue0 = 0;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001838 unsigned long mask;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001839 struct ixgbe_ring_feature *feature = adapter->ring_feature;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001840
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001841 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Alexander Duyck163de422009-05-07 10:39:16 +00001842 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001843 int dcb_i = feature[RING_F_DCB].indices;
Alexander Duyck163de422009-05-07 10:39:16 +00001844 if (dcb_i == 8)
1845 queue0 = index >> 4;
1846 else if (dcb_i == 4)
1847 queue0 = index >> 5;
1848 else
1849 dev_err(&adapter->pdev->dev, "Invalid DCB "
1850 "configuration\n");
Yi Zou0331a832009-05-17 12:33:52 +00001851#ifdef IXGBE_FCOE
1852 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1853 struct ixgbe_ring_feature *f;
1854
1855 rx_ring = &adapter->rx_ring[queue0];
1856 f = &adapter->ring_feature[RING_F_FCOE];
1857 if ((queue0 == 0) && (index > rx_ring->reg_idx))
1858 queue0 = f->mask + index -
1859 rx_ring->reg_idx - 1;
1860 }
1861#endif /* IXGBE_FCOE */
Alexander Duyck163de422009-05-07 10:39:16 +00001862 } else {
1863 queue0 = index;
1864 }
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001865 } else {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001866 mask = (unsigned long) feature[RING_F_RSS].mask;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001867 queue0 = index & mask;
1868 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001869 }
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001870
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001871 rx_ring = &adapter->rx_ring[queue0];
1872
1873 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1874
1875 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1876 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1877
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001878 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1879 IXGBE_SRRCTL_BSIZEHDR_MASK;
1880
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001881 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001882#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
1883 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1884#else
1885 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1886#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001887 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001888 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001889 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
1890 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001891 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001892 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001893
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001894 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1895}
1896
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001897static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
1898{
1899 u32 mrqc = 0;
1900 int mask;
1901
1902 if (!(adapter->hw.mac.type == ixgbe_mac_82599EB))
1903 return mrqc;
1904
1905 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
1906#ifdef CONFIG_IXGBE_DCB
1907 | IXGBE_FLAG_DCB_ENABLED
1908#endif
1909 );
1910
1911 switch (mask) {
1912 case (IXGBE_FLAG_RSS_ENABLED):
1913 mrqc = IXGBE_MRQC_RSSEN;
1914 break;
1915#ifdef CONFIG_IXGBE_DCB
1916 case (IXGBE_FLAG_DCB_ENABLED):
1917 mrqc = IXGBE_MRQC_RT8TCEN;
1918 break;
1919#endif /* CONFIG_IXGBE_DCB */
1920 default:
1921 break;
1922 }
1923
1924 return mrqc;
1925}
1926
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001927/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001928 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001929 * @adapter: board private structure
1930 *
1931 * Configure the Rx unit of the MAC after a reset.
1932 **/
1933static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1934{
1935 u64 rdba;
1936 struct ixgbe_hw *hw = &adapter->hw;
1937 struct net_device *netdev = adapter->netdev;
1938 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001939 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001940 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001941 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1942 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1943 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001944 u32 fctrl, hlreg0;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001945 u32 reta = 0, mrqc = 0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001946 u32 rdrxctl;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001947 u32 rscctrl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001948 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07001949
1950 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001951 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07001952
Yi Zoueacd73f2009-05-13 13:11:06 +00001953#ifdef IXGBE_FCOE
1954 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
1955 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
1956#endif /* IXGBE_FCOE */
1957
Auke Kok9a799d72007-09-15 14:07:45 -07001958 /* Set the RX buffer length according to the mode */
1959 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001960 rx_buf_len = IXGBE_RX_HDR_SIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001961 if (hw->mac.type == ixgbe_mac_82599EB) {
1962 /* PSRTYPE must be initialized in 82599 */
1963 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
1964 IXGBE_PSRTYPE_UDPHDR |
1965 IXGBE_PSRTYPE_IPV4HDR |
Yi Zoudfa12f02009-05-07 10:39:35 +00001966 IXGBE_PSRTYPE_IPV6HDR |
1967 IXGBE_PSRTYPE_L2HDR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001968 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
1969 }
Auke Kok9a799d72007-09-15 14:07:45 -07001970 } else {
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00001971 if (!(adapter->flags & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00001972 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001973 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001974 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001975 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07001976 }
1977
1978 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1979 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001980 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001981 fctrl |= IXGBE_FCTRL_PMCF;
Auke Kok9a799d72007-09-15 14:07:45 -07001982 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1983
1984 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1985 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1986 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1987 else
1988 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Yi Zou63f39bd2009-05-17 12:34:35 +00001989#ifdef IXGBE_FCOE
1990 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
1991 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1992#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001993 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1994
Auke Kok9a799d72007-09-15 14:07:45 -07001995 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1996 /* disable receives while setting up the descriptors */
1997 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1998 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1999
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002000 /*
2001 * Setup the HW Rx Head and Tail Descriptor Pointers and
2002 * the Base and Length of the Rx Descriptor Ring
2003 */
Auke Kok9a799d72007-09-15 14:07:45 -07002004 for (i = 0; i < adapter->num_rx_queues; i++) {
2005 rdba = adapter->rx_ring[i].dma;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002006 j = adapter->rx_ring[i].reg_idx;
Yang Hongyang284901a2009-04-06 19:01:15 -07002007 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32)));
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002008 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
2009 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
2010 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
2011 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
2012 adapter->rx_ring[i].head = IXGBE_RDH(j);
2013 adapter->rx_ring[i].tail = IXGBE_RDT(j);
2014 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002015
Yi Zou63f39bd2009-05-17 12:34:35 +00002016#ifdef IXGBE_FCOE
2017 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
2018 struct ixgbe_ring_feature *f;
2019 f = &adapter->ring_feature[RING_F_FCOE];
2020 if ((rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
2021 (i >= f->mask) && (i < f->mask + f->indices))
2022 adapter->rx_ring[i].rx_buf_len =
2023 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2024 }
2025
2026#endif /* IXGBE_FCOE */
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002027 ixgbe_configure_srrctl(adapter, j);
Auke Kok9a799d72007-09-15 14:07:45 -07002028 }
2029
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002030 if (hw->mac.type == ixgbe_mac_82598EB) {
2031 /*
2032 * For VMDq support of different descriptor types or
2033 * buffer sizes through the use of multiple SRRCTL
2034 * registers, RDRXCTL.MVMEN must be set to 1
2035 *
2036 * also, the manual doesn't mention it clearly but DCA hints
2037 * will only use queue 0's tags unless this bit is set. Side
2038 * effects of setting this bit are only that SRRCTL must be
2039 * fully programmed [0..15]
2040 */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002041 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2042 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
2043 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
Alexander Duyck2f90b862008-11-20 20:52:10 -08002044 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002045
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002046 /* Program MRQC for the distribution of queues */
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002047 mrqc = ixgbe_setup_mrqc(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002048
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002049 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07002050 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002051 for (i = 0, j = 0; i < 128; i++, j++) {
2052 if (j == adapter->ring_feature[RING_F_RSS].indices)
2053 j = 0;
2054 /* reta = 4-byte sliding window of
2055 * 0x00..(indices-1)(indices-1)00..etc. */
2056 reta = (reta << 8) | (j * 0x11);
2057 if ((i & 3) == 3)
2058 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07002059 }
2060
2061 /* Fill out hash function seeds */
2062 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002063 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002064
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002065 if (hw->mac.type == ixgbe_mac_82598EB)
2066 mrqc |= IXGBE_MRQC_RSSEN;
Auke Kok9a799d72007-09-15 14:07:45 -07002067 /* Perform hash on these packet types */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002068 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2069 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2070 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
2071 | IXGBE_MRQC_RSS_FIELD_IPV6
2072 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
2073 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07002074 }
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002075 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002076
2077 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2078
2079 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
2080 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
2081 /* Disable indicating checksum in descriptor, enables
2082 * RSS hash */
2083 rxcsum |= IXGBE_RXCSUM_PCSD;
2084 }
2085 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
2086 /* Enable IPv4 payload checksum for UDP fragments
2087 * if PCSD is not set */
2088 rxcsum |= IXGBE_RXCSUM_IPPCSE;
2089 }
2090
2091 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002092
2093 if (hw->mac.type == ixgbe_mac_82599EB) {
2094 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2095 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002096 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002097 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
2098 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002099
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00002100 if (adapter->flags & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002101 /* Enable 82599 HW-RSC */
2102 for (i = 0; i < adapter->num_rx_queues; i++) {
2103 j = adapter->rx_ring[i].reg_idx;
2104 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j));
2105 rscctrl |= IXGBE_RSCCTL_RSCEN;
2106 /*
Alexander Duycke76678d2009-05-17 20:57:47 +00002107 * we must limit the number of descriptors so that the
2108 * total size of max desc * buf_len is not greater
2109 * than 65535
Alexander Duyckf8212f92009-04-27 22:42:37 +00002110 */
Alexander Duycke76678d2009-05-17 20:57:47 +00002111 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
2112#if (MAX_SKB_FRAGS > 16)
2113 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2114#elif (MAX_SKB_FRAGS > 8)
Alexander Duyckf8212f92009-04-27 22:42:37 +00002115 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Alexander Duycke76678d2009-05-17 20:57:47 +00002116#elif (MAX_SKB_FRAGS > 4)
2117 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002118#else
Alexander Duycke76678d2009-05-17 20:57:47 +00002119 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002120#endif
Alexander Duycke76678d2009-05-17 20:57:47 +00002121 } else {
2122 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2123 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2124 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2125 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2126 else
2127 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2128 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002129 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl);
2130 }
2131 /* Disable RSC for ACK packets */
2132 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
2133 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
2134 }
Auke Kok9a799d72007-09-15 14:07:45 -07002135}
2136
Auke Kok9a799d72007-09-15 14:07:45 -07002137static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2138{
2139 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002140 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002141
2142 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002143 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002144}
2145
2146static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2147{
2148 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002149 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002150
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002151 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2152 ixgbe_irq_disable(adapter);
2153
Auke Kok9a799d72007-09-15 14:07:45 -07002154 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002155
2156 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2157 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002158
2159 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002160 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07002161}
2162
Don Skidmore068c89b2009-01-19 16:54:36 -08002163static void ixgbe_vlan_rx_register(struct net_device *netdev,
2164 struct vlan_group *grp)
2165{
2166 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2167 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002168 int i, j;
Don Skidmore068c89b2009-01-19 16:54:36 -08002169
2170 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2171 ixgbe_irq_disable(adapter);
2172 adapter->vlgrp = grp;
2173
2174 /*
2175 * For a DCB driver, always enable VLAN tag stripping so we can
2176 * still receive traffic from a DCB-enabled host even if we're
2177 * not in DCB mode.
2178 */
2179 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002180 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
2181 ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
Don Skidmore068c89b2009-01-19 16:54:36 -08002182 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2183 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002184 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
2185 ctrl |= IXGBE_VLNCTRL_VFE;
2186 /* enable VLAN tag insert/strip */
2187 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
2188 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2189 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
2190 for (i = 0; i < adapter->num_rx_queues; i++) {
2191 j = adapter->rx_ring[i].reg_idx;
2192 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
2193 ctrl |= IXGBE_RXDCTL_VME;
2194 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
2195 }
Don Skidmore068c89b2009-01-19 16:54:36 -08002196 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002197 ixgbe_vlan_rx_add_vid(netdev, 0);
Don Skidmore068c89b2009-01-19 16:54:36 -08002198
2199 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2200 ixgbe_irq_enable(adapter);
2201}
2202
Auke Kok9a799d72007-09-15 14:07:45 -07002203static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
2204{
2205 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2206
2207 if (adapter->vlgrp) {
2208 u16 vid;
2209 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2210 if (!vlan_group_get_device(adapter->vlgrp, vid))
2211 continue;
2212 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
2213 }
2214 }
2215}
2216
Christopher Leech2c5645c2008-08-26 04:27:02 -07002217static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
2218{
2219 struct dev_mc_list *mc_ptr;
2220 u8 *addr = *mc_addr_ptr;
2221 *vmdq = 0;
2222
2223 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
2224 if (mc_ptr->next)
2225 *mc_addr_ptr = mc_ptr->next->dmi_addr;
2226 else
2227 *mc_addr_ptr = NULL;
2228
2229 return addr;
2230}
2231
Auke Kok9a799d72007-09-15 14:07:45 -07002232/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07002233 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07002234 * @netdev: network interface device structure
2235 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07002236 * The set_rx_method entry point is called whenever the unicast/multicast
2237 * address list or the network interface flags are updated. This routine is
2238 * responsible for configuring the hardware for proper unicast, multicast and
2239 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07002240 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07002241static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07002242{
2243 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2244 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07002245 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002246 u8 *addr_list = NULL;
2247 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002248
2249 /* Check for Promiscuous and All Multicast modes */
2250
2251 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07002252 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07002253
2254 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07002255 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002256 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07002257 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07002258 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002259 if (netdev->flags & IFF_ALLMULTI) {
2260 fctrl |= IXGBE_FCTRL_MPE;
2261 fctrl &= ~IXGBE_FCTRL_UPE;
2262 } else {
2263 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2264 }
Alexander Duyck3d016252008-08-26 18:30:04 -07002265 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002266 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002267 }
2268
2269 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07002270 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07002271
Christopher Leech2c5645c2008-08-26 04:27:02 -07002272 /* reprogram secondary unicast list */
Jiri Pirkoccffad252009-05-22 23:22:17 +00002273 hw->mac.ops.update_uc_addr_list(hw, &netdev->uc_list);
Auke Kok9a799d72007-09-15 14:07:45 -07002274
Christopher Leech2c5645c2008-08-26 04:27:02 -07002275 /* reprogram multicast list */
2276 addr_count = netdev->mc_count;
2277 if (addr_count)
2278 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002279 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2280 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002281}
2282
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002283static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2284{
2285 int q_idx;
2286 struct ixgbe_q_vector *q_vector;
2287 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2288
2289 /* legacy and MSI only use one vector */
2290 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2291 q_vectors = 1;
2292
2293 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002294 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002295 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002296 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002297 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2298 if (!q_vector->rxr_count || !q_vector->txr_count) {
2299 if (q_vector->txr_count == 1)
2300 napi->poll = &ixgbe_clean_txonly;
2301 else if (q_vector->rxr_count == 1)
2302 napi->poll = &ixgbe_clean_rxonly;
2303 }
2304 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002305
2306 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002307 }
2308}
2309
2310static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2311{
2312 int q_idx;
2313 struct ixgbe_q_vector *q_vector;
2314 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2315
2316 /* legacy and MSI only use one vector */
2317 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2318 q_vectors = 1;
2319
2320 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002321 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002322 napi_disable(&q_vector->napi);
2323 }
2324}
2325
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002326#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002327/*
2328 * ixgbe_configure_dcb - Configure DCB hardware
2329 * @adapter: ixgbe adapter struct
2330 *
2331 * This is called by the driver on open to configure the DCB hardware.
2332 * This is also called by the gennetlink interface when reconfiguring
2333 * the DCB state.
2334 */
2335static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2336{
2337 struct ixgbe_hw *hw = &adapter->hw;
2338 u32 txdctl, vlnctrl;
2339 int i, j;
2340
2341 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2342 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2343 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2344
2345 /* reconfigure the hardware */
2346 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2347
2348 for (i = 0; i < adapter->num_tx_queues; i++) {
2349 j = adapter->tx_ring[i].reg_idx;
2350 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2351 /* PThresh workaround for Tx hang with DFP enabled. */
2352 txdctl |= 32;
2353 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2354 }
2355 /* Enable VLAN tag insert/strip */
2356 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002357 if (hw->mac.type == ixgbe_mac_82598EB) {
2358 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2359 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2360 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2361 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2362 vlnctrl |= IXGBE_VLNCTRL_VFE;
2363 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2364 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2365 for (i = 0; i < adapter->num_rx_queues; i++) {
2366 j = adapter->rx_ring[i].reg_idx;
2367 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2368 vlnctrl |= IXGBE_RXDCTL_VME;
2369 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2370 }
2371 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08002372 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2373}
2374
2375#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002376static void ixgbe_configure(struct ixgbe_adapter *adapter)
2377{
2378 struct net_device *netdev = adapter->netdev;
2379 int i;
2380
Christopher Leech2c5645c2008-08-26 04:27:02 -07002381 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002382
2383 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002384#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002385 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2386 netif_set_gso_max_size(netdev, 32768);
2387 ixgbe_configure_dcb(adapter);
2388 } else {
2389 netif_set_gso_max_size(netdev, 65536);
2390 }
2391#else
2392 netif_set_gso_max_size(netdev, 65536);
2393#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002394
Yi Zoueacd73f2009-05-13 13:11:06 +00002395#ifdef IXGBE_FCOE
2396 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2397 ixgbe_configure_fcoe(adapter);
2398
2399#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07002400 ixgbe_configure_tx(adapter);
2401 ixgbe_configure_rx(adapter);
2402 for (i = 0; i < adapter->num_rx_queues; i++)
2403 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002404 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07002405}
2406
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002407static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2408{
2409 switch (hw->phy.type) {
2410 case ixgbe_phy_sfp_avago:
2411 case ixgbe_phy_sfp_ftl:
2412 case ixgbe_phy_sfp_intel:
2413 case ixgbe_phy_sfp_unknown:
2414 case ixgbe_phy_tw_tyco:
2415 case ixgbe_phy_tw_unknown:
2416 return true;
2417 default:
2418 return false;
2419 }
2420}
2421
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002422/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002423 * ixgbe_sfp_link_config - set up SFP+ link
2424 * @adapter: pointer to private adapter struct
2425 **/
2426static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2427{
2428 struct ixgbe_hw *hw = &adapter->hw;
2429
2430 if (hw->phy.multispeed_fiber) {
2431 /*
2432 * In multispeed fiber setups, the device may not have
2433 * had a physical connection when the driver loaded.
2434 * If that's the case, the initial link configuration
2435 * couldn't get the MAC into 10G or 1G mode, so we'll
2436 * never have a link status change interrupt fire.
2437 * We need to try and force an autonegotiation
2438 * session, then bring up link.
2439 */
2440 hw->mac.ops.setup_sfp(hw);
2441 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2442 schedule_work(&adapter->multispeed_fiber_task);
2443 } else {
2444 /*
2445 * Direct Attach Cu and non-multispeed fiber modules
2446 * still need to be configured properly prior to
2447 * attempting link.
2448 */
2449 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2450 schedule_work(&adapter->sfp_config_module_task);
2451 }
2452}
2453
2454/**
2455 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002456 * @hw: pointer to private hardware struct
2457 *
2458 * Returns 0 on success, negative on failure
2459 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002460static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002461{
2462 u32 autoneg;
2463 bool link_up = false;
2464 u32 ret = IXGBE_ERR_LINK_SETUP;
2465
2466 if (hw->mac.ops.check_link)
2467 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2468
2469 if (ret)
2470 goto link_cfg_out;
2471
2472 if (hw->mac.ops.get_link_capabilities)
2473 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
2474 &hw->mac.autoneg);
2475 if (ret)
2476 goto link_cfg_out;
2477
2478 if (hw->mac.ops.setup_link_speed)
2479 ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002480link_cfg_out:
2481 return ret;
2482}
2483
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002484#define IXGBE_MAX_RX_DESC_POLL 10
2485static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2486 int rxr)
2487{
2488 int j = adapter->rx_ring[rxr].reg_idx;
2489 int k;
2490
2491 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2492 if (IXGBE_READ_REG(&adapter->hw,
2493 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2494 break;
2495 else
2496 msleep(1);
2497 }
2498 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2499 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2500 "not set within the polling period\n", rxr);
2501 }
2502 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2503 (adapter->rx_ring[rxr].count - 1));
2504}
2505
Auke Kok9a799d72007-09-15 14:07:45 -07002506static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2507{
2508 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07002509 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002510 int i, j = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002511 int num_rx_rings = adapter->num_rx_queues;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002512 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002513 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002514 u32 txdctl, rxdctl, mhadd;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002515 u32 dmatxctl;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002516 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002517
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002518 ixgbe_get_hw_control(adapter);
2519
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002520 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2521 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002522 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2523 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002524 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002525 } else {
2526 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002527 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002528 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002529 /* XXX: to interrupt immediately for EICS writes, enable this */
2530 /* gpie |= IXGBE_GPIE_EIMEN; */
2531 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2532 }
2533
2534 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2535 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2536 * specifically only auto mask tx and rx interrupts */
2537 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002538 }
2539
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002540 /* Enable fan failure interrupt if media type is copper */
2541 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2542 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2543 gpie |= IXGBE_SDP1_GPIEN;
2544 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2545 }
2546
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002547 if (hw->mac.type == ixgbe_mac_82599EB) {
2548 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2549 gpie |= IXGBE_SDP1_GPIEN;
2550 gpie |= IXGBE_SDP2_GPIEN;
2551 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2552 }
2553
Yi Zou63f39bd2009-05-17 12:34:35 +00002554#ifdef IXGBE_FCOE
2555 /* adjust max frame to be able to do baby jumbo for FCoE */
2556 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
2557 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
2558 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
2559
2560#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07002561 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002562 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2563 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2564 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2565
2566 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2567 }
2568
2569 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002570 j = adapter->tx_ring[i].reg_idx;
2571 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002572 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2573 txdctl |= (8 << 16);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002574 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2575 }
2576
2577 if (hw->mac.type == ixgbe_mac_82599EB) {
2578 /* DMATXCTL.EN must be set after all Tx queue config is done */
2579 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2580 dmatxctl |= IXGBE_DMATXCTL_TE;
2581 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2582 }
2583 for (i = 0; i < adapter->num_tx_queues; i++) {
2584 j = adapter->tx_ring[i].reg_idx;
2585 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Auke Kok9a799d72007-09-15 14:07:45 -07002586 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002587 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002588 }
2589
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002590 for (i = 0; i < num_rx_rings; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002591 j = adapter->rx_ring[i].reg_idx;
2592 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2593 /* enable PTHRESH=32 descriptors (half the internal cache)
2594 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2595 * this also removes a pesky rx_no_buffer_count increment */
2596 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002597 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002598 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002599 if (hw->mac.type == ixgbe_mac_82599EB)
2600 ixgbe_rx_desc_queue_enable(adapter, i);
Auke Kok9a799d72007-09-15 14:07:45 -07002601 }
2602 /* enable all receives */
2603 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002604 if (hw->mac.type == ixgbe_mac_82598EB)
2605 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2606 else
2607 rxdctl |= IXGBE_RXCTRL_RXEN;
2608 hw->mac.ops.enable_rx_dma(hw, rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002609
2610 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2611 ixgbe_configure_msix(adapter);
2612 else
2613 ixgbe_configure_msi_and_legacy(adapter);
2614
2615 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002616 ixgbe_napi_enable_all(adapter);
2617
2618 /* clear any pending interrupts, may auto mask */
2619 IXGBE_READ_REG(hw, IXGBE_EICR);
2620
Auke Kok9a799d72007-09-15 14:07:45 -07002621 ixgbe_irq_enable(adapter);
2622
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002623 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00002624 * If this adapter has a fan, check to see if we had a failure
2625 * before we enabled the interrupt.
2626 */
2627 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2628 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2629 if (esdp & IXGBE_ESDP_SDP1)
2630 DPRINTK(DRV, CRIT,
2631 "Fan has stopped, replace the adapter\n");
2632 }
2633
2634 /*
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002635 * For hot-pluggable SFP+ devices, a new SFP+ module may have
2636 * arrived before interrupts were enabled. We need to kick off
2637 * the SFP+ module setup first, then try to bring up link.
2638 * If we're not hot-pluggable SFP+, we just need to configure link
2639 * and bring it up.
2640 */
2641 err = hw->phy.ops.identify(hw);
2642 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2643 DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err);
2644 ixgbe_down(adapter);
2645 return err;
2646 }
2647
2648 if (ixgbe_is_sfp(hw)) {
2649 ixgbe_sfp_link_config(adapter);
2650 } else {
2651 err = ixgbe_non_sfp_link_config(hw);
2652 if (err)
2653 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2654 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002655
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002656 /* enable transmits */
2657 netif_tx_start_all_queues(netdev);
2658
Auke Kok9a799d72007-09-15 14:07:45 -07002659 /* bring the link up in the watchdog, this could race with our first
2660 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002661 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2662 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002663 mod_timer(&adapter->watchdog_timer, jiffies);
2664 return 0;
2665}
2666
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002667void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2668{
2669 WARN_ON(in_interrupt());
2670 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2671 msleep(1);
2672 ixgbe_down(adapter);
2673 ixgbe_up(adapter);
2674 clear_bit(__IXGBE_RESETTING, &adapter->state);
2675}
2676
Auke Kok9a799d72007-09-15 14:07:45 -07002677int ixgbe_up(struct ixgbe_adapter *adapter)
2678{
2679 /* hardware has been reset, we need to reload some things */
2680 ixgbe_configure(adapter);
2681
2682 return ixgbe_up_complete(adapter);
2683}
2684
2685void ixgbe_reset(struct ixgbe_adapter *adapter)
2686{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002687 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07002688 int err;
2689
2690 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002691 switch (err) {
2692 case 0:
2693 case IXGBE_ERR_SFP_NOT_PRESENT:
2694 break;
2695 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
2696 dev_err(&adapter->pdev->dev, "master disable timed out\n");
2697 break;
2698 default:
2699 dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err);
2700 }
Auke Kok9a799d72007-09-15 14:07:45 -07002701
2702 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002703 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002704}
2705
Auke Kok9a799d72007-09-15 14:07:45 -07002706/**
2707 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2708 * @adapter: board private structure
2709 * @rx_ring: ring to free buffers from
2710 **/
2711static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002712 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002713{
2714 struct pci_dev *pdev = adapter->pdev;
2715 unsigned long size;
2716 unsigned int i;
2717
2718 /* Free all the Rx ring sk_buffs */
2719
2720 for (i = 0; i < rx_ring->count; i++) {
2721 struct ixgbe_rx_buffer *rx_buffer_info;
2722
2723 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2724 if (rx_buffer_info->dma) {
2725 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002726 rx_ring->rx_buf_len,
2727 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002728 rx_buffer_info->dma = 0;
2729 }
2730 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002731 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002732 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002733 do {
2734 struct sk_buff *this = skb;
2735 skb = skb->prev;
2736 dev_kfree_skb(this);
2737 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002738 }
2739 if (!rx_buffer_info->page)
2740 continue;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002741 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2742 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002743 rx_buffer_info->page_dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002744 put_page(rx_buffer_info->page);
2745 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002746 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002747 }
2748
2749 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2750 memset(rx_ring->rx_buffer_info, 0, size);
2751
2752 /* Zero out the descriptor ring */
2753 memset(rx_ring->desc, 0, rx_ring->size);
2754
2755 rx_ring->next_to_clean = 0;
2756 rx_ring->next_to_use = 0;
2757
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002758 if (rx_ring->head)
2759 writel(0, adapter->hw.hw_addr + rx_ring->head);
2760 if (rx_ring->tail)
2761 writel(0, adapter->hw.hw_addr + rx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002762}
2763
2764/**
2765 * ixgbe_clean_tx_ring - Free Tx Buffers
2766 * @adapter: board private structure
2767 * @tx_ring: ring to be cleaned
2768 **/
2769static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002770 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002771{
2772 struct ixgbe_tx_buffer *tx_buffer_info;
2773 unsigned long size;
2774 unsigned int i;
2775
2776 /* Free all the Tx ring sk_buffs */
2777
2778 for (i = 0; i < tx_ring->count; i++) {
2779 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2780 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2781 }
2782
2783 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2784 memset(tx_ring->tx_buffer_info, 0, size);
2785
2786 /* Zero out the descriptor ring */
2787 memset(tx_ring->desc, 0, tx_ring->size);
2788
2789 tx_ring->next_to_use = 0;
2790 tx_ring->next_to_clean = 0;
2791
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002792 if (tx_ring->head)
2793 writel(0, adapter->hw.hw_addr + tx_ring->head);
2794 if (tx_ring->tail)
2795 writel(0, adapter->hw.hw_addr + tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002796}
2797
2798/**
Auke Kok9a799d72007-09-15 14:07:45 -07002799 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2800 * @adapter: board private structure
2801 **/
2802static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2803{
2804 int i;
2805
2806 for (i = 0; i < adapter->num_rx_queues; i++)
2807 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2808}
2809
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002810/**
2811 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2812 * @adapter: board private structure
2813 **/
2814static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2815{
2816 int i;
2817
2818 for (i = 0; i < adapter->num_tx_queues; i++)
2819 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2820}
2821
Auke Kok9a799d72007-09-15 14:07:45 -07002822void ixgbe_down(struct ixgbe_adapter *adapter)
2823{
2824 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002825 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002826 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002827 u32 txdctl;
2828 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002829
2830 /* signal that we are down to the interrupt handler */
2831 set_bit(__IXGBE_DOWN, &adapter->state);
2832
2833 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002834 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2835 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002836
2837 netif_tx_disable(netdev);
2838
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002839 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002840 msleep(10);
2841
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002842 netif_tx_stop_all_queues(netdev);
2843
Auke Kok9a799d72007-09-15 14:07:45 -07002844 ixgbe_irq_disable(adapter);
2845
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002846 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002847
Auke Kok9a799d72007-09-15 14:07:45 -07002848 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002849 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002850
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002851 /* disable transmits in the hardware now that interrupts are off */
2852 for (i = 0; i < adapter->num_tx_queues; i++) {
2853 j = adapter->tx_ring[i].reg_idx;
2854 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2855 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2856 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2857 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00002858 /* Disable the Tx DMA engine on 82599 */
2859 if (hw->mac.type == ixgbe_mac_82599EB)
2860 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
2861 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
2862 ~IXGBE_DMATXCTL_TE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002863
Auke Kok9a799d72007-09-15 14:07:45 -07002864 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002865
Paul Larson6f4a0e42008-06-24 17:00:56 -07002866 if (!pci_channel_offline(adapter->pdev))
2867 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002868 ixgbe_clean_all_tx_rings(adapter);
2869 ixgbe_clean_all_rx_rings(adapter);
2870
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002871#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002872 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00002873 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002874#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002875}
2876
Auke Kok9a799d72007-09-15 14:07:45 -07002877/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002878 * ixgbe_poll - NAPI Rx polling callback
2879 * @napi: structure for representing this polling device
2880 * @budget: how many packets driver is allowed to clean
2881 *
2882 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002883 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002884static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002885{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002886 struct ixgbe_q_vector *q_vector =
2887 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002888 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002889 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002890
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002891#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002892 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2893 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2894 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2895 }
2896#endif
2897
Alexander Duyckfe49f042009-06-04 16:00:09 +00002898 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002899 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002900
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002901 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002902 work_done = budget;
2903
David S. Miller53e52c72008-01-07 21:06:12 -08002904 /* If budget not fully consumed, exit the polling mode */
2905 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002906 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002907 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002908 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002909 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00002910 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002911 }
Auke Kok9a799d72007-09-15 14:07:45 -07002912 return work_done;
2913}
2914
2915/**
2916 * ixgbe_tx_timeout - Respond to a Tx Hang
2917 * @netdev: network interface device structure
2918 **/
2919static void ixgbe_tx_timeout(struct net_device *netdev)
2920{
2921 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2922
2923 /* Do the reset outside of interrupt context */
2924 schedule_work(&adapter->reset_task);
2925}
2926
2927static void ixgbe_reset_task(struct work_struct *work)
2928{
2929 struct ixgbe_adapter *adapter;
2930 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2931
Alexander Duyck2f90b862008-11-20 20:52:10 -08002932 /* If we're already down or resetting, just bail */
2933 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2934 test_bit(__IXGBE_RESETTING, &adapter->state))
2935 return;
2936
Auke Kok9a799d72007-09-15 14:07:45 -07002937 adapter->tx_timeout_count++;
2938
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002939 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002940}
2941
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002942#ifdef CONFIG_IXGBE_DCB
2943static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002944{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002945 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002946 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002947
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002948 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
2949 return ret;
2950
2951 f->mask = 0x7 << 3;
2952 adapter->num_rx_queues = f->indices;
2953 adapter->num_tx_queues = f->indices;
2954 ret = true;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002955
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002956 return ret;
2957}
2958#endif
2959
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002960/**
2961 * ixgbe_set_rss_queues: Allocate queues for RSS
2962 * @adapter: board private structure to initialize
2963 *
2964 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
2965 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
2966 *
2967 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002968static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
2969{
2970 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002971 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002972
2973 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002974 f->mask = 0xF;
2975 adapter->num_rx_queues = f->indices;
2976 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002977 ret = true;
2978 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002979 ret = false;
2980 }
2981
2982 return ret;
2983}
2984
Yi Zou0331a832009-05-17 12:33:52 +00002985#ifdef IXGBE_FCOE
2986/**
2987 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
2988 * @adapter: board private structure to initialize
2989 *
2990 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
2991 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
2992 * rx queues out of the max number of rx queues, instead, it is used as the
2993 * index of the first rx queue used by FCoE.
2994 *
2995 **/
2996static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
2997{
2998 bool ret = false;
2999 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3000
3001 f->indices = min((int)num_online_cpus(), f->indices);
3002 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3003#ifdef CONFIG_IXGBE_DCB
3004 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3005 DPRINTK(PROBE, INFO, "FCOE enabled with DCB \n");
3006 ixgbe_set_dcb_queues(adapter);
3007 }
3008#endif
3009 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3010 DPRINTK(PROBE, INFO, "FCOE enabled with RSS \n");
3011 ixgbe_set_rss_queues(adapter);
3012 }
3013 /* adding FCoE rx rings to the end */
3014 f->mask = adapter->num_rx_queues;
3015 adapter->num_rx_queues += f->indices;
3016 if (adapter->num_tx_queues == 0)
3017 adapter->num_tx_queues = f->indices;
3018
3019 ret = true;
3020 }
3021
3022 return ret;
3023}
3024
3025#endif /* IXGBE_FCOE */
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003026/*
3027 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
3028 * @adapter: board private structure to initialize
3029 *
3030 * This is the top level queue allocation routine. The order here is very
3031 * important, starting with the "most" number of features turned on at once,
3032 * and ending with the smallest set of features. This way large combinations
3033 * can be allocated if they're turned on, and smaller combinations are the
3034 * fallthrough conditions.
3035 *
3036 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003037static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
3038{
Yi Zou0331a832009-05-17 12:33:52 +00003039#ifdef IXGBE_FCOE
3040 if (ixgbe_set_fcoe_queues(adapter))
3041 goto done;
3042
3043#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003044#ifdef CONFIG_IXGBE_DCB
3045 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003046 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003047
3048#endif
3049 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003050 goto done;
3051
3052 /* fallback to base case */
3053 adapter->num_rx_queues = 1;
3054 adapter->num_tx_queues = 1;
3055
3056done:
3057 /* Notify the stack of the (possibly) reduced Tx Queue count. */
3058 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003059}
3060
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003061static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003062 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003063{
3064 int err, vector_threshold;
3065
3066 /* We'll want at least 3 (vector_threshold):
3067 * 1) TxQ[0] Cleanup
3068 * 2) RxQ[0] Cleanup
3069 * 3) Other (Link Status Change, etc.)
3070 * 4) TCP Timer (optional)
3071 */
3072 vector_threshold = MIN_MSIX_COUNT;
3073
3074 /* The more we get, the more we will assign to Tx/Rx Cleanup
3075 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
3076 * Right now, we simply care about how many we'll get; we'll
3077 * set them up later while requesting irq's.
3078 */
3079 while (vectors >= vector_threshold) {
3080 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003081 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003082 if (!err) /* Success in acquiring all requested vectors. */
3083 break;
3084 else if (err < 0)
3085 vectors = 0; /* Nasty failure, quit now */
3086 else /* err == number of vectors we should try again with */
3087 vectors = err;
3088 }
3089
3090 if (vectors < vector_threshold) {
3091 /* Can't allocate enough MSI-X interrupts? Oh well.
3092 * This just means we'll go with either a single MSI
3093 * vector or fall back to legacy interrupts.
3094 */
3095 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
3096 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3097 kfree(adapter->msix_entries);
3098 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003099 } else {
3100 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08003101 /*
3102 * Adjust for only the vectors we'll use, which is minimum
3103 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
3104 * vectors we were allocated.
3105 */
3106 adapter->num_msix_vectors = min(vectors,
3107 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003108 }
3109}
3110
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003111/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003112 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003113 * @adapter: board private structure to initialize
3114 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003115 * Cache the descriptor ring offsets for RSS to the assigned rings.
3116 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003117 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003118static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003119{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003120 int i;
3121 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003122
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003123 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3124 for (i = 0; i < adapter->num_rx_queues; i++)
3125 adapter->rx_ring[i].reg_idx = i;
3126 for (i = 0; i < adapter->num_tx_queues; i++)
3127 adapter->tx_ring[i].reg_idx = i;
3128 ret = true;
3129 } else {
3130 ret = false;
3131 }
3132
3133 return ret;
3134}
3135
3136#ifdef CONFIG_IXGBE_DCB
3137/**
3138 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
3139 * @adapter: board private structure to initialize
3140 *
3141 * Cache the descriptor ring offsets for DCB to the assigned rings.
3142 *
3143 **/
3144static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
3145{
3146 int i;
3147 bool ret = false;
3148 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
3149
3150 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3151 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08003152 /* the number of queues is assumed to be symmetric */
3153 for (i = 0; i < dcb_i; i++) {
3154 adapter->rx_ring[i].reg_idx = i << 3;
3155 adapter->tx_ring[i].reg_idx = i << 2;
3156 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003157 ret = true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003158 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
PJ Waskiewiczf92ef202009-04-16 15:00:20 +00003159 if (dcb_i == 8) {
3160 /*
3161 * Tx TC0 starts at: descriptor queue 0
3162 * Tx TC1 starts at: descriptor queue 32
3163 * Tx TC2 starts at: descriptor queue 64
3164 * Tx TC3 starts at: descriptor queue 80
3165 * Tx TC4 starts at: descriptor queue 96
3166 * Tx TC5 starts at: descriptor queue 104
3167 * Tx TC6 starts at: descriptor queue 112
3168 * Tx TC7 starts at: descriptor queue 120
3169 *
3170 * Rx TC0-TC7 are offset by 16 queues each
3171 */
3172 for (i = 0; i < 3; i++) {
3173 adapter->tx_ring[i].reg_idx = i << 5;
3174 adapter->rx_ring[i].reg_idx = i << 4;
3175 }
3176 for ( ; i < 5; i++) {
3177 adapter->tx_ring[i].reg_idx =
3178 ((i + 2) << 4);
3179 adapter->rx_ring[i].reg_idx = i << 4;
3180 }
3181 for ( ; i < dcb_i; i++) {
3182 adapter->tx_ring[i].reg_idx =
3183 ((i + 8) << 3);
3184 adapter->rx_ring[i].reg_idx = i << 4;
3185 }
3186
3187 ret = true;
3188 } else if (dcb_i == 4) {
3189 /*
3190 * Tx TC0 starts at: descriptor queue 0
3191 * Tx TC1 starts at: descriptor queue 64
3192 * Tx TC2 starts at: descriptor queue 96
3193 * Tx TC3 starts at: descriptor queue 112
3194 *
3195 * Rx TC0-TC3 are offset by 32 queues each
3196 */
3197 adapter->tx_ring[0].reg_idx = 0;
3198 adapter->tx_ring[1].reg_idx = 64;
3199 adapter->tx_ring[2].reg_idx = 96;
3200 adapter->tx_ring[3].reg_idx = 112;
3201 for (i = 0 ; i < dcb_i; i++)
3202 adapter->rx_ring[i].reg_idx = i << 5;
3203
3204 ret = true;
3205 } else {
3206 ret = false;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003207 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003208 } else {
3209 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003210 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003211 } else {
3212 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003213 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003214
3215 return ret;
3216}
3217#endif
3218
Yi Zou0331a832009-05-17 12:33:52 +00003219#ifdef IXGBE_FCOE
3220/**
3221 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
3222 * @adapter: board private structure to initialize
3223 *
3224 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
3225 *
3226 */
3227static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
3228{
3229 int i, fcoe_i = 0;
3230 bool ret = false;
3231 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3232
3233 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3234#ifdef CONFIG_IXGBE_DCB
3235 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3236 ixgbe_cache_ring_dcb(adapter);
3237 fcoe_i = adapter->rx_ring[0].reg_idx + 1;
3238 }
3239#endif /* CONFIG_IXGBE_DCB */
3240 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3241 ixgbe_cache_ring_rss(adapter);
3242 fcoe_i = f->mask;
3243 }
3244 for (i = 0; i < f->indices; i++, fcoe_i++)
3245 adapter->rx_ring[f->mask + i].reg_idx = fcoe_i;
3246 ret = true;
3247 }
3248 return ret;
3249}
3250
3251#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003252/**
3253 * ixgbe_cache_ring_register - Descriptor ring to register mapping
3254 * @adapter: board private structure to initialize
3255 *
3256 * Once we know the feature-set enabled for the device, we'll cache
3257 * the register offset the descriptor ring is assigned to.
3258 *
3259 * Note, the order the various feature calls is important. It must start with
3260 * the "most" features enabled at the same time, then trickle down to the
3261 * least amount of features turned on at once.
3262 **/
3263static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
3264{
3265 /* start with default case */
3266 adapter->rx_ring[0].reg_idx = 0;
3267 adapter->tx_ring[0].reg_idx = 0;
3268
Yi Zou0331a832009-05-17 12:33:52 +00003269#ifdef IXGBE_FCOE
3270 if (ixgbe_cache_ring_fcoe(adapter))
3271 return;
3272
3273#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003274#ifdef CONFIG_IXGBE_DCB
3275 if (ixgbe_cache_ring_dcb(adapter))
3276 return;
3277
3278#endif
3279 if (ixgbe_cache_ring_rss(adapter))
3280 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003281}
3282
Auke Kok9a799d72007-09-15 14:07:45 -07003283/**
3284 * ixgbe_alloc_queues - Allocate memory for all rings
3285 * @adapter: board private structure to initialize
3286 *
3287 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003288 * number of queues at compile-time. The polling_netdev array is
3289 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07003290 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003291static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003292{
3293 int i;
3294
3295 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003296 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07003297 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003298 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07003299
3300 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003301 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003302 if (!adapter->rx_ring)
3303 goto err_rx_ring_allocation;
3304
3305 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003306 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003307 adapter->tx_ring[i].queue_index = i;
3308 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003309
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003310 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003311 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003312 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07003313 }
3314
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003315 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003316
3317 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003318
3319err_rx_ring_allocation:
3320 kfree(adapter->tx_ring);
3321err_tx_ring_allocation:
3322 return -ENOMEM;
3323}
3324
3325/**
3326 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3327 * @adapter: board private structure to initialize
3328 *
3329 * Attempt to configure the interrupts using the best available
3330 * capabilities of the hardware and the kernel.
3331 **/
Al Virofeea6a52008-11-27 15:34:07 -08003332static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003333{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003334 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003335 int err = 0;
3336 int vector, v_budget;
3337
3338 /*
3339 * It's easy to be greedy for MSI-X vectors, but it really
3340 * doesn't do us much good if we have a lot more vectors
3341 * than CPU's. So let's be conservative and only ask for
3342 * (roughly) twice the number of vectors as there are CPU's.
3343 */
3344 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003345 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003346
3347 /*
3348 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003349 * hw.mac->max_msix_vectors vectors. With features
3350 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3351 * descriptor queues supported by our device. Thus, we cap it off in
3352 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003353 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003354 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003355
3356 /* A failure in MSI-X entry allocation isn't fatal, but it does
3357 * mean we disable MSI-X capabilities of the adapter. */
3358 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003359 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003360 if (adapter->msix_entries) {
3361 for (vector = 0; vector < v_budget; vector++)
3362 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003363
Alexander Duyck7a921c92009-05-06 10:43:28 +00003364 ixgbe_acquire_msix_vectors(adapter, v_budget);
3365
3366 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3367 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003368 }
3369
Alexander Duyck7a921c92009-05-06 10:43:28 +00003370 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
3371 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
3372 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003373
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003374 err = pci_enable_msi(adapter->pdev);
3375 if (!err) {
3376 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
3377 } else {
3378 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003379 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003380 /* reset err */
3381 err = 0;
3382 }
3383
3384out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003385 return err;
3386}
3387
Alexander Duyck7a921c92009-05-06 10:43:28 +00003388/**
3389 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
3390 * @adapter: board private structure to initialize
3391 *
3392 * We allocate one q_vector per queue interrupt. If allocation fails we
3393 * return -ENOMEM.
3394 **/
3395static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
3396{
3397 int q_idx, num_q_vectors;
3398 struct ixgbe_q_vector *q_vector;
3399 int napi_vectors;
3400 int (*poll)(struct napi_struct *, int);
3401
3402 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3403 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3404 napi_vectors = adapter->num_rx_queues;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003405 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003406 } else {
3407 num_q_vectors = 1;
3408 napi_vectors = 1;
3409 poll = &ixgbe_poll;
3410 }
3411
3412 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3413 q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL);
3414 if (!q_vector)
3415 goto err_out;
3416 q_vector->adapter = adapter;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003417 q_vector->eitr = adapter->eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00003418 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003419 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003420 adapter->q_vector[q_idx] = q_vector;
3421 }
3422
3423 return 0;
3424
3425err_out:
3426 while (q_idx) {
3427 q_idx--;
3428 q_vector = adapter->q_vector[q_idx];
3429 netif_napi_del(&q_vector->napi);
3430 kfree(q_vector);
3431 adapter->q_vector[q_idx] = NULL;
3432 }
3433 return -ENOMEM;
3434}
3435
3436/**
3437 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
3438 * @adapter: board private structure to initialize
3439 *
3440 * This function frees the memory allocated to the q_vectors. In addition if
3441 * NAPI is enabled it will delete any references to the NAPI struct prior
3442 * to freeing the q_vector.
3443 **/
3444static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
3445{
3446 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003447
Alexander Duyck91281fd2009-06-04 16:00:27 +00003448 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00003449 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003450 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00003451 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003452
3453 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3454 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00003455 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003456 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003457 kfree(q_vector);
3458 }
3459}
3460
Alexander Duyck2f90b862008-11-20 20:52:10 -08003461void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003462{
3463 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3464 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3465 pci_disable_msix(adapter->pdev);
3466 kfree(adapter->msix_entries);
3467 adapter->msix_entries = NULL;
3468 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
3469 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
3470 pci_disable_msi(adapter->pdev);
3471 }
3472 return;
3473}
3474
3475/**
3476 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3477 * @adapter: board private structure to initialize
3478 *
3479 * We determine which interrupt scheme to use based on...
3480 * - Kernel support (MSI, MSI-X)
3481 * - which can be user-defined (via MODULE_PARAM)
3482 * - Hardware queue count (num_*_queues)
3483 * - defined by miscellaneous hardware support/features (RSS, etc.)
3484 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003485int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003486{
3487 int err;
3488
3489 /* Number of supported queues */
3490 ixgbe_set_num_queues(adapter);
3491
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003492 err = ixgbe_set_interrupt_capability(adapter);
3493 if (err) {
3494 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3495 goto err_set_interrupt;
3496 }
3497
Alexander Duyck7a921c92009-05-06 10:43:28 +00003498 err = ixgbe_alloc_q_vectors(adapter);
3499 if (err) {
3500 DPRINTK(PROBE, ERR, "Unable to allocate memory for queue "
3501 "vectors\n");
3502 goto err_alloc_q_vectors;
3503 }
3504
3505 err = ixgbe_alloc_queues(adapter);
3506 if (err) {
3507 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3508 goto err_alloc_queues;
3509 }
3510
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003511 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003512 "Tx Queue count = %u\n",
3513 (adapter->num_rx_queues > 1) ? "Enabled" :
3514 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003515
3516 set_bit(__IXGBE_DOWN, &adapter->state);
3517
3518 return 0;
3519
Alexander Duyck7a921c92009-05-06 10:43:28 +00003520err_alloc_queues:
3521 ixgbe_free_q_vectors(adapter);
3522err_alloc_q_vectors:
3523 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003524err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00003525 return err;
3526}
3527
3528/**
3529 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
3530 * @adapter: board private structure to clear interrupt scheme on
3531 *
3532 * We go through and clear interrupt specific resources and reset the structure
3533 * to pre-load conditions
3534 **/
3535void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
3536{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003537 kfree(adapter->tx_ring);
3538 kfree(adapter->rx_ring);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003539 adapter->tx_ring = NULL;
3540 adapter->rx_ring = NULL;
3541
3542 ixgbe_free_q_vectors(adapter);
3543 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003544}
3545
3546/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08003547 * ixgbe_sfp_timer - worker thread to find a missing module
3548 * @data: pointer to our adapter struct
3549 **/
3550static void ixgbe_sfp_timer(unsigned long data)
3551{
3552 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3553
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003554 /*
3555 * Do the sfp_timer outside of interrupt context due to the
Donald Skidmorec4900be2008-11-20 21:11:42 -08003556 * delays that sfp+ detection requires
3557 */
3558 schedule_work(&adapter->sfp_task);
3559}
3560
3561/**
3562 * ixgbe_sfp_task - worker thread to find a missing module
3563 * @work: pointer to work_struct containing our data
3564 **/
3565static void ixgbe_sfp_task(struct work_struct *work)
3566{
3567 struct ixgbe_adapter *adapter = container_of(work,
3568 struct ixgbe_adapter,
3569 sfp_task);
3570 struct ixgbe_hw *hw = &adapter->hw;
3571
3572 if ((hw->phy.type == ixgbe_phy_nl) &&
3573 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3574 s32 ret = hw->phy.ops.identify_sfp(hw);
3575 if (ret)
3576 goto reschedule;
3577 ret = hw->phy.ops.reset(hw);
3578 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
3579 DPRINTK(PROBE, ERR, "failed to initialize because an "
3580 "unsupported SFP+ module type was detected.\n"
3581 "Reload the driver after installing a "
3582 "supported module.\n");
3583 unregister_netdev(adapter->netdev);
3584 } else {
3585 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3586 hw->phy.sfp_type);
3587 }
3588 /* don't need this routine any more */
3589 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3590 }
3591 return;
3592reschedule:
3593 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3594 mod_timer(&adapter->sfp_timer,
3595 round_jiffies(jiffies + (2 * HZ)));
3596}
3597
3598/**
Auke Kok9a799d72007-09-15 14:07:45 -07003599 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3600 * @adapter: board private structure to initialize
3601 *
3602 * ixgbe_sw_init initializes the Adapter private data structure.
3603 * Fields are initialized based on PCI device information and
3604 * OS network device settings (MTU size).
3605 **/
3606static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3607{
3608 struct ixgbe_hw *hw = &adapter->hw;
3609 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003610 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003611#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003612 int j;
3613 struct tc_configuration *tc;
3614#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003615
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003616 /* PCI config space info */
3617
3618 hw->vendor_id = pdev->vendor;
3619 hw->device_id = pdev->device;
3620 hw->revision_id = pdev->revision;
3621 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3622 hw->subsystem_device_id = pdev->subsystem_device;
3623
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003624 /* Set capability flags */
3625 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3626 adapter->ring_feature[RING_F_RSS].indices = rss;
3627 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003628 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Don Skidmorebf069c92009-05-07 10:39:54 +00003629 if (hw->mac.type == ixgbe_mac_82598EB) {
3630 if (hw->device_id == IXGBE_DEV_ID_82598AT)
3631 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003632 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Don Skidmorebf069c92009-05-07 10:39:54 +00003633 } else if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003634 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00003635 adapter->flags |= IXGBE_FLAG2_RSC_CAPABLE;
3636 adapter->flags |= IXGBE_FLAG2_RSC_ENABLED;
Yi Zoueacd73f2009-05-13 13:11:06 +00003637#ifdef IXGBE_FCOE
3638 adapter->flags |= IXGBE_FLAG_FCOE_ENABLED;
Yi Zou0331a832009-05-17 12:33:52 +00003639 adapter->ring_feature[RING_F_FCOE].indices = IXGBE_FCRETA_SIZE;
Yi Zoueacd73f2009-05-13 13:11:06 +00003640#endif /* IXGBE_FCOE */
Alexander Duyckf8212f92009-04-27 22:42:37 +00003641 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003642
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003643#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003644 /* Configure DCB traffic classes */
3645 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3646 tc = &adapter->dcb_cfg.tc_config[j];
3647 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3648 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3649 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3650 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3651 tc->dcb_pfc = pfc_disabled;
3652 }
3653 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3654 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3655 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003656 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003657 adapter->dcb_cfg.round_robin_enable = false;
3658 adapter->dcb_set_bitmap = 0x00;
3659 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3660 adapter->ring_feature[RING_F_DCB].indices);
3661
3662#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003663
3664 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00003665 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00003666 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003667#ifdef CONFIG_DCB
3668 adapter->last_lfc_mode = hw->fc.current_mode;
3669#endif
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07003670 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3671 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3672 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3673 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00003674 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07003675
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07003676 /* enable itr by default in dynamic mode */
3677 adapter->itr_setting = 1;
3678 adapter->eitr_param = 20000;
3679
3680 /* set defaults for eitr in MegaBytes */
3681 adapter->eitr_low = 10;
3682 adapter->eitr_high = 20;
3683
3684 /* set default ring sizes */
3685 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
3686 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
3687
Auke Kok9a799d72007-09-15 14:07:45 -07003688 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003689 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003690 dev_err(&pdev->dev, "EEPROM initialization failed\n");
3691 return -EIO;
3692 }
3693
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003694 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07003695 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
3696
Auke Kok9a799d72007-09-15 14:07:45 -07003697 set_bit(__IXGBE_DOWN, &adapter->state);
3698
3699 return 0;
3700}
3701
3702/**
3703 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3704 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003705 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003706 *
3707 * Return 0 on success, negative on failure
3708 **/
3709int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003710 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003711{
3712 struct pci_dev *pdev = adapter->pdev;
3713 int size;
3714
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003715 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3716 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003717 if (!tx_ring->tx_buffer_info)
3718 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003719 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003720
3721 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08003722 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003723 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003724
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003725 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
3726 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003727 if (!tx_ring->desc)
3728 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07003729
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003730 tx_ring->next_to_use = 0;
3731 tx_ring->next_to_clean = 0;
3732 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07003733 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003734
3735err:
3736 vfree(tx_ring->tx_buffer_info);
3737 tx_ring->tx_buffer_info = NULL;
3738 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
3739 "descriptor ring\n");
3740 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003741}
3742
3743/**
Alexander Duyck69888672008-09-11 20:05:39 -07003744 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
3745 * @adapter: board private structure
3746 *
3747 * If this function returns with an error, then it's possible one or
3748 * more of the rings is populated (while the rest are not). It is the
3749 * callers duty to clean those orphaned rings.
3750 *
3751 * Return 0 on success, negative on failure
3752 **/
3753static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
3754{
3755 int i, err = 0;
3756
3757 for (i = 0; i < adapter->num_tx_queues; i++) {
3758 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
3759 if (!err)
3760 continue;
3761 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
3762 break;
3763 }
3764
3765 return err;
3766}
3767
3768/**
Auke Kok9a799d72007-09-15 14:07:45 -07003769 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
3770 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003771 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003772 *
3773 * Returns 0 on success, negative on failure
3774 **/
3775int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003776 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003777{
3778 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003779 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07003780
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003781 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
3782 rx_ring->rx_buffer_info = vmalloc(size);
3783 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07003784 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003785 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003786 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003787 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003788 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003789
Auke Kok9a799d72007-09-15 14:07:45 -07003790 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003791 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
3792 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003793
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003794 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07003795
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003796 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07003797 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003798 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003799 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003800 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003801 }
3802
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003803 rx_ring->next_to_clean = 0;
3804 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003805
3806 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003807
3808alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003809 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003810}
3811
3812/**
Alexander Duyck69888672008-09-11 20:05:39 -07003813 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
3814 * @adapter: board private structure
3815 *
3816 * If this function returns with an error, then it's possible one or
3817 * more of the rings is populated (while the rest are not). It is the
3818 * callers duty to clean those orphaned rings.
3819 *
3820 * Return 0 on success, negative on failure
3821 **/
3822
3823static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
3824{
3825 int i, err = 0;
3826
3827 for (i = 0; i < adapter->num_rx_queues; i++) {
3828 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
3829 if (!err)
3830 continue;
3831 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
3832 break;
3833 }
3834
3835 return err;
3836}
3837
3838/**
Auke Kok9a799d72007-09-15 14:07:45 -07003839 * ixgbe_free_tx_resources - Free Tx Resources per Queue
3840 * @adapter: board private structure
3841 * @tx_ring: Tx descriptor ring for a specific queue
3842 *
3843 * Free all transmit software resources
3844 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003845void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
3846 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003847{
3848 struct pci_dev *pdev = adapter->pdev;
3849
3850 ixgbe_clean_tx_ring(adapter, tx_ring);
3851
3852 vfree(tx_ring->tx_buffer_info);
3853 tx_ring->tx_buffer_info = NULL;
3854
3855 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
3856
3857 tx_ring->desc = NULL;
3858}
3859
3860/**
3861 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
3862 * @adapter: board private structure
3863 *
3864 * Free all transmit software resources
3865 **/
3866static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
3867{
3868 int i;
3869
3870 for (i = 0; i < adapter->num_tx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00003871 if (adapter->tx_ring[i].desc)
3872 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003873}
3874
3875/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003876 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07003877 * @adapter: board private structure
3878 * @rx_ring: ring to clean the resources from
3879 *
3880 * Free all receive software resources
3881 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003882void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
3883 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003884{
3885 struct pci_dev *pdev = adapter->pdev;
3886
3887 ixgbe_clean_rx_ring(adapter, rx_ring);
3888
3889 vfree(rx_ring->rx_buffer_info);
3890 rx_ring->rx_buffer_info = NULL;
3891
3892 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
3893
3894 rx_ring->desc = NULL;
3895}
3896
3897/**
3898 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
3899 * @adapter: board private structure
3900 *
3901 * Free all receive software resources
3902 **/
3903static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
3904{
3905 int i;
3906
3907 for (i = 0; i < adapter->num_rx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00003908 if (adapter->rx_ring[i].desc)
3909 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003910}
3911
3912/**
Auke Kok9a799d72007-09-15 14:07:45 -07003913 * ixgbe_change_mtu - Change the Maximum Transfer Unit
3914 * @netdev: network interface device structure
3915 * @new_mtu: new value for maximum frame size
3916 *
3917 * Returns 0 on success, negative on failure
3918 **/
3919static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
3920{
3921 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3922 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3923
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07003924 /* MTU < 68 is an error and causes problems on some kernels */
3925 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07003926 return -EINVAL;
3927
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003928 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003929 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003930 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07003931 netdev->mtu = new_mtu;
3932
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003933 if (netif_running(netdev))
3934 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003935
3936 return 0;
3937}
3938
3939/**
3940 * ixgbe_open - Called when a network interface is made active
3941 * @netdev: network interface device structure
3942 *
3943 * Returns 0 on success, negative value on failure
3944 *
3945 * The open entry point is called when a network interface is made
3946 * active by the system (IFF_UP). At this point all resources needed
3947 * for transmit and receive operations are allocated, the interrupt
3948 * handler is registered with the OS, the watchdog timer is started,
3949 * and the stack is notified that the interface is ready.
3950 **/
3951static int ixgbe_open(struct net_device *netdev)
3952{
3953 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3954 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003955
Auke Kok4bebfaa2008-02-11 09:26:01 -08003956 /* disallow open during test */
3957 if (test_bit(__IXGBE_TESTING, &adapter->state))
3958 return -EBUSY;
3959
Jesse Brandeburg54386462009-04-17 20:44:27 +00003960 netif_carrier_off(netdev);
3961
Auke Kok9a799d72007-09-15 14:07:45 -07003962 /* allocate transmit descriptors */
3963 err = ixgbe_setup_all_tx_resources(adapter);
3964 if (err)
3965 goto err_setup_tx;
3966
Auke Kok9a799d72007-09-15 14:07:45 -07003967 /* allocate receive descriptors */
3968 err = ixgbe_setup_all_rx_resources(adapter);
3969 if (err)
3970 goto err_setup_rx;
3971
3972 ixgbe_configure(adapter);
3973
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003974 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003975 if (err)
3976 goto err_req_irq;
3977
Auke Kok9a799d72007-09-15 14:07:45 -07003978 err = ixgbe_up_complete(adapter);
3979 if (err)
3980 goto err_up;
3981
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003982 netif_tx_start_all_queues(netdev);
3983
Auke Kok9a799d72007-09-15 14:07:45 -07003984 return 0;
3985
3986err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003987 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003988 ixgbe_free_irq(adapter);
3989err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07003990err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00003991 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003992err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00003993 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003994 ixgbe_reset(adapter);
3995
3996 return err;
3997}
3998
3999/**
4000 * ixgbe_close - Disables a network interface
4001 * @netdev: network interface device structure
4002 *
4003 * Returns 0, this is not allowed to fail
4004 *
4005 * The close entry point is called when an interface is de-activated
4006 * by the OS. The hardware is still under the drivers control, but
4007 * needs to be disabled. A global MAC reset is issued to stop the
4008 * hardware, and all transmit and receive resources are freed.
4009 **/
4010static int ixgbe_close(struct net_device *netdev)
4011{
4012 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004013
4014 ixgbe_down(adapter);
4015 ixgbe_free_irq(adapter);
4016
4017 ixgbe_free_all_tx_resources(adapter);
4018 ixgbe_free_all_rx_resources(adapter);
4019
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004020 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004021
4022 return 0;
4023}
4024
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004025#ifdef CONFIG_PM
4026static int ixgbe_resume(struct pci_dev *pdev)
4027{
4028 struct net_device *netdev = pci_get_drvdata(pdev);
4029 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4030 u32 err;
4031
4032 pci_set_power_state(pdev, PCI_D0);
4033 pci_restore_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004034
4035 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004036 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07004037 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004038 "suspend\n");
4039 return err;
4040 }
4041 pci_set_master(pdev);
4042
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004043 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004044
4045 err = ixgbe_init_interrupt_scheme(adapter);
4046 if (err) {
4047 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
4048 "device\n");
4049 return err;
4050 }
4051
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004052 ixgbe_reset(adapter);
4053
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00004054 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4055
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004056 if (netif_running(netdev)) {
4057 err = ixgbe_open(adapter->netdev);
4058 if (err)
4059 return err;
4060 }
4061
4062 netif_device_attach(netdev);
4063
4064 return 0;
4065}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004066#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004067
4068static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004069{
4070 struct net_device *netdev = pci_get_drvdata(pdev);
4071 struct ixgbe_adapter *adapter = netdev_priv(netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004072 struct ixgbe_hw *hw = &adapter->hw;
4073 u32 ctrl, fctrl;
4074 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004075#ifdef CONFIG_PM
4076 int retval = 0;
4077#endif
4078
4079 netif_device_detach(netdev);
4080
4081 if (netif_running(netdev)) {
4082 ixgbe_down(adapter);
4083 ixgbe_free_irq(adapter);
4084 ixgbe_free_all_tx_resources(adapter);
4085 ixgbe_free_all_rx_resources(adapter);
4086 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00004087 ixgbe_clear_interrupt_scheme(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004088
4089#ifdef CONFIG_PM
4090 retval = pci_save_state(pdev);
4091 if (retval)
4092 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004093
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004094#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004095 if (wufc) {
4096 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004097
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004098 /* turn on all-multi mode if wake on multicast is enabled */
4099 if (wufc & IXGBE_WUFC_MC) {
4100 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4101 fctrl |= IXGBE_FCTRL_MPE;
4102 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4103 }
4104
4105 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4106 ctrl |= IXGBE_CTRL_GIO_DIS;
4107 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4108
4109 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4110 } else {
4111 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4112 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4113 }
4114
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004115 if (wufc && hw->mac.type == ixgbe_mac_82599EB)
4116 pci_wake_from_d3(pdev, true);
4117 else
4118 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004119
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004120 *enable_wake = !!wufc;
4121
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004122 ixgbe_release_hw_control(adapter);
4123
4124 pci_disable_device(pdev);
4125
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004126 return 0;
4127}
4128
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004129#ifdef CONFIG_PM
4130static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4131{
4132 int retval;
4133 bool wake;
4134
4135 retval = __ixgbe_shutdown(pdev, &wake);
4136 if (retval)
4137 return retval;
4138
4139 if (wake) {
4140 pci_prepare_to_sleep(pdev);
4141 } else {
4142 pci_wake_from_d3(pdev, false);
4143 pci_set_power_state(pdev, PCI_D3hot);
4144 }
4145
4146 return 0;
4147}
4148#endif /* CONFIG_PM */
4149
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004150static void ixgbe_shutdown(struct pci_dev *pdev)
4151{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004152 bool wake;
4153
4154 __ixgbe_shutdown(pdev, &wake);
4155
4156 if (system_state == SYSTEM_POWER_OFF) {
4157 pci_wake_from_d3(pdev, wake);
4158 pci_set_power_state(pdev, PCI_D3hot);
4159 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004160}
4161
4162/**
Auke Kok9a799d72007-09-15 14:07:45 -07004163 * ixgbe_update_stats - Update the board statistics counters.
4164 * @adapter: board private structure
4165 **/
4166void ixgbe_update_stats(struct ixgbe_adapter *adapter)
4167{
4168 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004169 u64 total_mpc = 0;
4170 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004171
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004172 if (hw->mac.type == ixgbe_mac_82599EB) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004173 u64 rsc_count = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004174 for (i = 0; i < 16; i++)
4175 adapter->hw_rx_no_dma_resources +=
4176 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Alexander Duyckf8212f92009-04-27 22:42:37 +00004177 for (i = 0; i < adapter->num_rx_queues; i++)
4178 rsc_count += adapter->rx_ring[i].rsc_count;
4179 adapter->rsc_count = rsc_count;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004180 }
4181
Auke Kok9a799d72007-09-15 14:07:45 -07004182 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004183 for (i = 0; i < 8; i++) {
4184 /* for packet buffers not used, the register should read 0 */
4185 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
4186 missed_rx += mpc;
4187 adapter->stats.mpc[i] += mpc;
4188 total_mpc += adapter->stats.mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004189 if (hw->mac.type == ixgbe_mac_82598EB)
4190 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004191 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
4192 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
4193 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
4194 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004195 if (hw->mac.type == ixgbe_mac_82599EB) {
4196 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4197 IXGBE_PXONRXCNT(i));
4198 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4199 IXGBE_PXOFFRXCNT(i));
4200 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004201 } else {
4202 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4203 IXGBE_PXONRXC(i));
4204 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4205 IXGBE_PXOFFRXC(i));
4206 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004207 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
4208 IXGBE_PXONTXC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004209 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004210 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004211 }
4212 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
4213 /* work around hardware counting issue */
4214 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07004215
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004216 /* 82598 hardware only has a 32 bit counter in the high register */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004217 if (hw->mac.type == ixgbe_mac_82599EB) {
4218 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
4219 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
4220 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
4221 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
4222 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
4223 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
4224 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
4225 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
Yi Zou6d455222009-05-13 13:12:16 +00004226#ifdef IXGBE_FCOE
4227 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
4228 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
4229 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
4230 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
4231 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
4232 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
4233#endif /* IXGBE_FCOE */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004234 } else {
4235 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
4236 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
4237 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
4238 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
4239 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
4240 }
Auke Kok9a799d72007-09-15 14:07:45 -07004241 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
4242 adapter->stats.bprc += bprc;
4243 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004244 if (hw->mac.type == ixgbe_mac_82598EB)
4245 adapter->stats.mprc -= bprc;
Auke Kok9a799d72007-09-15 14:07:45 -07004246 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
4247 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
4248 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
4249 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
4250 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
4251 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
4252 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004253 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004254 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
4255 adapter->stats.lxontxc += lxon;
4256 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
4257 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07004258 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4259 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004260 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
4261 /*
4262 * 82598 errata - tx of flow control packets is included in tx counters
4263 */
4264 xon_off_tot = lxon + lxoff;
4265 adapter->stats.gptc -= xon_off_tot;
4266 adapter->stats.mptc -= xon_off_tot;
4267 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07004268 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4269 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
4270 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07004271 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
4272 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004273 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004274 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
4275 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
4276 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
4277 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
4278 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004279 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
4280
4281 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07004282 adapter->net_stats.multicast = adapter->stats.mprc;
4283
4284 /* Rx Errors */
4285 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004286 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07004287 adapter->net_stats.rx_dropped = 0;
4288 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
4289 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004290 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07004291}
4292
4293/**
4294 * ixgbe_watchdog - Timer Call-back
4295 * @data: pointer to adapter cast into an unsigned long
4296 **/
4297static void ixgbe_watchdog(unsigned long data)
4298{
4299 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004300 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004301 u64 eics = 0;
4302 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004303
Alexander Duyckfe49f042009-06-04 16:00:09 +00004304 /*
4305 * Do the watchdog outside of interrupt context due to the lovely
4306 * delays that some of the newer hardware requires
4307 */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004308
Alexander Duyckfe49f042009-06-04 16:00:09 +00004309 if (test_bit(__IXGBE_DOWN, &adapter->state))
4310 goto watchdog_short_circuit;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004311
Alexander Duyckfe49f042009-06-04 16:00:09 +00004312 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
4313 /*
4314 * for legacy and MSI interrupts don't set any bits
4315 * that are enabled for EIAM, because this operation
4316 * would set *both* EIMS and EICS for any bit in EIAM
4317 */
4318 IXGBE_WRITE_REG(hw, IXGBE_EICS,
4319 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
4320 goto watchdog_reschedule;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004321 }
4322
Alexander Duyckfe49f042009-06-04 16:00:09 +00004323 /* get one bit for every active tx/rx interrupt vector */
4324 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
4325 struct ixgbe_q_vector *qv = adapter->q_vector[i];
4326 if (qv->rxr_count || qv->txr_count)
4327 eics |= ((u64)1 << i);
4328 }
4329
4330 /* Cause software interrupt to ensure rx rings are cleaned */
4331 ixgbe_irq_rearm_queues(adapter, eics);
4332
4333watchdog_reschedule:
4334 /* Reset the timer */
4335 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
4336
4337watchdog_short_circuit:
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004338 schedule_work(&adapter->watchdog_task);
4339}
4340
4341/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004342 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
4343 * @work: pointer to work_struct containing our data
4344 **/
4345static void ixgbe_multispeed_fiber_task(struct work_struct *work)
4346{
4347 struct ixgbe_adapter *adapter = container_of(work,
4348 struct ixgbe_adapter,
4349 multispeed_fiber_task);
4350 struct ixgbe_hw *hw = &adapter->hw;
4351 u32 autoneg;
4352
4353 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
4354 if (hw->mac.ops.get_link_capabilities)
4355 hw->mac.ops.get_link_capabilities(hw, &autoneg,
4356 &hw->mac.autoneg);
4357 if (hw->mac.ops.setup_link_speed)
4358 hw->mac.ops.setup_link_speed(hw, autoneg, true, true);
4359 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4360 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
4361}
4362
4363/**
4364 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
4365 * @work: pointer to work_struct containing our data
4366 **/
4367static void ixgbe_sfp_config_module_task(struct work_struct *work)
4368{
4369 struct ixgbe_adapter *adapter = container_of(work,
4370 struct ixgbe_adapter,
4371 sfp_config_module_task);
4372 struct ixgbe_hw *hw = &adapter->hw;
4373 u32 err;
4374
4375 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
4376 err = hw->phy.ops.identify_sfp(hw);
4377 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4378 DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err);
4379 ixgbe_down(adapter);
4380 return;
4381 }
4382 hw->mac.ops.setup_sfp(hw);
4383
Tony Breeds8d1c3c02009-04-09 22:29:10 +00004384 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004385 /* This will also work for DA Twinax connections */
4386 schedule_work(&adapter->multispeed_fiber_task);
4387 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
4388}
4389
4390/**
Alexander Duyck69888672008-09-11 20:05:39 -07004391 * ixgbe_watchdog_task - worker thread to bring link up
4392 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004393 **/
4394static void ixgbe_watchdog_task(struct work_struct *work)
4395{
4396 struct ixgbe_adapter *adapter = container_of(work,
4397 struct ixgbe_adapter,
4398 watchdog_task);
4399 struct net_device *netdev = adapter->netdev;
4400 struct ixgbe_hw *hw = &adapter->hw;
4401 u32 link_speed = adapter->link_speed;
4402 bool link_up = adapter->link_up;
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004403 int i;
4404 struct ixgbe_ring *tx_ring;
4405 int some_tx_pending = 0;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004406
4407 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
4408
4409 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4410 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004411 if (link_up) {
4412#ifdef CONFIG_DCB
4413 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4414 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004415 hw->mac.ops.fc_enable(hw, i);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004416 } else {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004417 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004418 }
4419#else
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004420 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004421#endif
4422 }
4423
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004424 if (link_up ||
4425 time_after(jiffies, (adapter->link_check_timeout +
4426 IXGBE_TRY_LINK_TIMEOUT))) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004427 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004428 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004429 }
4430 adapter->link_up = link_up;
4431 adapter->link_speed = link_speed;
4432 }
Auke Kok9a799d72007-09-15 14:07:45 -07004433
4434 if (link_up) {
4435 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004436 bool flow_rx, flow_tx;
4437
4438 if (hw->mac.type == ixgbe_mac_82599EB) {
4439 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4440 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
4441 flow_rx = (mflcn & IXGBE_MFLCN_RFCE);
4442 flow_tx = (fccfg & IXGBE_FCCFG_TFCE_802_3X);
4443 } else {
4444 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4445 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
4446 flow_rx = (frctl & IXGBE_FCTRL_RFCE);
4447 flow_tx = (rmcs & IXGBE_RMCS_TFCE_802_3X);
4448 }
4449
Jeff Kirshera46e5342008-11-27 00:22:21 -08004450 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
4451 "Flow Control: %s\n",
4452 netdev->name,
4453 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
4454 "10 Gbps" :
4455 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
4456 "1 Gbps" : "unknown speed")),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004457 ((flow_rx && flow_tx) ? "RX/TX" :
4458 (flow_rx ? "RX" :
4459 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07004460
4461 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004462 } else {
4463 /* Force detection of hung controller */
4464 adapter->detect_tx_hung = true;
4465 }
4466 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004467 adapter->link_up = false;
4468 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004469 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08004470 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
4471 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07004472 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004473 }
4474 }
4475
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004476 if (!netif_carrier_ok(netdev)) {
4477 for (i = 0; i < adapter->num_tx_queues; i++) {
4478 tx_ring = &adapter->tx_ring[i];
4479 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
4480 some_tx_pending = 1;
4481 break;
4482 }
4483 }
4484
4485 if (some_tx_pending) {
4486 /* We've lost link, so the controller stops DMA,
4487 * but we've got queued Tx work that's never going
4488 * to get done, so reset controller to flush Tx.
4489 * (Do the reset outside of interrupt context).
4490 */
4491 schedule_work(&adapter->reset_task);
4492 }
4493 }
4494
Auke Kok9a799d72007-09-15 14:07:45 -07004495 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004496 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07004497}
4498
Auke Kok9a799d72007-09-15 14:07:45 -07004499static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004500 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
4501 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004502{
4503 struct ixgbe_adv_tx_context_desc *context_desc;
4504 unsigned int i;
4505 int err;
4506 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004507 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
4508 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07004509
4510 if (skb_is_gso(skb)) {
4511 if (skb_header_cloned(skb)) {
4512 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4513 if (err)
4514 return err;
4515 }
4516 l4len = tcp_hdrlen(skb);
4517 *hdr_len += l4len;
4518
Al Viro8327d002007-12-10 18:54:12 +00004519 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004520 struct iphdr *iph = ip_hdr(skb);
4521 iph->tot_len = 0;
4522 iph->check = 0;
4523 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004524 iph->daddr, 0,
4525 IPPROTO_TCP,
4526 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004527 adapter->hw_tso_ctxt++;
4528 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
4529 ipv6_hdr(skb)->payload_len = 0;
4530 tcp_hdr(skb)->check =
4531 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004532 &ipv6_hdr(skb)->daddr,
4533 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004534 adapter->hw_tso6_ctxt++;
4535 }
4536
4537 i = tx_ring->next_to_use;
4538
4539 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4540 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4541
4542 /* VLAN MACLEN IPLEN */
4543 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4544 vlan_macip_lens |=
4545 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4546 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004547 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004548 *hdr_len += skb_network_offset(skb);
4549 vlan_macip_lens |=
4550 (skb_transport_header(skb) - skb_network_header(skb));
4551 *hdr_len +=
4552 (skb_transport_header(skb) - skb_network_header(skb));
4553 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4554 context_desc->seqnum_seed = 0;
4555
4556 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004557 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004558 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004559
Al Viro8327d002007-12-10 18:54:12 +00004560 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004561 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4562 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
4563 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4564
4565 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004566 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07004567 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
4568 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004569 /* use index 1 for TSO */
4570 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004571 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4572
4573 tx_buffer_info->time_stamp = jiffies;
4574 tx_buffer_info->next_to_watch = i;
4575
4576 i++;
4577 if (i == tx_ring->count)
4578 i = 0;
4579 tx_ring->next_to_use = i;
4580
4581 return true;
4582 }
4583 return false;
4584}
4585
4586static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004587 struct ixgbe_ring *tx_ring,
4588 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07004589{
4590 struct ixgbe_adv_tx_context_desc *context_desc;
4591 unsigned int i;
4592 struct ixgbe_tx_buffer *tx_buffer_info;
4593 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4594
4595 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4596 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4597 i = tx_ring->next_to_use;
4598 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4599 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4600
4601 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4602 vlan_macip_lens |=
4603 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4604 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004605 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004606 if (skb->ip_summed == CHECKSUM_PARTIAL)
4607 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004608 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07004609
4610 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4611 context_desc->seqnum_seed = 0;
4612
4613 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004614 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004615
4616 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08004617 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004618 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07004619 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08004620 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4621 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004622 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004623 else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
4624 type_tucmd_mlhl |=
4625 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004626 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004627 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08004628 /* XXX what about other V6 headers?? */
4629 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4630 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004631 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004632 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
4633 type_tucmd_mlhl |=
4634 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004635 break;
Auke Kok41825d72008-02-12 15:20:33 -08004636 default:
4637 if (unlikely(net_ratelimit())) {
4638 DPRINTK(PROBE, WARNING,
4639 "partial checksum but proto=%x!\n",
4640 skb->protocol);
4641 }
4642 break;
4643 }
Auke Kok9a799d72007-09-15 14:07:45 -07004644 }
4645
4646 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004647 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07004648 context_desc->mss_l4len_idx = 0;
4649
4650 tx_buffer_info->time_stamp = jiffies;
4651 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004652
Auke Kok9a799d72007-09-15 14:07:45 -07004653 adapter->hw_csum_tx_good++;
4654 i++;
4655 if (i == tx_ring->count)
4656 i = 0;
4657 tx_ring->next_to_use = i;
4658
4659 return true;
4660 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004661
Auke Kok9a799d72007-09-15 14:07:45 -07004662 return false;
4663}
4664
4665static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004666 struct ixgbe_ring *tx_ring,
Yi Zoueacd73f2009-05-13 13:11:06 +00004667 struct sk_buff *skb, u32 tx_flags,
4668 unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07004669{
4670 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00004671 unsigned int len;
4672 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07004673 unsigned int offset = 0, size, count = 0, i;
4674 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
4675 unsigned int f;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004676 dma_addr_t *map;
Auke Kok9a799d72007-09-15 14:07:45 -07004677
4678 i = tx_ring->next_to_use;
4679
Alexander Duyck44df32c2009-03-31 21:34:23 +00004680 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
4681 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
4682 return 0;
4683 }
4684
4685 map = skb_shinfo(skb)->dma_maps;
4686
Yi Zoueacd73f2009-05-13 13:11:06 +00004687 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
4688 /* excluding fcoe_crc_eof for FCoE */
4689 total -= sizeof(struct fcoe_crc_eof);
4690
4691 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07004692 while (len) {
4693 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4694 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4695
4696 tx_buffer_info->length = size;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004697 tx_buffer_info->dma = map[0] + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004698 tx_buffer_info->time_stamp = jiffies;
4699 tx_buffer_info->next_to_watch = i;
4700
4701 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00004702 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07004703 offset += size;
4704 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004705
4706 if (len) {
4707 i++;
4708 if (i == tx_ring->count)
4709 i = 0;
4710 }
Auke Kok9a799d72007-09-15 14:07:45 -07004711 }
4712
4713 for (f = 0; f < nr_frags; f++) {
4714 struct skb_frag_struct *frag;
4715
4716 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00004717 len = min((unsigned int)frag->size, total);
Alexander Duyck44df32c2009-03-31 21:34:23 +00004718 offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004719
4720 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00004721 i++;
4722 if (i == tx_ring->count)
4723 i = 0;
4724
Auke Kok9a799d72007-09-15 14:07:45 -07004725 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4726 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4727
4728 tx_buffer_info->length = size;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004729 tx_buffer_info->dma = map[f + 1] + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004730 tx_buffer_info->time_stamp = jiffies;
4731 tx_buffer_info->next_to_watch = i;
4732
4733 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00004734 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07004735 offset += size;
4736 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07004737 }
Yi Zoueacd73f2009-05-13 13:11:06 +00004738 if (total == 0)
4739 break;
Auke Kok9a799d72007-09-15 14:07:45 -07004740 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00004741
Auke Kok9a799d72007-09-15 14:07:45 -07004742 tx_ring->tx_buffer_info[i].skb = skb;
4743 tx_ring->tx_buffer_info[first].next_to_watch = i;
4744
4745 return count;
4746}
4747
4748static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004749 struct ixgbe_ring *tx_ring,
4750 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004751{
4752 union ixgbe_adv_tx_desc *tx_desc = NULL;
4753 struct ixgbe_tx_buffer *tx_buffer_info;
4754 u32 olinfo_status = 0, cmd_type_len = 0;
4755 unsigned int i;
4756 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
4757
4758 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
4759
4760 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
4761
4762 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4763 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
4764
4765 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
4766 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4767
4768 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004769 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004770
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004771 /* use index 1 context for tso */
4772 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004773 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
4774 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004775 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004776
4777 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
4778 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004779 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004780
Yi Zoueacd73f2009-05-13 13:11:06 +00004781 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
4782 olinfo_status |= IXGBE_ADVTXD_CC;
4783 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
4784 if (tx_flags & IXGBE_TX_FLAGS_FSO)
4785 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4786 }
4787
Auke Kok9a799d72007-09-15 14:07:45 -07004788 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
4789
4790 i = tx_ring->next_to_use;
4791 while (count--) {
4792 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4793 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
4794 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
4795 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004796 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07004797 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07004798 i++;
4799 if (i == tx_ring->count)
4800 i = 0;
4801 }
4802
4803 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
4804
4805 /*
4806 * Force memory writes to complete before letting h/w
4807 * know there are new descriptors to fetch. (Only
4808 * applicable for weak-ordered memory model archs,
4809 * such as IA-64).
4810 */
4811 wmb();
4812
4813 tx_ring->next_to_use = i;
4814 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4815}
4816
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004817static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004818 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004819{
4820 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4821
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004822 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004823 /* Herbert's original patch had:
4824 * smp_mb__after_netif_stop_queue();
4825 * but since that doesn't exist yet, just open code it. */
4826 smp_mb();
4827
4828 /* We need to check again in a case another CPU has just
4829 * made room available. */
4830 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
4831 return -EBUSY;
4832
4833 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07004834 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004835 ++adapter->restart_queue;
4836 return 0;
4837}
4838
4839static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004840 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004841{
4842 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
4843 return 0;
4844 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
4845}
4846
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07004847static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
4848{
4849 struct ixgbe_adapter *adapter = netdev_priv(dev);
4850
4851 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4852 return 0; /* All traffic should default to class 0 */
4853
4854 return skb_tx_hash(dev, skb);
4855}
4856
Auke Kok9a799d72007-09-15 14:07:45 -07004857static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
4858{
4859 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4860 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004861 unsigned int first;
4862 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004863 u8 hdr_len = 0;
4864 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07004865 int count = 0;
4866 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004867
Wu Fengguang95615d92009-04-14 21:53:48 -07004868 r_idx = skb->queue_mapping;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004869 tx_ring = &adapter->tx_ring[r_idx];
Auke Kok9a799d72007-09-15 14:07:45 -07004870
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004871 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
4872 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004873 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4874 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
4875 tx_flags |= (skb->queue_mapping << 13);
4876 }
4877 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
4878 tx_flags |= IXGBE_TX_FLAGS_VLAN;
4879 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4880 tx_flags |= (skb->queue_mapping << 13);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004881 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
4882 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07004883 }
Yi Zoueacd73f2009-05-13 13:11:06 +00004884
4885 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
4886 (skb->protocol == htons(ETH_P_FCOE)))
4887 tx_flags |= IXGBE_TX_FLAGS_FCOE;
4888
4889 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004890 if (skb_is_gso(skb) ||
4891 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00004892 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
4893 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07004894 count++;
4895
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004896 count += TXD_USE_COUNT(skb_headlen(skb));
4897 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07004898 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
4899
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004900 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004901 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07004902 return NETDEV_TX_BUSY;
4903 }
Auke Kok9a799d72007-09-15 14:07:45 -07004904
Auke Kok9a799d72007-09-15 14:07:45 -07004905 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00004906 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
4907#ifdef IXGBE_FCOE
4908 /* setup tx offload for FCoE */
4909 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
4910 if (tso < 0) {
4911 dev_kfree_skb_any(skb);
4912 return NETDEV_TX_OK;
4913 }
4914 if (tso)
4915 tx_flags |= IXGBE_TX_FLAGS_FSO;
4916#endif /* IXGBE_FCOE */
4917 } else {
4918 if (skb->protocol == htons(ETH_P_IP))
4919 tx_flags |= IXGBE_TX_FLAGS_IPV4;
4920 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
4921 if (tso < 0) {
4922 dev_kfree_skb_any(skb);
4923 return NETDEV_TX_OK;
4924 }
4925
4926 if (tso)
4927 tx_flags |= IXGBE_TX_FLAGS_TSO;
4928 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
4929 (skb->ip_summed == CHECKSUM_PARTIAL))
4930 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07004931 }
4932
Yi Zoueacd73f2009-05-13 13:11:06 +00004933 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
Alexander Duyck44df32c2009-03-31 21:34:23 +00004934 if (count) {
4935 ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
4936 hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00004937 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07004938
Alexander Duyck44df32c2009-03-31 21:34:23 +00004939 } else {
4940 dev_kfree_skb_any(skb);
4941 tx_ring->tx_buffer_info[first].time_stamp = 0;
4942 tx_ring->next_to_use = first;
4943 }
Auke Kok9a799d72007-09-15 14:07:45 -07004944
4945 return NETDEV_TX_OK;
4946}
4947
4948/**
4949 * ixgbe_get_stats - Get System Network Statistics
4950 * @netdev: network interface device structure
4951 *
4952 * Returns the address of the device statistics structure.
4953 * The statistics are actually updated from the timer callback.
4954 **/
4955static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
4956{
4957 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4958
4959 /* only return the current stats */
4960 return &adapter->net_stats;
4961}
4962
4963/**
4964 * ixgbe_set_mac - Change the Ethernet Address of the NIC
4965 * @netdev: network interface device structure
4966 * @p: pointer to an address structure
4967 *
4968 * Returns 0 on success, negative on failure
4969 **/
4970static int ixgbe_set_mac(struct net_device *netdev, void *p)
4971{
4972 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004973 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004974 struct sockaddr *addr = p;
4975
4976 if (!is_valid_ether_addr(addr->sa_data))
4977 return -EADDRNOTAVAIL;
4978
4979 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004980 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07004981
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004982 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004983
4984 return 0;
4985}
4986
Ben Hutchings6b73e102009-04-29 08:08:58 +00004987static int
4988ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
4989{
4990 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4991 struct ixgbe_hw *hw = &adapter->hw;
4992 u16 value;
4993 int rc;
4994
4995 if (prtad != hw->phy.mdio.prtad)
4996 return -EINVAL;
4997 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
4998 if (!rc)
4999 rc = value;
5000 return rc;
5001}
5002
5003static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
5004 u16 addr, u16 value)
5005{
5006 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5007 struct ixgbe_hw *hw = &adapter->hw;
5008
5009 if (prtad != hw->phy.mdio.prtad)
5010 return -EINVAL;
5011 return hw->phy.ops.write_reg(hw, addr, devad, value);
5012}
5013
5014static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
5015{
5016 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5017
5018 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
5019}
5020
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005021/**
5022 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
5023 * netdev->dev_addr_list
5024 * @netdev: network interface device structure
5025 *
5026 * Returns non-zero on failure
5027 **/
5028static int ixgbe_add_sanmac_netdev(struct net_device *dev)
5029{
5030 int err = 0;
5031 struct ixgbe_adapter *adapter = netdev_priv(dev);
5032 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5033
5034 if (is_valid_ether_addr(mac->san_addr)) {
5035 rtnl_lock();
5036 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5037 rtnl_unlock();
5038 }
5039 return err;
5040}
5041
5042/**
5043 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
5044 * netdev->dev_addr_list
5045 * @netdev: network interface device structure
5046 *
5047 * Returns non-zero on failure
5048 **/
5049static int ixgbe_del_sanmac_netdev(struct net_device *dev)
5050{
5051 int err = 0;
5052 struct ixgbe_adapter *adapter = netdev_priv(dev);
5053 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5054
5055 if (is_valid_ether_addr(mac->san_addr)) {
5056 rtnl_lock();
5057 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5058 rtnl_unlock();
5059 }
5060 return err;
5061}
5062
Auke Kok9a799d72007-09-15 14:07:45 -07005063#ifdef CONFIG_NET_POLL_CONTROLLER
5064/*
5065 * Polling 'interrupt' - used by things like netconsole to send skbs
5066 * without having to re-enable interrupts. It's not called while
5067 * the interrupt routine is executing.
5068 */
5069static void ixgbe_netpoll(struct net_device *netdev)
5070{
5071 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5072
5073 disable_irq(adapter->pdev->irq);
5074 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
5075 ixgbe_intr(adapter->pdev->irq, netdev);
5076 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
5077 enable_irq(adapter->pdev->irq);
5078}
5079#endif
5080
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005081static const struct net_device_ops ixgbe_netdev_ops = {
5082 .ndo_open = ixgbe_open,
5083 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005084 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005085 .ndo_select_queue = ixgbe_select_queue,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005086 .ndo_get_stats = ixgbe_get_stats,
Chris Leeche90d4002009-03-10 16:00:24 +00005087 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005088 .ndo_set_multicast_list = ixgbe_set_rx_mode,
5089 .ndo_validate_addr = eth_validate_addr,
5090 .ndo_set_mac_address = ixgbe_set_mac,
5091 .ndo_change_mtu = ixgbe_change_mtu,
5092 .ndo_tx_timeout = ixgbe_tx_timeout,
5093 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
5094 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
5095 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00005096 .ndo_do_ioctl = ixgbe_ioctl,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005097#ifdef CONFIG_NET_POLL_CONTROLLER
5098 .ndo_poll_controller = ixgbe_netpoll,
5099#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005100#ifdef IXGBE_FCOE
5101 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
5102 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
5103#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005104};
5105
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005106/**
Auke Kok9a799d72007-09-15 14:07:45 -07005107 * ixgbe_probe - Device Initialization Routine
5108 * @pdev: PCI device information struct
5109 * @ent: entry in ixgbe_pci_tbl
5110 *
5111 * Returns 0 on success, negative on failure
5112 *
5113 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
5114 * The OS initialization, configuring of the adapter private structure,
5115 * and a hardware reset occur.
5116 **/
5117static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005118 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07005119{
5120 struct net_device *netdev;
5121 struct ixgbe_adapter *adapter = NULL;
5122 struct ixgbe_hw *hw;
5123 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07005124 static int cards_found;
5125 int i, err, pci_using_dac;
Yi Zoueacd73f2009-05-13 13:11:06 +00005126#ifdef IXGBE_FCOE
5127 u16 device_caps;
5128#endif
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005129 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07005130
gouji-new9ce77662009-05-06 10:44:45 +00005131 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005132 if (err)
5133 return err;
5134
Yang Hongyang6a355282009-04-06 19:01:13 -07005135 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
5136 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07005137 pci_using_dac = 1;
5138 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07005139 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005140 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -07005141 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005142 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005143 dev_err(&pdev->dev, "No usable DMA "
5144 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005145 goto err_dma;
5146 }
5147 }
5148 pci_using_dac = 0;
5149 }
5150
gouji-new9ce77662009-05-06 10:44:45 +00005151 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
5152 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07005153 if (err) {
gouji-new9ce77662009-05-06 10:44:45 +00005154 dev_err(&pdev->dev,
5155 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07005156 goto err_pci_reg;
5157 }
5158
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005159 err = pci_enable_pcie_error_reporting(pdev);
5160 if (err) {
5161 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
5162 "0x%x\n", err);
5163 /* non-fatal, continue */
5164 }
5165
Auke Kok9a799d72007-09-15 14:07:45 -07005166 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07005167 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005168
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005169 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07005170 if (!netdev) {
5171 err = -ENOMEM;
5172 goto err_alloc_etherdev;
5173 }
5174
Auke Kok9a799d72007-09-15 14:07:45 -07005175 SET_NETDEV_DEV(netdev, &pdev->dev);
5176
5177 pci_set_drvdata(pdev, netdev);
5178 adapter = netdev_priv(netdev);
5179
5180 adapter->netdev = netdev;
5181 adapter->pdev = pdev;
5182 hw = &adapter->hw;
5183 hw->back = adapter;
5184 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
5185
Jeff Kirsher05857982008-09-11 19:57:00 -07005186 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
5187 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07005188 if (!hw->hw_addr) {
5189 err = -EIO;
5190 goto err_ioremap;
5191 }
5192
5193 for (i = 1; i <= 5; i++) {
5194 if (pci_resource_len(pdev, i) == 0)
5195 continue;
5196 }
5197
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005198 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07005199 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005200 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07005201 strcpy(netdev->name, pci_name(pdev));
5202
Auke Kok9a799d72007-09-15 14:07:45 -07005203 adapter->bd_number = cards_found;
5204
Auke Kok9a799d72007-09-15 14:07:45 -07005205 /* Setup hw api */
5206 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005207 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07005208
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005209 /* EEPROM */
5210 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
5211 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
5212 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
5213 if (!(eec & (1 << 8)))
5214 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
5215
5216 /* PHY */
5217 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08005218 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00005219 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
5220 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
5221 hw->phy.mdio.mmds = 0;
5222 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
5223 hw->phy.mdio.dev = netdev;
5224 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
5225 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08005226
5227 /* set up this timer and work struct before calling get_invariants
5228 * which might start the timer
5229 */
5230 init_timer(&adapter->sfp_timer);
5231 adapter->sfp_timer.function = &ixgbe_sfp_timer;
5232 adapter->sfp_timer.data = (unsigned long) adapter;
5233
5234 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005235
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005236 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
5237 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
5238
5239 /* a new SFP+ module arrival, called from GPI SDP2 context */
5240 INIT_WORK(&adapter->sfp_config_module_task,
5241 ixgbe_sfp_config_module_task);
5242
Don Skidmore8ca783a2009-05-26 20:40:47 -07005243 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005244
5245 /* setup the private structure */
5246 err = ixgbe_sw_init(adapter);
5247 if (err)
5248 goto err_sw_init;
5249
Don Skidmorebf069c92009-05-07 10:39:54 +00005250 /*
5251 * If there is a fan on this device and it has failed log the
5252 * failure.
5253 */
5254 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5255 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5256 if (esdp & IXGBE_ESDP_SDP1)
5257 DPRINTK(PROBE, CRIT,
5258 "Fan has stopped, replace the adapter\n");
5259 }
5260
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005261 /* reset_hw fills in the perm_addr as well */
5262 err = hw->mac.ops.reset_hw(hw);
Don Skidmore8ca783a2009-05-26 20:40:47 -07005263 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
5264 hw->mac.type == ixgbe_mac_82598EB) {
5265 /*
5266 * Start a kernel thread to watch for a module to arrive.
5267 * Only do this for 82598, since 82599 will generate
5268 * interrupts on module arrival.
5269 */
5270 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5271 mod_timer(&adapter->sfp_timer,
5272 round_jiffies(jiffies + (2 * HZ)));
5273 err = 0;
5274 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005275 dev_err(&adapter->pdev->dev, "failed to load because an "
5276 "unsupported SFP+ module type was detected.\n");
5277 goto err_sw_init;
5278 } else if (err) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005279 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
5280 goto err_sw_init;
5281 }
5282
Auke Kok9a799d72007-09-15 14:07:45 -07005283 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005284 NETIF_F_IP_CSUM |
5285 NETIF_F_HW_VLAN_TX |
5286 NETIF_F_HW_VLAN_RX |
5287 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07005288
Jesse Brandeburge9990a92008-08-26 04:27:24 -07005289 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005290 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07005291 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08005292 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005293
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00005294 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
5295 netdev->features |= NETIF_F_SCTP_CSUM;
5296
Jeff Kirsherad31c402008-06-05 04:05:30 -07005297 netdev->vlan_features |= NETIF_F_TSO;
5298 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07005299 netdev->vlan_features |= NETIF_F_IP_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005300 netdev->vlan_features |= NETIF_F_SG;
5301
Alexander Duyck2f90b862008-11-20 20:52:10 -08005302 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5303 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
5304
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005305#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005306 netdev->dcbnl_ops = &dcbnl_ops;
5307#endif
5308
Yi Zoueacd73f2009-05-13 13:11:06 +00005309#ifdef IXGBE_FCOE
5310 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
5311 if (hw->mac.ops.get_device_caps) {
5312 hw->mac.ops.get_device_caps(hw, &device_caps);
5313 if (!(device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)) {
5314 netdev->features |= NETIF_F_FCOE_CRC;
5315 netdev->features |= NETIF_F_FSO;
Yi Zou332d4a72009-05-13 13:11:53 +00005316 netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1;
Yi Zoueacd73f2009-05-13 13:11:06 +00005317 } else {
5318 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5319 }
5320 }
5321 }
5322#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005323 if (pci_using_dac)
5324 netdev->features |= NETIF_F_HIGHDMA;
5325
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00005326 if (adapter->flags & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00005327 netdev->features |= NETIF_F_LRO;
5328
Auke Kok9a799d72007-09-15 14:07:45 -07005329 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005330 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07005331 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
5332 err = -EIO;
5333 goto err_eeprom;
5334 }
5335
5336 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
5337 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
5338
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005339 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
5340 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005341 err = -EIO;
5342 goto err_eeprom;
5343 }
5344
5345 init_timer(&adapter->watchdog_timer);
5346 adapter->watchdog_timer.function = &ixgbe_watchdog;
5347 adapter->watchdog_timer.data = (unsigned long)adapter;
5348
5349 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005350 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005351
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005352 err = ixgbe_init_interrupt_scheme(adapter);
5353 if (err)
5354 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07005355
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005356 switch (pdev->device) {
5357 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005358 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
5359 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
Peter P Waskiewicz Jrbdf0a552009-06-04 11:09:58 +00005360 /* Enable ACPI wakeup in GRC */
5361 IXGBE_WRITE_REG(hw, IXGBE_GRC,
5362 (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005363 break;
5364 default:
5365 adapter->wol = 0;
5366 break;
5367 }
5368 device_init_wakeup(&adapter->pdev->dev, true);
5369 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
5370
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005371 /* pick up the PCI bus settings for reporting later */
5372 hw->mac.ops.get_bus_info(hw);
5373
Auke Kok9a799d72007-09-15 14:07:45 -07005374 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07005375 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005376 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
5377 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
5378 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
5379 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
5380 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005381 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07005382 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005383 ixgbe_read_pba_num_generic(hw, &part_num);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005384 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
5385 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
5386 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
5387 (part_num >> 8), (part_num & 0xff));
5388 else
5389 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
5390 hw->mac.type, hw->phy.type,
5391 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07005392
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005393 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Auke Kok0c254d82008-02-11 09:25:56 -08005394 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005395 "this card is not sufficient for optimal "
5396 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005397 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005398 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005399 }
5400
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08005401 /* save off EEPROM version number */
5402 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
5403
Auke Kok9a799d72007-09-15 14:07:45 -07005404 /* reset the hardware with the new settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005405 hw->mac.ops.start_hw(hw);
5406
Auke Kok9a799d72007-09-15 14:07:45 -07005407 strcpy(netdev->name, "eth%d");
5408 err = register_netdev(netdev);
5409 if (err)
5410 goto err_register;
5411
Jesse Brandeburg54386462009-04-17 20:44:27 +00005412 /* carrier off reporting is important to ethtool even BEFORE open */
5413 netif_carrier_off(netdev);
5414
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005415#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03005416 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005417 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005418 ixgbe_setup_dca(adapter);
5419 }
5420#endif
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005421 /* add san mac addr to netdev */
5422 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005423
5424 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
5425 cards_found++;
5426 return 0;
5427
5428err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005429 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005430 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005431err_sw_init:
5432err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08005433 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5434 del_timer_sync(&adapter->sfp_timer);
5435 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005436 cancel_work_sync(&adapter->multispeed_fiber_task);
5437 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005438 iounmap(hw->hw_addr);
5439err_ioremap:
5440 free_netdev(netdev);
5441err_alloc_etherdev:
gouji-new9ce77662009-05-06 10:44:45 +00005442 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5443 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005444err_pci_reg:
5445err_dma:
5446 pci_disable_device(pdev);
5447 return err;
5448}
5449
5450/**
5451 * ixgbe_remove - Device Removal Routine
5452 * @pdev: PCI device information struct
5453 *
5454 * ixgbe_remove is called by the PCI subsystem to alert the driver
5455 * that it should release a PCI device. The could be caused by a
5456 * Hot-Plug event, or because the driver is going to be removed from
5457 * memory.
5458 **/
5459static void __devexit ixgbe_remove(struct pci_dev *pdev)
5460{
5461 struct net_device *netdev = pci_get_drvdata(pdev);
5462 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005463 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005464
5465 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08005466 /* clear the module not found bit to make sure the worker won't
5467 * reschedule
5468 */
5469 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07005470 del_timer_sync(&adapter->watchdog_timer);
5471
Donald Skidmorec4900be2008-11-20 21:11:42 -08005472 del_timer_sync(&adapter->sfp_timer);
5473 cancel_work_sync(&adapter->watchdog_task);
5474 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005475 cancel_work_sync(&adapter->multispeed_fiber_task);
5476 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005477 flush_scheduled_work();
5478
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005479#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005480 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
5481 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
5482 dca_remove_requester(&pdev->dev);
5483 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
5484 }
5485
5486#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005487#ifdef IXGBE_FCOE
5488 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
5489 ixgbe_cleanup_fcoe(adapter);
5490
5491#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005492
5493 /* remove the added san mac */
5494 ixgbe_del_sanmac_netdev(netdev);
5495
Donald Skidmorec4900be2008-11-20 21:11:42 -08005496 if (netdev->reg_state == NETREG_REGISTERED)
5497 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005498
Alexander Duyck7a921c92009-05-06 10:43:28 +00005499 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005500
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005501 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005502
5503 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00005504 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5505 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005506
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005507 DPRINTK(PROBE, INFO, "complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005508
Auke Kok9a799d72007-09-15 14:07:45 -07005509 free_netdev(netdev);
5510
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005511 err = pci_disable_pcie_error_reporting(pdev);
5512 if (err)
5513 dev_err(&pdev->dev,
5514 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
5515
Auke Kok9a799d72007-09-15 14:07:45 -07005516 pci_disable_device(pdev);
5517}
5518
5519/**
5520 * ixgbe_io_error_detected - called when PCI error is detected
5521 * @pdev: Pointer to PCI device
5522 * @state: The current pci connection state
5523 *
5524 * This function is called after a PCI bus error affecting
5525 * this device has been detected.
5526 */
5527static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005528 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07005529{
5530 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005531 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005532
5533 netif_device_detach(netdev);
5534
Breno Leitao3044b8d2009-05-06 10:44:26 +00005535 if (state == pci_channel_io_perm_failure)
5536 return PCI_ERS_RESULT_DISCONNECT;
5537
Auke Kok9a799d72007-09-15 14:07:45 -07005538 if (netif_running(netdev))
5539 ixgbe_down(adapter);
5540 pci_disable_device(pdev);
5541
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005542 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07005543 return PCI_ERS_RESULT_NEED_RESET;
5544}
5545
5546/**
5547 * ixgbe_io_slot_reset - called after the pci bus has been reset.
5548 * @pdev: Pointer to PCI device
5549 *
5550 * Restart the card from scratch, as if from a cold-boot.
5551 */
5552static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
5553{
5554 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005555 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005556 pci_ers_result_t result;
5557 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005558
gouji-new9ce77662009-05-06 10:44:45 +00005559 if (pci_enable_device_mem(pdev)) {
Auke Kok9a799d72007-09-15 14:07:45 -07005560 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005561 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005562 result = PCI_ERS_RESULT_DISCONNECT;
5563 } else {
5564 pci_set_master(pdev);
5565 pci_restore_state(pdev);
5566
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005567 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005568
5569 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00005570 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005571 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07005572 }
Auke Kok9a799d72007-09-15 14:07:45 -07005573
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005574 err = pci_cleanup_aer_uncorrect_error_status(pdev);
5575 if (err) {
5576 dev_err(&pdev->dev,
5577 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
5578 /* non-fatal, continue */
5579 }
Auke Kok9a799d72007-09-15 14:07:45 -07005580
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005581 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07005582}
5583
5584/**
5585 * ixgbe_io_resume - called when traffic can start flowing again.
5586 * @pdev: Pointer to PCI device
5587 *
5588 * This callback is called when the error recovery driver tells us that
5589 * its OK to resume normal operation.
5590 */
5591static void ixgbe_io_resume(struct pci_dev *pdev)
5592{
5593 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005594 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005595
5596 if (netif_running(netdev)) {
5597 if (ixgbe_up(adapter)) {
5598 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
5599 return;
5600 }
5601 }
5602
5603 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005604}
5605
5606static struct pci_error_handlers ixgbe_err_handler = {
5607 .error_detected = ixgbe_io_error_detected,
5608 .slot_reset = ixgbe_io_slot_reset,
5609 .resume = ixgbe_io_resume,
5610};
5611
5612static struct pci_driver ixgbe_driver = {
5613 .name = ixgbe_driver_name,
5614 .id_table = ixgbe_pci_tbl,
5615 .probe = ixgbe_probe,
5616 .remove = __devexit_p(ixgbe_remove),
5617#ifdef CONFIG_PM
5618 .suspend = ixgbe_suspend,
5619 .resume = ixgbe_resume,
5620#endif
5621 .shutdown = ixgbe_shutdown,
5622 .err_handler = &ixgbe_err_handler
5623};
5624
5625/**
5626 * ixgbe_init_module - Driver Registration Routine
5627 *
5628 * ixgbe_init_module is the first routine called when the driver is
5629 * loaded. All it does is register with the PCI subsystem.
5630 **/
5631static int __init ixgbe_init_module(void)
5632{
5633 int ret;
5634 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
5635 ixgbe_driver_string, ixgbe_driver_version);
5636
5637 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
5638
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005639#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005640 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005641#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005642
Auke Kok9a799d72007-09-15 14:07:45 -07005643 ret = pci_register_driver(&ixgbe_driver);
5644 return ret;
5645}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005646
Auke Kok9a799d72007-09-15 14:07:45 -07005647module_init(ixgbe_init_module);
5648
5649/**
5650 * ixgbe_exit_module - Driver Exit Cleanup Routine
5651 *
5652 * ixgbe_exit_module is called just before the driver is removed
5653 * from memory.
5654 **/
5655static void __exit ixgbe_exit_module(void)
5656{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005657#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005658 dca_unregister_notify(&dca_notifier);
5659#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005660 pci_unregister_driver(&ixgbe_driver);
5661}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005662
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005663#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005664static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005665 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005666{
5667 int ret_val;
5668
5669 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005670 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005671
5672 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
5673}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005674
Alexander Duyckb4533682009-03-31 21:32:42 +00005675#endif /* CONFIG_IXGBE_DCA */
5676#ifdef DEBUG
5677/**
5678 * ixgbe_get_hw_dev_name - return device name string
5679 * used by hardware layer to print debugging information
5680 **/
5681char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
5682{
5683 struct ixgbe_adapter *adapter = hw->back;
5684 return adapter->netdev->name;
5685}
5686
5687#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005688module_exit(ixgbe_exit_module);
5689
5690/* ixgbe_main.c */