blob: ca7c5d508752ca35823ce6131b97c920e215126c [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
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001126 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001127 ixgbe_check_sfp_event(adapter, eicr);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001128
1129 /* Handle Flow Director Full threshold interrupt */
1130 if (eicr & IXGBE_EICR_FLOW_DIR) {
1131 int i;
1132 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
1133 /* Disable transmits before FDIR Re-initialization */
1134 netif_tx_stop_all_queues(netdev);
1135 for (i = 0; i < adapter->num_tx_queues; i++) {
1136 struct ixgbe_ring *tx_ring =
1137 &adapter->tx_ring[i];
1138 if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE,
1139 &tx_ring->reinit_state))
1140 schedule_work(&adapter->fdir_reinit_task);
1141 }
1142 }
1143 }
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001144 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1145 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -07001146
1147 return IRQ_HANDLED;
1148}
1149
Alexander Duyckfe49f042009-06-04 16:00:09 +00001150static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1151 u64 qmask)
1152{
1153 u32 mask;
1154
1155 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1156 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1157 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1158 } else {
1159 mask = (qmask & 0xFFFFFFFF);
1160 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
1161 mask = (qmask >> 32);
1162 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
1163 }
1164 /* skip the flush */
1165}
1166
1167static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
1168 u64 qmask)
1169{
1170 u32 mask;
1171
1172 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1173 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1174 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
1175 } else {
1176 mask = (qmask & 0xFFFFFFFF);
1177 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
1178 mask = (qmask >> 32);
1179 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
1180 }
1181 /* skip the flush */
1182}
1183
Auke Kok9a799d72007-09-15 14:07:45 -07001184static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1185{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001186 struct ixgbe_q_vector *q_vector = data;
1187 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001188 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001189 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001190
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001191 if (!q_vector->txr_count)
1192 return IRQ_HANDLED;
1193
1194 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1195 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001196 tx_ring = &(adapter->tx_ring[r_idx]);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001197 tx_ring->total_bytes = 0;
1198 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001199 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001200 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001201 }
1202
Alexander Duyck91281fd2009-06-04 16:00:27 +00001203 /* disable interrupts on this vector only */
1204 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1205 napi_schedule(&q_vector->napi);
1206
Auke Kok9a799d72007-09-15 14:07:45 -07001207 return IRQ_HANDLED;
1208}
1209
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001210/**
1211 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1212 * @irq: unused
1213 * @data: pointer to our q_vector struct for this interrupt vector
1214 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001215static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1216{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001217 struct ixgbe_q_vector *q_vector = data;
1218 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001219 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001220 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001221 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001222
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001223 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001224 for (i = 0; i < q_vector->rxr_count; i++) {
1225 rx_ring = &(adapter->rx_ring[r_idx]);
1226 rx_ring->total_bytes = 0;
1227 rx_ring->total_packets = 0;
1228 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1229 r_idx + 1);
1230 }
1231
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001232 if (!q_vector->rxr_count)
1233 return IRQ_HANDLED;
1234
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001235 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001236 rx_ring = &(adapter->rx_ring[r_idx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001237 /* disable interrupts on this vector only */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001238 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
Ben Hutchings288379f2009-01-19 16:43:59 -08001239 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001240
Auke Kok9a799d72007-09-15 14:07:45 -07001241 return IRQ_HANDLED;
1242}
1243
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001244static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1245{
Alexander Duyck91281fd2009-06-04 16:00:27 +00001246 struct ixgbe_q_vector *q_vector = data;
1247 struct ixgbe_adapter *adapter = q_vector->adapter;
1248 struct ixgbe_ring *ring;
1249 int r_idx;
1250 int i;
1251
1252 if (!q_vector->txr_count && !q_vector->rxr_count)
1253 return IRQ_HANDLED;
1254
1255 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1256 for (i = 0; i < q_vector->txr_count; i++) {
1257 ring = &(adapter->tx_ring[r_idx]);
1258 ring->total_bytes = 0;
1259 ring->total_packets = 0;
1260 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1261 r_idx + 1);
1262 }
1263
1264 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1265 for (i = 0; i < q_vector->rxr_count; i++) {
1266 ring = &(adapter->rx_ring[r_idx]);
1267 ring->total_bytes = 0;
1268 ring->total_packets = 0;
1269 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1270 r_idx + 1);
1271 }
1272
1273 /* disable interrupts on this vector only */
1274 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1275 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001276
1277 return IRQ_HANDLED;
1278}
1279
1280/**
1281 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1282 * @napi: napi struct with our devices info in it
1283 * @budget: amount of work driver is allowed to do this pass, in packets
1284 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001285 * This function is optimized for cleaning one queue only on a single
1286 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001287 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001288static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1289{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001290 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001291 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001292 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001293 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001294 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001295 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001296
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001297 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001298 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001299#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001300 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001301 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001302#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001303
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001304 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001305
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001306 /* If all Rx work done, exit the polling mode */
1307 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001308 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001309 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001310 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001311 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001312 ixgbe_irq_enable_queues(adapter,
1313 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07001314 }
1315
1316 return work_done;
1317}
1318
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001319/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00001320 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001321 * @napi: napi struct with our devices info in it
1322 * @budget: amount of work driver is allowed to do this pass, in packets
1323 *
1324 * This function will clean more than one rx queue associated with a
1325 * q_vector.
1326 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00001327static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001328{
1329 struct ixgbe_q_vector *q_vector =
1330 container_of(napi, struct ixgbe_q_vector, napi);
1331 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001332 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001333 int work_done = 0, i;
1334 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001335 bool tx_clean_complete = true;
1336
1337 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1338 for (i = 0; i < q_vector->txr_count; i++) {
1339 ring = &(adapter->tx_ring[r_idx]);
1340#ifdef CONFIG_IXGBE_DCA
1341 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1342 ixgbe_update_tx_dca(adapter, ring);
1343#endif
1344 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
1345 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1346 r_idx + 1);
1347 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001348
1349 /* attempt to distribute budget to each queue fairly, but don't allow
1350 * the budget to go below 1 because we'll exit polling */
1351 budget /= (q_vector->rxr_count ?: 1);
1352 budget = max(budget, 1);
1353 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1354 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck91281fd2009-06-04 16:00:27 +00001355 ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001356#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001357 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck91281fd2009-06-04 16:00:27 +00001358 ixgbe_update_rx_dca(adapter, ring);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001359#endif
Alexander Duyck91281fd2009-06-04 16:00:27 +00001360 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001361 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1362 r_idx + 1);
1363 }
1364
1365 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck91281fd2009-06-04 16:00:27 +00001366 ring = &(adapter->rx_ring[r_idx]);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001367 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001368 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001369 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001370 if (adapter->itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001371 ixgbe_set_itr_msix(q_vector);
1372 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001373 ixgbe_irq_enable_queues(adapter,
1374 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001375 return 0;
1376 }
1377
1378 return work_done;
1379}
Alexander Duyck91281fd2009-06-04 16:00:27 +00001380
1381/**
1382 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
1383 * @napi: napi struct with our devices info in it
1384 * @budget: amount of work driver is allowed to do this pass, in packets
1385 *
1386 * This function is optimized for cleaning one queue only on a single
1387 * q_vector!!!
1388 **/
1389static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
1390{
1391 struct ixgbe_q_vector *q_vector =
1392 container_of(napi, struct ixgbe_q_vector, napi);
1393 struct ixgbe_adapter *adapter = q_vector->adapter;
1394 struct ixgbe_ring *tx_ring = NULL;
1395 int work_done = 0;
1396 long r_idx;
1397
1398 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1399 tx_ring = &(adapter->tx_ring[r_idx]);
1400#ifdef CONFIG_IXGBE_DCA
1401 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1402 ixgbe_update_tx_dca(adapter, tx_ring);
1403#endif
1404
1405 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
1406 work_done = budget;
1407
1408 /* If all Rx work done, exit the polling mode */
1409 if (work_done < budget) {
1410 napi_complete(napi);
1411 if (adapter->itr_setting & 1)
1412 ixgbe_set_itr_msix(q_vector);
1413 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1414 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
1415 }
1416
1417 return work_done;
1418}
1419
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001420static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001421 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001422{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001423 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1424
1425 set_bit(r_idx, q_vector->rxr_idx);
1426 q_vector->rxr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001427}
Auke Kok9a799d72007-09-15 14:07:45 -07001428
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001429static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001430 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001431{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001432 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1433
1434 set_bit(t_idx, q_vector->txr_idx);
1435 q_vector->txr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001436}
Auke Kok9a799d72007-09-15 14:07:45 -07001437
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001438/**
1439 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1440 * @adapter: board private structure to initialize
1441 * @vectors: allotted vector count for descriptor rings
1442 *
1443 * This function maps descriptor rings to the queue-specific vectors
1444 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1445 * one vector per ring/queue, but on a constrained vector budget, we
1446 * group the rings as "efficiently" as possible. You would add new
1447 * mapping configurations in here.
1448 **/
1449static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001450 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001451{
1452 int v_start = 0;
1453 int rxr_idx = 0, txr_idx = 0;
1454 int rxr_remaining = adapter->num_rx_queues;
1455 int txr_remaining = adapter->num_tx_queues;
1456 int i, j;
1457 int rqpv, tqpv;
1458 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001459
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001460 /* No mapping required if MSI-X is disabled. */
1461 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001462 goto out;
1463
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001464 /*
1465 * The ideal configuration...
1466 * We have enough vectors to map one per queue.
1467 */
1468 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1469 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1470 map_vector_to_rxq(adapter, v_start, rxr_idx);
1471
1472 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1473 map_vector_to_txq(adapter, v_start, txr_idx);
1474
1475 goto out;
1476 }
1477
1478 /*
1479 * If we don't have enough vectors for a 1-to-1
1480 * mapping, we'll have to group them so there are
1481 * multiple queues per vector.
1482 */
1483 /* Re-adjusting *qpv takes care of the remainder. */
1484 for (i = v_start; i < vectors; i++) {
1485 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1486 for (j = 0; j < rqpv; j++) {
1487 map_vector_to_rxq(adapter, i, rxr_idx);
1488 rxr_idx++;
1489 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001490 }
Auke Kok9a799d72007-09-15 14:07:45 -07001491 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001492 for (i = v_start; i < vectors; i++) {
1493 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1494 for (j = 0; j < tqpv; j++) {
1495 map_vector_to_txq(adapter, i, txr_idx);
1496 txr_idx++;
1497 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001498 }
Auke Kok9a799d72007-09-15 14:07:45 -07001499 }
1500
Auke Kok9a799d72007-09-15 14:07:45 -07001501out:
Auke Kok9a799d72007-09-15 14:07:45 -07001502 return err;
1503}
1504
1505/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001506 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1507 * @adapter: board private structure
1508 *
1509 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1510 * interrupts from the kernel.
1511 **/
1512static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1513{
1514 struct net_device *netdev = adapter->netdev;
1515 irqreturn_t (*handler)(int, void *);
1516 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001517 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001518
1519 /* Decrement for Other and TCP Timer vectors */
1520 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1521
1522 /* Map the Tx/Rx rings to the vectors we were allotted. */
1523 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1524 if (err)
1525 goto out;
1526
1527#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001528 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1529 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001530 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001531 handler = SET_HANDLER(adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001532
1533 if(handler == &ixgbe_msix_clean_rx) {
1534 sprintf(adapter->name[vector], "%s-%s-%d",
1535 netdev->name, "rx", ri++);
1536 }
1537 else if(handler == &ixgbe_msix_clean_tx) {
1538 sprintf(adapter->name[vector], "%s-%s-%d",
1539 netdev->name, "tx", ti++);
1540 }
1541 else
1542 sprintf(adapter->name[vector], "%s-%s-%d",
1543 netdev->name, "TxRx", vector);
1544
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001545 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001546 handler, 0, adapter->name[vector],
Alexander Duyck7a921c92009-05-06 10:43:28 +00001547 adapter->q_vector[vector]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001548 if (err) {
1549 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001550 "request_irq failed for MSIX interrupt "
1551 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001552 goto free_queue_irqs;
1553 }
1554 }
1555
1556 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1557 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001558 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001559 if (err) {
1560 DPRINTK(PROBE, ERR,
1561 "request_irq for msix_lsc failed: %d\n", err);
1562 goto free_queue_irqs;
1563 }
1564
1565 return 0;
1566
1567free_queue_irqs:
1568 for (i = vector - 1; i >= 0; i--)
1569 free_irq(adapter->msix_entries[--vector].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001570 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001571 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1572 pci_disable_msix(adapter->pdev);
1573 kfree(adapter->msix_entries);
1574 adapter->msix_entries = NULL;
1575out:
1576 return err;
1577}
1578
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001579static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1580{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001581 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001582 u8 current_itr;
1583 u32 new_itr = q_vector->eitr;
1584 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1585 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1586
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001587 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001588 q_vector->tx_itr,
1589 tx_ring->total_packets,
1590 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001591 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001592 q_vector->rx_itr,
1593 rx_ring->total_packets,
1594 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001595
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001596 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001597
1598 switch (current_itr) {
1599 /* counts and packets in update_itr are dependent on these numbers */
1600 case lowest_latency:
1601 new_itr = 100000;
1602 break;
1603 case low_latency:
1604 new_itr = 20000; /* aka hwitr = ~200 */
1605 break;
1606 case bulk_latency:
1607 new_itr = 8000;
1608 break;
1609 default:
1610 break;
1611 }
1612
1613 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001614 /* do an exponential smoothing */
1615 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001616
1617 /* save the algorithm value here, not the smoothed one */
1618 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001619
1620 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001621 }
1622
1623 return;
1624}
1625
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001626/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001627 * ixgbe_irq_enable - Enable default interrupt generation settings
1628 * @adapter: board private structure
1629 **/
1630static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1631{
1632 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00001633
1634 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
David S. Miller6ab33d52008-11-20 16:44:00 -08001635 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1636 mask |= IXGBE_EIMS_GPI_SDP1;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001637 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001638 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001639 mask |= IXGBE_EIMS_GPI_SDP1;
1640 mask |= IXGBE_EIMS_GPI_SDP2;
1641 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001642 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
1643 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
1644 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001645
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001646 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Nelson, Shannon835462f2009-04-27 22:42:54 +00001647 ixgbe_irq_enable_queues(adapter, ~0);
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001648 IXGBE_WRITE_FLUSH(&adapter->hw);
1649}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001650
1651/**
1652 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001653 * @irq: interrupt number
1654 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001655 **/
1656static irqreturn_t ixgbe_intr(int irq, void *data)
1657{
1658 struct net_device *netdev = data;
1659 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1660 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001661 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07001662 u32 eicr;
1663
Don Skidmore54037502009-02-21 15:42:56 -08001664 /*
1665 * Workaround for silicon errata. Mask the interrupts
1666 * before the read of EICR.
1667 */
1668 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1669
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001670 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1671 * therefore no explict interrupt disable is necessary */
1672 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001673 if (!eicr) {
1674 /* shared interrupt alert!
1675 * make sure interrupts are enabled because the read will
1676 * have disabled interrupts due to EIAM */
1677 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001678 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001679 }
Auke Kok9a799d72007-09-15 14:07:45 -07001680
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001681 if (eicr & IXGBE_EICR_LSC)
1682 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001683
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001684 if (hw->mac.type == ixgbe_mac_82599EB)
1685 ixgbe_check_sfp_event(adapter, eicr);
1686
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001687 ixgbe_check_fan_failure(adapter, eicr);
1688
Alexander Duyck7a921c92009-05-06 10:43:28 +00001689 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001690 adapter->tx_ring[0].total_packets = 0;
1691 adapter->tx_ring[0].total_bytes = 0;
1692 adapter->rx_ring[0].total_packets = 0;
1693 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001694 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00001695 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07001696 }
1697
1698 return IRQ_HANDLED;
1699}
1700
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001701static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1702{
1703 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1704
1705 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001706 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001707 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1708 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1709 q_vector->rxr_count = 0;
1710 q_vector->txr_count = 0;
1711 }
1712}
1713
Auke Kok9a799d72007-09-15 14:07:45 -07001714/**
1715 * ixgbe_request_irq - initialize interrupts
1716 * @adapter: board private structure
1717 *
1718 * Attempts to configure interrupts using the best available
1719 * capabilities of the hardware and kernel.
1720 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001721static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001722{
1723 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001724 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001725
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001726 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1727 err = ixgbe_request_msix_irqs(adapter);
1728 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1729 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001730 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001731 } else {
1732 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001733 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001734 }
1735
Auke Kok9a799d72007-09-15 14:07:45 -07001736 if (err)
1737 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1738
Auke Kok9a799d72007-09-15 14:07:45 -07001739 return err;
1740}
1741
1742static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1743{
1744 struct net_device *netdev = adapter->netdev;
1745
1746 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001747 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001748
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001749 q_vectors = adapter->num_msix_vectors;
1750
1751 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001752 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001753
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001754 i--;
1755 for (; i >= 0; i--) {
1756 free_irq(adapter->msix_entries[i].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001757 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001758 }
1759
1760 ixgbe_reset_q_vectors(adapter);
1761 } else {
1762 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001763 }
1764}
1765
1766/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001767 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1768 * @adapter: board private structure
1769 **/
1770static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1771{
Nelson, Shannon835462f2009-04-27 22:42:54 +00001772 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1773 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1774 } else {
1775 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
1776 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001777 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001778 }
1779 IXGBE_WRITE_FLUSH(&adapter->hw);
1780 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1781 int i;
1782 for (i = 0; i < adapter->num_msix_vectors; i++)
1783 synchronize_irq(adapter->msix_entries[i].vector);
1784 } else {
1785 synchronize_irq(adapter->pdev->irq);
1786 }
1787}
1788
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001789/**
Auke Kok9a799d72007-09-15 14:07:45 -07001790 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1791 *
1792 **/
1793static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1794{
Auke Kok9a799d72007-09-15 14:07:45 -07001795 struct ixgbe_hw *hw = &adapter->hw;
1796
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001797 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001798 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001799
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001800 ixgbe_set_ivar(adapter, 0, 0, 0);
1801 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001802
1803 map_vector_to_rxq(adapter, 0, 0);
1804 map_vector_to_txq(adapter, 0, 0);
1805
1806 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001807}
1808
1809/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001810 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001811 * @adapter: board private structure
1812 *
1813 * Configure the Tx unit of the MAC after a reset.
1814 **/
1815static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1816{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001817 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001818 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001819 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001820
1821 /* Setup the HW Tx Head and Tail descriptor pointers */
1822 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001823 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1824 j = ring->reg_idx;
1825 tdba = ring->dma;
1826 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001827 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Yang Hongyang284901a2009-04-06 19:01:15 -07001828 (tdba & DMA_BIT_MASK(32)));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001829 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1830 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1831 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1832 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1833 adapter->tx_ring[i].head = IXGBE_TDH(j);
1834 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1835 /* Disable Tx Head Writeback RO bit, since this hoses
1836 * bookkeeping if things aren't delivered in order.
1837 */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001838 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001839 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001840 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001841 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001842 if (hw->mac.type == ixgbe_mac_82599EB) {
1843 /* We enable 8 traffic classes, DCB only */
1844 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1845 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1846 IXGBE_MTQC_8TC_8TQ));
1847 }
Auke Kok9a799d72007-09-15 14:07:45 -07001848}
1849
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001850#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07001851
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001852static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1853{
1854 struct ixgbe_ring *rx_ring;
1855 u32 srrctl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001856 int queue0 = 0;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001857 unsigned long mask;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001858 struct ixgbe_ring_feature *feature = adapter->ring_feature;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001859
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001860 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Alexander Duyck163de422009-05-07 10:39:16 +00001861 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001862 int dcb_i = feature[RING_F_DCB].indices;
Alexander Duyck163de422009-05-07 10:39:16 +00001863 if (dcb_i == 8)
1864 queue0 = index >> 4;
1865 else if (dcb_i == 4)
1866 queue0 = index >> 5;
1867 else
1868 dev_err(&adapter->pdev->dev, "Invalid DCB "
1869 "configuration\n");
Yi Zou0331a832009-05-17 12:33:52 +00001870#ifdef IXGBE_FCOE
1871 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1872 struct ixgbe_ring_feature *f;
1873
1874 rx_ring = &adapter->rx_ring[queue0];
1875 f = &adapter->ring_feature[RING_F_FCOE];
1876 if ((queue0 == 0) && (index > rx_ring->reg_idx))
1877 queue0 = f->mask + index -
1878 rx_ring->reg_idx - 1;
1879 }
1880#endif /* IXGBE_FCOE */
Alexander Duyck163de422009-05-07 10:39:16 +00001881 } else {
1882 queue0 = index;
1883 }
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001884 } else {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001885 mask = (unsigned long) feature[RING_F_RSS].mask;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001886 queue0 = index & mask;
1887 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001888 }
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001889
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001890 rx_ring = &adapter->rx_ring[queue0];
1891
1892 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1893
1894 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1895 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1896
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001897 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1898 IXGBE_SRRCTL_BSIZEHDR_MASK;
1899
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001900 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001901#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
1902 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1903#else
1904 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1905#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001906 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001907 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00001908 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
1909 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001910 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001911 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001912
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001913 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1914}
1915
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00001916static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
1917{
1918 u32 mrqc = 0;
1919 int mask;
1920
1921 if (!(adapter->hw.mac.type == ixgbe_mac_82599EB))
1922 return mrqc;
1923
1924 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
1925#ifdef CONFIG_IXGBE_DCB
1926 | IXGBE_FLAG_DCB_ENABLED
1927#endif
1928 );
1929
1930 switch (mask) {
1931 case (IXGBE_FLAG_RSS_ENABLED):
1932 mrqc = IXGBE_MRQC_RSSEN;
1933 break;
1934#ifdef CONFIG_IXGBE_DCB
1935 case (IXGBE_FLAG_DCB_ENABLED):
1936 mrqc = IXGBE_MRQC_RT8TCEN;
1937 break;
1938#endif /* CONFIG_IXGBE_DCB */
1939 default:
1940 break;
1941 }
1942
1943 return mrqc;
1944}
1945
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001946/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001947 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001948 * @adapter: board private structure
1949 *
1950 * Configure the Rx unit of the MAC after a reset.
1951 **/
1952static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1953{
1954 u64 rdba;
1955 struct ixgbe_hw *hw = &adapter->hw;
1956 struct net_device *netdev = adapter->netdev;
1957 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001958 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001959 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001960 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1961 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1962 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001963 u32 fctrl, hlreg0;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001964 u32 reta = 0, mrqc = 0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001965 u32 rdrxctl;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001966 u32 rscctrl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001967 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07001968
1969 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001970 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07001971
Yi Zoueacd73f2009-05-13 13:11:06 +00001972#ifdef IXGBE_FCOE
1973 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
1974 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
1975#endif /* IXGBE_FCOE */
1976
Auke Kok9a799d72007-09-15 14:07:45 -07001977 /* Set the RX buffer length according to the mode */
1978 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001979 rx_buf_len = IXGBE_RX_HDR_SIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001980 if (hw->mac.type == ixgbe_mac_82599EB) {
1981 /* PSRTYPE must be initialized in 82599 */
1982 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
1983 IXGBE_PSRTYPE_UDPHDR |
1984 IXGBE_PSRTYPE_IPV4HDR |
Yi Zoudfa12f02009-05-07 10:39:35 +00001985 IXGBE_PSRTYPE_IPV6HDR |
1986 IXGBE_PSRTYPE_L2HDR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001987 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
1988 }
Auke Kok9a799d72007-09-15 14:07:45 -07001989 } else {
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00001990 if (!(adapter->flags & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00001991 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001992 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001993 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001994 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07001995 }
1996
1997 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1998 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001999 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002000 fctrl |= IXGBE_FCTRL_PMCF;
Auke Kok9a799d72007-09-15 14:07:45 -07002001 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
2002
2003 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2004 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2005 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
2006 else
2007 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Yi Zou63f39bd2009-05-17 12:34:35 +00002008#ifdef IXGBE_FCOE
2009 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2010 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2011#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002012 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2013
Auke Kok9a799d72007-09-15 14:07:45 -07002014 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
2015 /* disable receives while setting up the descriptors */
2016 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2017 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
2018
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002019 /*
2020 * Setup the HW Rx Head and Tail Descriptor Pointers and
2021 * the Base and Length of the Rx Descriptor Ring
2022 */
Auke Kok9a799d72007-09-15 14:07:45 -07002023 for (i = 0; i < adapter->num_rx_queues; i++) {
2024 rdba = adapter->rx_ring[i].dma;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002025 j = adapter->rx_ring[i].reg_idx;
Yang Hongyang284901a2009-04-06 19:01:15 -07002026 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32)));
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002027 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
2028 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
2029 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
2030 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
2031 adapter->rx_ring[i].head = IXGBE_RDH(j);
2032 adapter->rx_ring[i].tail = IXGBE_RDT(j);
2033 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002034
Yi Zou63f39bd2009-05-17 12:34:35 +00002035#ifdef IXGBE_FCOE
2036 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
2037 struct ixgbe_ring_feature *f;
2038 f = &adapter->ring_feature[RING_F_FCOE];
2039 if ((rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
2040 (i >= f->mask) && (i < f->mask + f->indices))
2041 adapter->rx_ring[i].rx_buf_len =
2042 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2043 }
2044
2045#endif /* IXGBE_FCOE */
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002046 ixgbe_configure_srrctl(adapter, j);
Auke Kok9a799d72007-09-15 14:07:45 -07002047 }
2048
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002049 if (hw->mac.type == ixgbe_mac_82598EB) {
2050 /*
2051 * For VMDq support of different descriptor types or
2052 * buffer sizes through the use of multiple SRRCTL
2053 * registers, RDRXCTL.MVMEN must be set to 1
2054 *
2055 * also, the manual doesn't mention it clearly but DCA hints
2056 * will only use queue 0's tags unless this bit is set. Side
2057 * effects of setting this bit are only that SRRCTL must be
2058 * fully programmed [0..15]
2059 */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002060 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2061 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
2062 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
Alexander Duyck2f90b862008-11-20 20:52:10 -08002063 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002064
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002065 /* Program MRQC for the distribution of queues */
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002066 mrqc = ixgbe_setup_mrqc(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002067
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002068 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07002069 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002070 for (i = 0, j = 0; i < 128; i++, j++) {
2071 if (j == adapter->ring_feature[RING_F_RSS].indices)
2072 j = 0;
2073 /* reta = 4-byte sliding window of
2074 * 0x00..(indices-1)(indices-1)00..etc. */
2075 reta = (reta << 8) | (j * 0x11);
2076 if ((i & 3) == 3)
2077 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07002078 }
2079
2080 /* Fill out hash function seeds */
2081 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002082 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002083
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002084 if (hw->mac.type == ixgbe_mac_82598EB)
2085 mrqc |= IXGBE_MRQC_RSSEN;
Auke Kok9a799d72007-09-15 14:07:45 -07002086 /* Perform hash on these packet types */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002087 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2088 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2089 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
2090 | IXGBE_MRQC_RSS_FIELD_IPV6
2091 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
2092 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07002093 }
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002094 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002095
2096 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2097
2098 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
2099 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
2100 /* Disable indicating checksum in descriptor, enables
2101 * RSS hash */
2102 rxcsum |= IXGBE_RXCSUM_PCSD;
2103 }
2104 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
2105 /* Enable IPv4 payload checksum for UDP fragments
2106 * if PCSD is not set */
2107 rxcsum |= IXGBE_RXCSUM_IPPCSE;
2108 }
2109
2110 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002111
2112 if (hw->mac.type == ixgbe_mac_82599EB) {
2113 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2114 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002115 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002116 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
2117 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002118
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00002119 if (adapter->flags & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002120 /* Enable 82599 HW-RSC */
2121 for (i = 0; i < adapter->num_rx_queues; i++) {
2122 j = adapter->rx_ring[i].reg_idx;
2123 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j));
2124 rscctrl |= IXGBE_RSCCTL_RSCEN;
2125 /*
Alexander Duycke76678d2009-05-17 20:57:47 +00002126 * we must limit the number of descriptors so that the
2127 * total size of max desc * buf_len is not greater
2128 * than 65535
Alexander Duyckf8212f92009-04-27 22:42:37 +00002129 */
Alexander Duycke76678d2009-05-17 20:57:47 +00002130 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
2131#if (MAX_SKB_FRAGS > 16)
2132 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2133#elif (MAX_SKB_FRAGS > 8)
Alexander Duyckf8212f92009-04-27 22:42:37 +00002134 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Alexander Duycke76678d2009-05-17 20:57:47 +00002135#elif (MAX_SKB_FRAGS > 4)
2136 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002137#else
Alexander Duycke76678d2009-05-17 20:57:47 +00002138 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002139#endif
Alexander Duycke76678d2009-05-17 20:57:47 +00002140 } else {
2141 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2142 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2143 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2144 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2145 else
2146 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2147 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002148 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl);
2149 }
2150 /* Disable RSC for ACK packets */
2151 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
2152 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
2153 }
Auke Kok9a799d72007-09-15 14:07:45 -07002154}
2155
Auke Kok9a799d72007-09-15 14:07:45 -07002156static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2157{
2158 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002159 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002160
2161 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002162 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002163}
2164
2165static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2166{
2167 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002168 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002169
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002170 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2171 ixgbe_irq_disable(adapter);
2172
Auke Kok9a799d72007-09-15 14:07:45 -07002173 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002174
2175 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2176 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002177
2178 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002179 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07002180}
2181
Don Skidmore068c89b2009-01-19 16:54:36 -08002182static void ixgbe_vlan_rx_register(struct net_device *netdev,
2183 struct vlan_group *grp)
2184{
2185 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2186 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002187 int i, j;
Don Skidmore068c89b2009-01-19 16:54:36 -08002188
2189 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2190 ixgbe_irq_disable(adapter);
2191 adapter->vlgrp = grp;
2192
2193 /*
2194 * For a DCB driver, always enable VLAN tag stripping so we can
2195 * still receive traffic from a DCB-enabled host even if we're
2196 * not in DCB mode.
2197 */
2198 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002199 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
2200 ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
Don Skidmore068c89b2009-01-19 16:54:36 -08002201 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2202 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002203 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
2204 ctrl |= IXGBE_VLNCTRL_VFE;
2205 /* enable VLAN tag insert/strip */
2206 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
2207 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2208 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
2209 for (i = 0; i < adapter->num_rx_queues; i++) {
2210 j = adapter->rx_ring[i].reg_idx;
2211 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
2212 ctrl |= IXGBE_RXDCTL_VME;
2213 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
2214 }
Don Skidmore068c89b2009-01-19 16:54:36 -08002215 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002216 ixgbe_vlan_rx_add_vid(netdev, 0);
Don Skidmore068c89b2009-01-19 16:54:36 -08002217
2218 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2219 ixgbe_irq_enable(adapter);
2220}
2221
Auke Kok9a799d72007-09-15 14:07:45 -07002222static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
2223{
2224 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2225
2226 if (adapter->vlgrp) {
2227 u16 vid;
2228 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2229 if (!vlan_group_get_device(adapter->vlgrp, vid))
2230 continue;
2231 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
2232 }
2233 }
2234}
2235
Christopher Leech2c5645c2008-08-26 04:27:02 -07002236static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
2237{
2238 struct dev_mc_list *mc_ptr;
2239 u8 *addr = *mc_addr_ptr;
2240 *vmdq = 0;
2241
2242 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
2243 if (mc_ptr->next)
2244 *mc_addr_ptr = mc_ptr->next->dmi_addr;
2245 else
2246 *mc_addr_ptr = NULL;
2247
2248 return addr;
2249}
2250
Auke Kok9a799d72007-09-15 14:07:45 -07002251/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07002252 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07002253 * @netdev: network interface device structure
2254 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07002255 * The set_rx_method entry point is called whenever the unicast/multicast
2256 * address list or the network interface flags are updated. This routine is
2257 * responsible for configuring the hardware for proper unicast, multicast and
2258 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07002259 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07002260static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07002261{
2262 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2263 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07002264 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002265 u8 *addr_list = NULL;
2266 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002267
2268 /* Check for Promiscuous and All Multicast modes */
2269
2270 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07002271 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07002272
2273 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07002274 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002275 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07002276 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07002277 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002278 if (netdev->flags & IFF_ALLMULTI) {
2279 fctrl |= IXGBE_FCTRL_MPE;
2280 fctrl &= ~IXGBE_FCTRL_UPE;
2281 } else {
2282 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2283 }
Alexander Duyck3d016252008-08-26 18:30:04 -07002284 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002285 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002286 }
2287
2288 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07002289 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07002290
Christopher Leech2c5645c2008-08-26 04:27:02 -07002291 /* reprogram secondary unicast list */
Jiri Pirkoccffad252009-05-22 23:22:17 +00002292 hw->mac.ops.update_uc_addr_list(hw, &netdev->uc_list);
Auke Kok9a799d72007-09-15 14:07:45 -07002293
Christopher Leech2c5645c2008-08-26 04:27:02 -07002294 /* reprogram multicast list */
2295 addr_count = netdev->mc_count;
2296 if (addr_count)
2297 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002298 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2299 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002300}
2301
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002302static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2303{
2304 int q_idx;
2305 struct ixgbe_q_vector *q_vector;
2306 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2307
2308 /* legacy and MSI only use one vector */
2309 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2310 q_vectors = 1;
2311
2312 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002313 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002314 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002315 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002316 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2317 if (!q_vector->rxr_count || !q_vector->txr_count) {
2318 if (q_vector->txr_count == 1)
2319 napi->poll = &ixgbe_clean_txonly;
2320 else if (q_vector->rxr_count == 1)
2321 napi->poll = &ixgbe_clean_rxonly;
2322 }
2323 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002324
2325 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002326 }
2327}
2328
2329static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2330{
2331 int q_idx;
2332 struct ixgbe_q_vector *q_vector;
2333 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2334
2335 /* legacy and MSI only use one vector */
2336 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2337 q_vectors = 1;
2338
2339 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002340 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002341 napi_disable(&q_vector->napi);
2342 }
2343}
2344
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002345#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002346/*
2347 * ixgbe_configure_dcb - Configure DCB hardware
2348 * @adapter: ixgbe adapter struct
2349 *
2350 * This is called by the driver on open to configure the DCB hardware.
2351 * This is also called by the gennetlink interface when reconfiguring
2352 * the DCB state.
2353 */
2354static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2355{
2356 struct ixgbe_hw *hw = &adapter->hw;
2357 u32 txdctl, vlnctrl;
2358 int i, j;
2359
2360 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2361 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2362 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2363
2364 /* reconfigure the hardware */
2365 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2366
2367 for (i = 0; i < adapter->num_tx_queues; i++) {
2368 j = adapter->tx_ring[i].reg_idx;
2369 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2370 /* PThresh workaround for Tx hang with DFP enabled. */
2371 txdctl |= 32;
2372 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2373 }
2374 /* Enable VLAN tag insert/strip */
2375 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002376 if (hw->mac.type == ixgbe_mac_82598EB) {
2377 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2378 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2379 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2380 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2381 vlnctrl |= IXGBE_VLNCTRL_VFE;
2382 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2383 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2384 for (i = 0; i < adapter->num_rx_queues; i++) {
2385 j = adapter->rx_ring[i].reg_idx;
2386 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2387 vlnctrl |= IXGBE_RXDCTL_VME;
2388 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2389 }
2390 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08002391 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2392}
2393
2394#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002395static void ixgbe_configure(struct ixgbe_adapter *adapter)
2396{
2397 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002398 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002399 int i;
2400
Christopher Leech2c5645c2008-08-26 04:27:02 -07002401 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002402
2403 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002404#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002405 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2406 netif_set_gso_max_size(netdev, 32768);
2407 ixgbe_configure_dcb(adapter);
2408 } else {
2409 netif_set_gso_max_size(netdev, 65536);
2410 }
2411#else
2412 netif_set_gso_max_size(netdev, 65536);
2413#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002414
Yi Zoueacd73f2009-05-13 13:11:06 +00002415#ifdef IXGBE_FCOE
2416 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2417 ixgbe_configure_fcoe(adapter);
2418
2419#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002420 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2421 for (i = 0; i < adapter->num_tx_queues; i++)
2422 adapter->tx_ring[i].atr_sample_rate =
2423 adapter->atr_sample_rate;
2424 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
2425 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
2426 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
2427 }
2428
Auke Kok9a799d72007-09-15 14:07:45 -07002429 ixgbe_configure_tx(adapter);
2430 ixgbe_configure_rx(adapter);
2431 for (i = 0; i < adapter->num_rx_queues; i++)
2432 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002433 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07002434}
2435
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002436static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2437{
2438 switch (hw->phy.type) {
2439 case ixgbe_phy_sfp_avago:
2440 case ixgbe_phy_sfp_ftl:
2441 case ixgbe_phy_sfp_intel:
2442 case ixgbe_phy_sfp_unknown:
2443 case ixgbe_phy_tw_tyco:
2444 case ixgbe_phy_tw_unknown:
2445 return true;
2446 default:
2447 return false;
2448 }
2449}
2450
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002451/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002452 * ixgbe_sfp_link_config - set up SFP+ link
2453 * @adapter: pointer to private adapter struct
2454 **/
2455static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2456{
2457 struct ixgbe_hw *hw = &adapter->hw;
2458
2459 if (hw->phy.multispeed_fiber) {
2460 /*
2461 * In multispeed fiber setups, the device may not have
2462 * had a physical connection when the driver loaded.
2463 * If that's the case, the initial link configuration
2464 * couldn't get the MAC into 10G or 1G mode, so we'll
2465 * never have a link status change interrupt fire.
2466 * We need to try and force an autonegotiation
2467 * session, then bring up link.
2468 */
2469 hw->mac.ops.setup_sfp(hw);
2470 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2471 schedule_work(&adapter->multispeed_fiber_task);
2472 } else {
2473 /*
2474 * Direct Attach Cu and non-multispeed fiber modules
2475 * still need to be configured properly prior to
2476 * attempting link.
2477 */
2478 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2479 schedule_work(&adapter->sfp_config_module_task);
2480 }
2481}
2482
2483/**
2484 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002485 * @hw: pointer to private hardware struct
2486 *
2487 * Returns 0 on success, negative on failure
2488 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002489static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002490{
2491 u32 autoneg;
2492 bool link_up = false;
2493 u32 ret = IXGBE_ERR_LINK_SETUP;
2494
2495 if (hw->mac.ops.check_link)
2496 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2497
2498 if (ret)
2499 goto link_cfg_out;
2500
2501 if (hw->mac.ops.get_link_capabilities)
2502 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
2503 &hw->mac.autoneg);
2504 if (ret)
2505 goto link_cfg_out;
2506
2507 if (hw->mac.ops.setup_link_speed)
2508 ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002509link_cfg_out:
2510 return ret;
2511}
2512
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002513#define IXGBE_MAX_RX_DESC_POLL 10
2514static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2515 int rxr)
2516{
2517 int j = adapter->rx_ring[rxr].reg_idx;
2518 int k;
2519
2520 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2521 if (IXGBE_READ_REG(&adapter->hw,
2522 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2523 break;
2524 else
2525 msleep(1);
2526 }
2527 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2528 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2529 "not set within the polling period\n", rxr);
2530 }
2531 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2532 (adapter->rx_ring[rxr].count - 1));
2533}
2534
Auke Kok9a799d72007-09-15 14:07:45 -07002535static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2536{
2537 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07002538 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002539 int i, j = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002540 int num_rx_rings = adapter->num_rx_queues;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002541 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002542 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002543 u32 txdctl, rxdctl, mhadd;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002544 u32 dmatxctl;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002545 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002546
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002547 ixgbe_get_hw_control(adapter);
2548
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002549 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2550 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002551 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2552 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002553 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002554 } else {
2555 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002556 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002557 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002558 /* XXX: to interrupt immediately for EICS writes, enable this */
2559 /* gpie |= IXGBE_GPIE_EIMEN; */
2560 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2561 }
2562
2563 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2564 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2565 * specifically only auto mask tx and rx interrupts */
2566 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002567 }
2568
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002569 /* Enable fan failure interrupt if media type is copper */
2570 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2571 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2572 gpie |= IXGBE_SDP1_GPIEN;
2573 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2574 }
2575
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002576 if (hw->mac.type == ixgbe_mac_82599EB) {
2577 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2578 gpie |= IXGBE_SDP1_GPIEN;
2579 gpie |= IXGBE_SDP2_GPIEN;
2580 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2581 }
2582
Yi Zou63f39bd2009-05-17 12:34:35 +00002583#ifdef IXGBE_FCOE
2584 /* adjust max frame to be able to do baby jumbo for FCoE */
2585 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
2586 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
2587 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
2588
2589#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07002590 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002591 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2592 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2593 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2594
2595 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2596 }
2597
2598 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002599 j = adapter->tx_ring[i].reg_idx;
2600 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002601 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2602 txdctl |= (8 << 16);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002603 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2604 }
2605
2606 if (hw->mac.type == ixgbe_mac_82599EB) {
2607 /* DMATXCTL.EN must be set after all Tx queue config is done */
2608 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2609 dmatxctl |= IXGBE_DMATXCTL_TE;
2610 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2611 }
2612 for (i = 0; i < adapter->num_tx_queues; i++) {
2613 j = adapter->tx_ring[i].reg_idx;
2614 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Auke Kok9a799d72007-09-15 14:07:45 -07002615 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002616 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002617 }
2618
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002619 for (i = 0; i < num_rx_rings; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002620 j = adapter->rx_ring[i].reg_idx;
2621 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2622 /* enable PTHRESH=32 descriptors (half the internal cache)
2623 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2624 * this also removes a pesky rx_no_buffer_count increment */
2625 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002626 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002627 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002628 if (hw->mac.type == ixgbe_mac_82599EB)
2629 ixgbe_rx_desc_queue_enable(adapter, i);
Auke Kok9a799d72007-09-15 14:07:45 -07002630 }
2631 /* enable all receives */
2632 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002633 if (hw->mac.type == ixgbe_mac_82598EB)
2634 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2635 else
2636 rxdctl |= IXGBE_RXCTRL_RXEN;
2637 hw->mac.ops.enable_rx_dma(hw, rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002638
2639 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2640 ixgbe_configure_msix(adapter);
2641 else
2642 ixgbe_configure_msi_and_legacy(adapter);
2643
2644 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002645 ixgbe_napi_enable_all(adapter);
2646
2647 /* clear any pending interrupts, may auto mask */
2648 IXGBE_READ_REG(hw, IXGBE_EICR);
2649
Auke Kok9a799d72007-09-15 14:07:45 -07002650 ixgbe_irq_enable(adapter);
2651
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002652 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00002653 * If this adapter has a fan, check to see if we had a failure
2654 * before we enabled the interrupt.
2655 */
2656 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2657 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2658 if (esdp & IXGBE_ESDP_SDP1)
2659 DPRINTK(DRV, CRIT,
2660 "Fan has stopped, replace the adapter\n");
2661 }
2662
2663 /*
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002664 * For hot-pluggable SFP+ devices, a new SFP+ module may have
2665 * arrived before interrupts were enabled. We need to kick off
2666 * the SFP+ module setup first, then try to bring up link.
2667 * If we're not hot-pluggable SFP+, we just need to configure link
2668 * and bring it up.
2669 */
2670 err = hw->phy.ops.identify(hw);
2671 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2672 DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err);
2673 ixgbe_down(adapter);
2674 return err;
2675 }
2676
2677 if (ixgbe_is_sfp(hw)) {
2678 ixgbe_sfp_link_config(adapter);
2679 } else {
2680 err = ixgbe_non_sfp_link_config(hw);
2681 if (err)
2682 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2683 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002684
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002685 for (i = 0; i < adapter->num_tx_queues; i++)
2686 set_bit(__IXGBE_FDIR_INIT_DONE,
2687 &(adapter->tx_ring[i].reinit_state));
2688
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002689 /* enable transmits */
2690 netif_tx_start_all_queues(netdev);
2691
Auke Kok9a799d72007-09-15 14:07:45 -07002692 /* bring the link up in the watchdog, this could race with our first
2693 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002694 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2695 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002696 mod_timer(&adapter->watchdog_timer, jiffies);
2697 return 0;
2698}
2699
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002700void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2701{
2702 WARN_ON(in_interrupt());
2703 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2704 msleep(1);
2705 ixgbe_down(adapter);
2706 ixgbe_up(adapter);
2707 clear_bit(__IXGBE_RESETTING, &adapter->state);
2708}
2709
Auke Kok9a799d72007-09-15 14:07:45 -07002710int ixgbe_up(struct ixgbe_adapter *adapter)
2711{
2712 /* hardware has been reset, we need to reload some things */
2713 ixgbe_configure(adapter);
2714
2715 return ixgbe_up_complete(adapter);
2716}
2717
2718void ixgbe_reset(struct ixgbe_adapter *adapter)
2719{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002720 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07002721 int err;
2722
2723 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002724 switch (err) {
2725 case 0:
2726 case IXGBE_ERR_SFP_NOT_PRESENT:
2727 break;
2728 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
2729 dev_err(&adapter->pdev->dev, "master disable timed out\n");
2730 break;
2731 default:
2732 dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err);
2733 }
Auke Kok9a799d72007-09-15 14:07:45 -07002734
2735 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002736 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002737}
2738
Auke Kok9a799d72007-09-15 14:07:45 -07002739/**
2740 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2741 * @adapter: board private structure
2742 * @rx_ring: ring to free buffers from
2743 **/
2744static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002745 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002746{
2747 struct pci_dev *pdev = adapter->pdev;
2748 unsigned long size;
2749 unsigned int i;
2750
2751 /* Free all the Rx ring sk_buffs */
2752
2753 for (i = 0; i < rx_ring->count; i++) {
2754 struct ixgbe_rx_buffer *rx_buffer_info;
2755
2756 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2757 if (rx_buffer_info->dma) {
2758 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002759 rx_ring->rx_buf_len,
2760 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002761 rx_buffer_info->dma = 0;
2762 }
2763 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002764 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002765 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002766 do {
2767 struct sk_buff *this = skb;
2768 skb = skb->prev;
2769 dev_kfree_skb(this);
2770 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002771 }
2772 if (!rx_buffer_info->page)
2773 continue;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002774 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2775 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002776 rx_buffer_info->page_dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002777 put_page(rx_buffer_info->page);
2778 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002779 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002780 }
2781
2782 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2783 memset(rx_ring->rx_buffer_info, 0, size);
2784
2785 /* Zero out the descriptor ring */
2786 memset(rx_ring->desc, 0, rx_ring->size);
2787
2788 rx_ring->next_to_clean = 0;
2789 rx_ring->next_to_use = 0;
2790
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002791 if (rx_ring->head)
2792 writel(0, adapter->hw.hw_addr + rx_ring->head);
2793 if (rx_ring->tail)
2794 writel(0, adapter->hw.hw_addr + rx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002795}
2796
2797/**
2798 * ixgbe_clean_tx_ring - Free Tx Buffers
2799 * @adapter: board private structure
2800 * @tx_ring: ring to be cleaned
2801 **/
2802static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002803 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002804{
2805 struct ixgbe_tx_buffer *tx_buffer_info;
2806 unsigned long size;
2807 unsigned int i;
2808
2809 /* Free all the Tx ring sk_buffs */
2810
2811 for (i = 0; i < tx_ring->count; i++) {
2812 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2813 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2814 }
2815
2816 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2817 memset(tx_ring->tx_buffer_info, 0, size);
2818
2819 /* Zero out the descriptor ring */
2820 memset(tx_ring->desc, 0, tx_ring->size);
2821
2822 tx_ring->next_to_use = 0;
2823 tx_ring->next_to_clean = 0;
2824
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002825 if (tx_ring->head)
2826 writel(0, adapter->hw.hw_addr + tx_ring->head);
2827 if (tx_ring->tail)
2828 writel(0, adapter->hw.hw_addr + tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002829}
2830
2831/**
Auke Kok9a799d72007-09-15 14:07:45 -07002832 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2833 * @adapter: board private structure
2834 **/
2835static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2836{
2837 int i;
2838
2839 for (i = 0; i < adapter->num_rx_queues; i++)
2840 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2841}
2842
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002843/**
2844 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2845 * @adapter: board private structure
2846 **/
2847static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2848{
2849 int i;
2850
2851 for (i = 0; i < adapter->num_tx_queues; i++)
2852 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2853}
2854
Auke Kok9a799d72007-09-15 14:07:45 -07002855void ixgbe_down(struct ixgbe_adapter *adapter)
2856{
2857 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002858 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002859 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002860 u32 txdctl;
2861 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002862
2863 /* signal that we are down to the interrupt handler */
2864 set_bit(__IXGBE_DOWN, &adapter->state);
2865
2866 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002867 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2868 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002869
2870 netif_tx_disable(netdev);
2871
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002872 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002873 msleep(10);
2874
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002875 netif_tx_stop_all_queues(netdev);
2876
Auke Kok9a799d72007-09-15 14:07:45 -07002877 ixgbe_irq_disable(adapter);
2878
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002879 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002880
Auke Kok9a799d72007-09-15 14:07:45 -07002881 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002882 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002883
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002884 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
2885 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2886 cancel_work_sync(&adapter->fdir_reinit_task);
2887
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002888 /* disable transmits in the hardware now that interrupts are off */
2889 for (i = 0; i < adapter->num_tx_queues; i++) {
2890 j = adapter->tx_ring[i].reg_idx;
2891 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2892 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2893 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2894 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00002895 /* Disable the Tx DMA engine on 82599 */
2896 if (hw->mac.type == ixgbe_mac_82599EB)
2897 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
2898 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
2899 ~IXGBE_DMATXCTL_TE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002900
Auke Kok9a799d72007-09-15 14:07:45 -07002901 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002902
Paul Larson6f4a0e42008-06-24 17:00:56 -07002903 if (!pci_channel_offline(adapter->pdev))
2904 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002905 ixgbe_clean_all_tx_rings(adapter);
2906 ixgbe_clean_all_rx_rings(adapter);
2907
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002908#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002909 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00002910 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002911#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002912}
2913
Auke Kok9a799d72007-09-15 14:07:45 -07002914/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002915 * ixgbe_poll - NAPI Rx polling callback
2916 * @napi: structure for representing this polling device
2917 * @budget: how many packets driver is allowed to clean
2918 *
2919 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002920 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002921static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002922{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002923 struct ixgbe_q_vector *q_vector =
2924 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002925 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002926 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002927
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002928#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002929 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2930 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2931 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2932 }
2933#endif
2934
Alexander Duyckfe49f042009-06-04 16:00:09 +00002935 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002936 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002937
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002938 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002939 work_done = budget;
2940
David S. Miller53e52c72008-01-07 21:06:12 -08002941 /* If budget not fully consumed, exit the polling mode */
2942 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002943 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002944 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002945 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002946 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00002947 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002948 }
Auke Kok9a799d72007-09-15 14:07:45 -07002949 return work_done;
2950}
2951
2952/**
2953 * ixgbe_tx_timeout - Respond to a Tx Hang
2954 * @netdev: network interface device structure
2955 **/
2956static void ixgbe_tx_timeout(struct net_device *netdev)
2957{
2958 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2959
2960 /* Do the reset outside of interrupt context */
2961 schedule_work(&adapter->reset_task);
2962}
2963
2964static void ixgbe_reset_task(struct work_struct *work)
2965{
2966 struct ixgbe_adapter *adapter;
2967 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2968
Alexander Duyck2f90b862008-11-20 20:52:10 -08002969 /* If we're already down or resetting, just bail */
2970 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2971 test_bit(__IXGBE_RESETTING, &adapter->state))
2972 return;
2973
Auke Kok9a799d72007-09-15 14:07:45 -07002974 adapter->tx_timeout_count++;
2975
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002976 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002977}
2978
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002979#ifdef CONFIG_IXGBE_DCB
2980static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002981{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002982 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002983 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002984
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002985 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
2986 return ret;
2987
2988 f->mask = 0x7 << 3;
2989 adapter->num_rx_queues = f->indices;
2990 adapter->num_tx_queues = f->indices;
2991 ret = true;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002992
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002993 return ret;
2994}
2995#endif
2996
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002997/**
2998 * ixgbe_set_rss_queues: Allocate queues for RSS
2999 * @adapter: board private structure to initialize
3000 *
3001 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
3002 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
3003 *
3004 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003005static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
3006{
3007 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003008 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003009
3010 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003011 f->mask = 0xF;
3012 adapter->num_rx_queues = f->indices;
3013 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003014 ret = true;
3015 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003016 ret = false;
3017 }
3018
3019 return ret;
3020}
3021
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003022/**
3023 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
3024 * @adapter: board private structure to initialize
3025 *
3026 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
3027 * to the original CPU that initiated the Tx session. This runs in addition
3028 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
3029 * Rx load across CPUs using RSS.
3030 *
3031 **/
3032static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
3033{
3034 bool ret = false;
3035 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
3036
3037 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
3038 f_fdir->mask = 0;
3039
3040 /* Flow Director must have RSS enabled */
3041 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3042 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3043 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
3044 adapter->num_tx_queues = f_fdir->indices;
3045 adapter->num_rx_queues = f_fdir->indices;
3046 ret = true;
3047 } else {
3048 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3049 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3050 }
3051 return ret;
3052}
3053
Yi Zou0331a832009-05-17 12:33:52 +00003054#ifdef IXGBE_FCOE
3055/**
3056 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
3057 * @adapter: board private structure to initialize
3058 *
3059 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
3060 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
3061 * rx queues out of the max number of rx queues, instead, it is used as the
3062 * index of the first rx queue used by FCoE.
3063 *
3064 **/
3065static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
3066{
3067 bool ret = false;
3068 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3069
3070 f->indices = min((int)num_online_cpus(), f->indices);
3071 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3072#ifdef CONFIG_IXGBE_DCB
3073 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3074 DPRINTK(PROBE, INFO, "FCOE enabled with DCB \n");
3075 ixgbe_set_dcb_queues(adapter);
3076 }
3077#endif
3078 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3079 DPRINTK(PROBE, INFO, "FCOE enabled with RSS \n");
3080 ixgbe_set_rss_queues(adapter);
3081 }
3082 /* adding FCoE rx rings to the end */
3083 f->mask = adapter->num_rx_queues;
3084 adapter->num_rx_queues += f->indices;
3085 if (adapter->num_tx_queues == 0)
3086 adapter->num_tx_queues = f->indices;
3087
3088 ret = true;
3089 }
3090
3091 return ret;
3092}
3093
3094#endif /* IXGBE_FCOE */
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003095/*
3096 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
3097 * @adapter: board private structure to initialize
3098 *
3099 * This is the top level queue allocation routine. The order here is very
3100 * important, starting with the "most" number of features turned on at once,
3101 * and ending with the smallest set of features. This way large combinations
3102 * can be allocated if they're turned on, and smaller combinations are the
3103 * fallthrough conditions.
3104 *
3105 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003106static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
3107{
Yi Zou0331a832009-05-17 12:33:52 +00003108#ifdef IXGBE_FCOE
3109 if (ixgbe_set_fcoe_queues(adapter))
3110 goto done;
3111
3112#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003113#ifdef CONFIG_IXGBE_DCB
3114 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003115 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003116
3117#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003118 if (ixgbe_set_fdir_queues(adapter))
3119 goto done;
3120
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003121 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003122 goto done;
3123
3124 /* fallback to base case */
3125 adapter->num_rx_queues = 1;
3126 adapter->num_tx_queues = 1;
3127
3128done:
3129 /* Notify the stack of the (possibly) reduced Tx Queue count. */
3130 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003131}
3132
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003133static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003134 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003135{
3136 int err, vector_threshold;
3137
3138 /* We'll want at least 3 (vector_threshold):
3139 * 1) TxQ[0] Cleanup
3140 * 2) RxQ[0] Cleanup
3141 * 3) Other (Link Status Change, etc.)
3142 * 4) TCP Timer (optional)
3143 */
3144 vector_threshold = MIN_MSIX_COUNT;
3145
3146 /* The more we get, the more we will assign to Tx/Rx Cleanup
3147 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
3148 * Right now, we simply care about how many we'll get; we'll
3149 * set them up later while requesting irq's.
3150 */
3151 while (vectors >= vector_threshold) {
3152 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003153 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003154 if (!err) /* Success in acquiring all requested vectors. */
3155 break;
3156 else if (err < 0)
3157 vectors = 0; /* Nasty failure, quit now */
3158 else /* err == number of vectors we should try again with */
3159 vectors = err;
3160 }
3161
3162 if (vectors < vector_threshold) {
3163 /* Can't allocate enough MSI-X interrupts? Oh well.
3164 * This just means we'll go with either a single MSI
3165 * vector or fall back to legacy interrupts.
3166 */
3167 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
3168 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3169 kfree(adapter->msix_entries);
3170 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003171 } else {
3172 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08003173 /*
3174 * Adjust for only the vectors we'll use, which is minimum
3175 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
3176 * vectors we were allocated.
3177 */
3178 adapter->num_msix_vectors = min(vectors,
3179 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003180 }
3181}
3182
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003183/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003184 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003185 * @adapter: board private structure to initialize
3186 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003187 * Cache the descriptor ring offsets for RSS to the assigned rings.
3188 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003189 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003190static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003191{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003192 int i;
3193 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003194
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003195 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3196 for (i = 0; i < adapter->num_rx_queues; i++)
3197 adapter->rx_ring[i].reg_idx = i;
3198 for (i = 0; i < adapter->num_tx_queues; i++)
3199 adapter->tx_ring[i].reg_idx = i;
3200 ret = true;
3201 } else {
3202 ret = false;
3203 }
3204
3205 return ret;
3206}
3207
3208#ifdef CONFIG_IXGBE_DCB
3209/**
3210 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
3211 * @adapter: board private structure to initialize
3212 *
3213 * Cache the descriptor ring offsets for DCB to the assigned rings.
3214 *
3215 **/
3216static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
3217{
3218 int i;
3219 bool ret = false;
3220 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
3221
3222 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3223 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08003224 /* the number of queues is assumed to be symmetric */
3225 for (i = 0; i < dcb_i; i++) {
3226 adapter->rx_ring[i].reg_idx = i << 3;
3227 adapter->tx_ring[i].reg_idx = i << 2;
3228 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003229 ret = true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003230 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
PJ Waskiewiczf92ef202009-04-16 15:00:20 +00003231 if (dcb_i == 8) {
3232 /*
3233 * Tx TC0 starts at: descriptor queue 0
3234 * Tx TC1 starts at: descriptor queue 32
3235 * Tx TC2 starts at: descriptor queue 64
3236 * Tx TC3 starts at: descriptor queue 80
3237 * Tx TC4 starts at: descriptor queue 96
3238 * Tx TC5 starts at: descriptor queue 104
3239 * Tx TC6 starts at: descriptor queue 112
3240 * Tx TC7 starts at: descriptor queue 120
3241 *
3242 * Rx TC0-TC7 are offset by 16 queues each
3243 */
3244 for (i = 0; i < 3; i++) {
3245 adapter->tx_ring[i].reg_idx = i << 5;
3246 adapter->rx_ring[i].reg_idx = i << 4;
3247 }
3248 for ( ; i < 5; i++) {
3249 adapter->tx_ring[i].reg_idx =
3250 ((i + 2) << 4);
3251 adapter->rx_ring[i].reg_idx = i << 4;
3252 }
3253 for ( ; i < dcb_i; i++) {
3254 adapter->tx_ring[i].reg_idx =
3255 ((i + 8) << 3);
3256 adapter->rx_ring[i].reg_idx = i << 4;
3257 }
3258
3259 ret = true;
3260 } else if (dcb_i == 4) {
3261 /*
3262 * Tx TC0 starts at: descriptor queue 0
3263 * Tx TC1 starts at: descriptor queue 64
3264 * Tx TC2 starts at: descriptor queue 96
3265 * Tx TC3 starts at: descriptor queue 112
3266 *
3267 * Rx TC0-TC3 are offset by 32 queues each
3268 */
3269 adapter->tx_ring[0].reg_idx = 0;
3270 adapter->tx_ring[1].reg_idx = 64;
3271 adapter->tx_ring[2].reg_idx = 96;
3272 adapter->tx_ring[3].reg_idx = 112;
3273 for (i = 0 ; i < dcb_i; i++)
3274 adapter->rx_ring[i].reg_idx = i << 5;
3275
3276 ret = true;
3277 } else {
3278 ret = false;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003279 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003280 } else {
3281 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003282 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003283 } else {
3284 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003285 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003286
3287 return ret;
3288}
3289#endif
3290
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003291/**
3292 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
3293 * @adapter: board private structure to initialize
3294 *
3295 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
3296 *
3297 **/
3298static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
3299{
3300 int i;
3301 bool ret = false;
3302
3303 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3304 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3305 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
3306 for (i = 0; i < adapter->num_rx_queues; i++)
3307 adapter->rx_ring[i].reg_idx = i;
3308 for (i = 0; i < adapter->num_tx_queues; i++)
3309 adapter->tx_ring[i].reg_idx = i;
3310 ret = true;
3311 }
3312
3313 return ret;
3314}
3315
Yi Zou0331a832009-05-17 12:33:52 +00003316#ifdef IXGBE_FCOE
3317/**
3318 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
3319 * @adapter: board private structure to initialize
3320 *
3321 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
3322 *
3323 */
3324static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
3325{
3326 int i, fcoe_i = 0;
3327 bool ret = false;
3328 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3329
3330 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3331#ifdef CONFIG_IXGBE_DCB
3332 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3333 ixgbe_cache_ring_dcb(adapter);
3334 fcoe_i = adapter->rx_ring[0].reg_idx + 1;
3335 }
3336#endif /* CONFIG_IXGBE_DCB */
3337 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3338 ixgbe_cache_ring_rss(adapter);
3339 fcoe_i = f->mask;
3340 }
3341 for (i = 0; i < f->indices; i++, fcoe_i++)
3342 adapter->rx_ring[f->mask + i].reg_idx = fcoe_i;
3343 ret = true;
3344 }
3345 return ret;
3346}
3347
3348#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003349/**
3350 * ixgbe_cache_ring_register - Descriptor ring to register mapping
3351 * @adapter: board private structure to initialize
3352 *
3353 * Once we know the feature-set enabled for the device, we'll cache
3354 * the register offset the descriptor ring is assigned to.
3355 *
3356 * Note, the order the various feature calls is important. It must start with
3357 * the "most" features enabled at the same time, then trickle down to the
3358 * least amount of features turned on at once.
3359 **/
3360static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
3361{
3362 /* start with default case */
3363 adapter->rx_ring[0].reg_idx = 0;
3364 adapter->tx_ring[0].reg_idx = 0;
3365
Yi Zou0331a832009-05-17 12:33:52 +00003366#ifdef IXGBE_FCOE
3367 if (ixgbe_cache_ring_fcoe(adapter))
3368 return;
3369
3370#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003371#ifdef CONFIG_IXGBE_DCB
3372 if (ixgbe_cache_ring_dcb(adapter))
3373 return;
3374
3375#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003376 if (ixgbe_cache_ring_fdir(adapter))
3377 return;
3378
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003379 if (ixgbe_cache_ring_rss(adapter))
3380 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003381}
3382
Auke Kok9a799d72007-09-15 14:07:45 -07003383/**
3384 * ixgbe_alloc_queues - Allocate memory for all rings
3385 * @adapter: board private structure to initialize
3386 *
3387 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003388 * number of queues at compile-time. The polling_netdev array is
3389 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07003390 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003391static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003392{
3393 int i;
3394
3395 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003396 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07003397 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003398 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07003399
3400 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003401 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003402 if (!adapter->rx_ring)
3403 goto err_rx_ring_allocation;
3404
3405 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003406 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003407 adapter->tx_ring[i].queue_index = i;
3408 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003409
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003410 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003411 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003412 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07003413 }
3414
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003415 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003416
3417 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003418
3419err_rx_ring_allocation:
3420 kfree(adapter->tx_ring);
3421err_tx_ring_allocation:
3422 return -ENOMEM;
3423}
3424
3425/**
3426 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3427 * @adapter: board private structure to initialize
3428 *
3429 * Attempt to configure the interrupts using the best available
3430 * capabilities of the hardware and the kernel.
3431 **/
Al Virofeea6a52008-11-27 15:34:07 -08003432static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003433{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003434 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003435 int err = 0;
3436 int vector, v_budget;
3437
3438 /*
3439 * It's easy to be greedy for MSI-X vectors, but it really
3440 * doesn't do us much good if we have a lot more vectors
3441 * than CPU's. So let's be conservative and only ask for
3442 * (roughly) twice the number of vectors as there are CPU's.
3443 */
3444 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003445 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003446
3447 /*
3448 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003449 * hw.mac->max_msix_vectors vectors. With features
3450 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3451 * descriptor queues supported by our device. Thus, we cap it off in
3452 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003453 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003454 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003455
3456 /* A failure in MSI-X entry allocation isn't fatal, but it does
3457 * mean we disable MSI-X capabilities of the adapter. */
3458 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003459 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003460 if (adapter->msix_entries) {
3461 for (vector = 0; vector < v_budget; vector++)
3462 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003463
Alexander Duyck7a921c92009-05-06 10:43:28 +00003464 ixgbe_acquire_msix_vectors(adapter, v_budget);
3465
3466 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3467 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003468 }
3469
Alexander Duyck7a921c92009-05-06 10:43:28 +00003470 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
3471 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003472 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3473 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3474 adapter->atr_sample_rate = 0;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003475 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003476
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003477 err = pci_enable_msi(adapter->pdev);
3478 if (!err) {
3479 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
3480 } else {
3481 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003482 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003483 /* reset err */
3484 err = 0;
3485 }
3486
3487out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003488 return err;
3489}
3490
Alexander Duyck7a921c92009-05-06 10:43:28 +00003491/**
3492 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
3493 * @adapter: board private structure to initialize
3494 *
3495 * We allocate one q_vector per queue interrupt. If allocation fails we
3496 * return -ENOMEM.
3497 **/
3498static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
3499{
3500 int q_idx, num_q_vectors;
3501 struct ixgbe_q_vector *q_vector;
3502 int napi_vectors;
3503 int (*poll)(struct napi_struct *, int);
3504
3505 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3506 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3507 napi_vectors = adapter->num_rx_queues;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003508 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003509 } else {
3510 num_q_vectors = 1;
3511 napi_vectors = 1;
3512 poll = &ixgbe_poll;
3513 }
3514
3515 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3516 q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL);
3517 if (!q_vector)
3518 goto err_out;
3519 q_vector->adapter = adapter;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003520 q_vector->eitr = adapter->eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00003521 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003522 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003523 adapter->q_vector[q_idx] = q_vector;
3524 }
3525
3526 return 0;
3527
3528err_out:
3529 while (q_idx) {
3530 q_idx--;
3531 q_vector = adapter->q_vector[q_idx];
3532 netif_napi_del(&q_vector->napi);
3533 kfree(q_vector);
3534 adapter->q_vector[q_idx] = NULL;
3535 }
3536 return -ENOMEM;
3537}
3538
3539/**
3540 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
3541 * @adapter: board private structure to initialize
3542 *
3543 * This function frees the memory allocated to the q_vectors. In addition if
3544 * NAPI is enabled it will delete any references to the NAPI struct prior
3545 * to freeing the q_vector.
3546 **/
3547static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
3548{
3549 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003550
Alexander Duyck91281fd2009-06-04 16:00:27 +00003551 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00003552 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003553 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00003554 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003555
3556 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3557 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00003558 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003559 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003560 kfree(q_vector);
3561 }
3562}
3563
Alexander Duyck2f90b862008-11-20 20:52:10 -08003564void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003565{
3566 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3567 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3568 pci_disable_msix(adapter->pdev);
3569 kfree(adapter->msix_entries);
3570 adapter->msix_entries = NULL;
3571 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
3572 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
3573 pci_disable_msi(adapter->pdev);
3574 }
3575 return;
3576}
3577
3578/**
3579 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3580 * @adapter: board private structure to initialize
3581 *
3582 * We determine which interrupt scheme to use based on...
3583 * - Kernel support (MSI, MSI-X)
3584 * - which can be user-defined (via MODULE_PARAM)
3585 * - Hardware queue count (num_*_queues)
3586 * - defined by miscellaneous hardware support/features (RSS, etc.)
3587 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003588int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003589{
3590 int err;
3591
3592 /* Number of supported queues */
3593 ixgbe_set_num_queues(adapter);
3594
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003595 err = ixgbe_set_interrupt_capability(adapter);
3596 if (err) {
3597 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3598 goto err_set_interrupt;
3599 }
3600
Alexander Duyck7a921c92009-05-06 10:43:28 +00003601 err = ixgbe_alloc_q_vectors(adapter);
3602 if (err) {
3603 DPRINTK(PROBE, ERR, "Unable to allocate memory for queue "
3604 "vectors\n");
3605 goto err_alloc_q_vectors;
3606 }
3607
3608 err = ixgbe_alloc_queues(adapter);
3609 if (err) {
3610 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3611 goto err_alloc_queues;
3612 }
3613
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003614 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003615 "Tx Queue count = %u\n",
3616 (adapter->num_rx_queues > 1) ? "Enabled" :
3617 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003618
3619 set_bit(__IXGBE_DOWN, &adapter->state);
3620
3621 return 0;
3622
Alexander Duyck7a921c92009-05-06 10:43:28 +00003623err_alloc_queues:
3624 ixgbe_free_q_vectors(adapter);
3625err_alloc_q_vectors:
3626 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003627err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00003628 return err;
3629}
3630
3631/**
3632 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
3633 * @adapter: board private structure to clear interrupt scheme on
3634 *
3635 * We go through and clear interrupt specific resources and reset the structure
3636 * to pre-load conditions
3637 **/
3638void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
3639{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003640 kfree(adapter->tx_ring);
3641 kfree(adapter->rx_ring);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003642 adapter->tx_ring = NULL;
3643 adapter->rx_ring = NULL;
3644
3645 ixgbe_free_q_vectors(adapter);
3646 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003647}
3648
3649/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08003650 * ixgbe_sfp_timer - worker thread to find a missing module
3651 * @data: pointer to our adapter struct
3652 **/
3653static void ixgbe_sfp_timer(unsigned long data)
3654{
3655 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3656
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003657 /*
3658 * Do the sfp_timer outside of interrupt context due to the
Donald Skidmorec4900be2008-11-20 21:11:42 -08003659 * delays that sfp+ detection requires
3660 */
3661 schedule_work(&adapter->sfp_task);
3662}
3663
3664/**
3665 * ixgbe_sfp_task - worker thread to find a missing module
3666 * @work: pointer to work_struct containing our data
3667 **/
3668static void ixgbe_sfp_task(struct work_struct *work)
3669{
3670 struct ixgbe_adapter *adapter = container_of(work,
3671 struct ixgbe_adapter,
3672 sfp_task);
3673 struct ixgbe_hw *hw = &adapter->hw;
3674
3675 if ((hw->phy.type == ixgbe_phy_nl) &&
3676 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3677 s32 ret = hw->phy.ops.identify_sfp(hw);
3678 if (ret)
3679 goto reschedule;
3680 ret = hw->phy.ops.reset(hw);
3681 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
3682 DPRINTK(PROBE, ERR, "failed to initialize because an "
3683 "unsupported SFP+ module type was detected.\n"
3684 "Reload the driver after installing a "
3685 "supported module.\n");
3686 unregister_netdev(adapter->netdev);
3687 } else {
3688 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3689 hw->phy.sfp_type);
3690 }
3691 /* don't need this routine any more */
3692 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3693 }
3694 return;
3695reschedule:
3696 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3697 mod_timer(&adapter->sfp_timer,
3698 round_jiffies(jiffies + (2 * HZ)));
3699}
3700
3701/**
Auke Kok9a799d72007-09-15 14:07:45 -07003702 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3703 * @adapter: board private structure to initialize
3704 *
3705 * ixgbe_sw_init initializes the Adapter private data structure.
3706 * Fields are initialized based on PCI device information and
3707 * OS network device settings (MTU size).
3708 **/
3709static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3710{
3711 struct ixgbe_hw *hw = &adapter->hw;
3712 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003713 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003714#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003715 int j;
3716 struct tc_configuration *tc;
3717#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003718
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003719 /* PCI config space info */
3720
3721 hw->vendor_id = pdev->vendor;
3722 hw->device_id = pdev->device;
3723 hw->revision_id = pdev->revision;
3724 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3725 hw->subsystem_device_id = pdev->subsystem_device;
3726
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003727 /* Set capability flags */
3728 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3729 adapter->ring_feature[RING_F_RSS].indices = rss;
3730 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003731 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Don Skidmorebf069c92009-05-07 10:39:54 +00003732 if (hw->mac.type == ixgbe_mac_82598EB) {
3733 if (hw->device_id == IXGBE_DEV_ID_82598AT)
3734 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003735 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Don Skidmorebf069c92009-05-07 10:39:54 +00003736 } else if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003737 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00003738 adapter->flags |= IXGBE_FLAG2_RSC_CAPABLE;
3739 adapter->flags |= IXGBE_FLAG2_RSC_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003740 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
3741 adapter->ring_feature[RING_F_FDIR].indices =
3742 IXGBE_MAX_FDIR_INDICES;
3743 adapter->atr_sample_rate = 20;
3744 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00003745#ifdef IXGBE_FCOE
3746 adapter->flags |= IXGBE_FLAG_FCOE_ENABLED;
Yi Zou0331a832009-05-17 12:33:52 +00003747 adapter->ring_feature[RING_F_FCOE].indices = IXGBE_FCRETA_SIZE;
Yi Zoueacd73f2009-05-13 13:11:06 +00003748#endif /* IXGBE_FCOE */
Alexander Duyckf8212f92009-04-27 22:42:37 +00003749 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003750
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003751#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003752 /* Configure DCB traffic classes */
3753 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3754 tc = &adapter->dcb_cfg.tc_config[j];
3755 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3756 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3757 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3758 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3759 tc->dcb_pfc = pfc_disabled;
3760 }
3761 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3762 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3763 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003764 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003765 adapter->dcb_cfg.round_robin_enable = false;
3766 adapter->dcb_set_bitmap = 0x00;
3767 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3768 adapter->ring_feature[RING_F_DCB].indices);
3769
3770#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003771
3772 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00003773 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00003774 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003775#ifdef CONFIG_DCB
3776 adapter->last_lfc_mode = hw->fc.current_mode;
3777#endif
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07003778 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3779 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3780 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3781 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00003782 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07003783
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07003784 /* enable itr by default in dynamic mode */
3785 adapter->itr_setting = 1;
3786 adapter->eitr_param = 20000;
3787
3788 /* set defaults for eitr in MegaBytes */
3789 adapter->eitr_low = 10;
3790 adapter->eitr_high = 20;
3791
3792 /* set default ring sizes */
3793 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
3794 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
3795
Auke Kok9a799d72007-09-15 14:07:45 -07003796 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003797 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003798 dev_err(&pdev->dev, "EEPROM initialization failed\n");
3799 return -EIO;
3800 }
3801
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003802 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07003803 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
3804
Auke Kok9a799d72007-09-15 14:07:45 -07003805 set_bit(__IXGBE_DOWN, &adapter->state);
3806
3807 return 0;
3808}
3809
3810/**
3811 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3812 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003813 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003814 *
3815 * Return 0 on success, negative on failure
3816 **/
3817int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003818 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003819{
3820 struct pci_dev *pdev = adapter->pdev;
3821 int size;
3822
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003823 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3824 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003825 if (!tx_ring->tx_buffer_info)
3826 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003827 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003828
3829 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08003830 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003831 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003832
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003833 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
3834 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003835 if (!tx_ring->desc)
3836 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07003837
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003838 tx_ring->next_to_use = 0;
3839 tx_ring->next_to_clean = 0;
3840 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07003841 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003842
3843err:
3844 vfree(tx_ring->tx_buffer_info);
3845 tx_ring->tx_buffer_info = NULL;
3846 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
3847 "descriptor ring\n");
3848 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003849}
3850
3851/**
Alexander Duyck69888672008-09-11 20:05:39 -07003852 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
3853 * @adapter: board private structure
3854 *
3855 * If this function returns with an error, then it's possible one or
3856 * more of the rings is populated (while the rest are not). It is the
3857 * callers duty to clean those orphaned rings.
3858 *
3859 * Return 0 on success, negative on failure
3860 **/
3861static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
3862{
3863 int i, err = 0;
3864
3865 for (i = 0; i < adapter->num_tx_queues; i++) {
3866 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
3867 if (!err)
3868 continue;
3869 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
3870 break;
3871 }
3872
3873 return err;
3874}
3875
3876/**
Auke Kok9a799d72007-09-15 14:07:45 -07003877 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
3878 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003879 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003880 *
3881 * Returns 0 on success, negative on failure
3882 **/
3883int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003884 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003885{
3886 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003887 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07003888
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003889 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
3890 rx_ring->rx_buffer_info = vmalloc(size);
3891 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07003892 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003893 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003894 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003895 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003896 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003897
Auke Kok9a799d72007-09-15 14:07:45 -07003898 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003899 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
3900 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003901
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003902 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07003903
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003904 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07003905 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003906 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003907 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003908 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003909 }
3910
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003911 rx_ring->next_to_clean = 0;
3912 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003913
3914 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003915
3916alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003917 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003918}
3919
3920/**
Alexander Duyck69888672008-09-11 20:05:39 -07003921 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
3922 * @adapter: board private structure
3923 *
3924 * If this function returns with an error, then it's possible one or
3925 * more of the rings is populated (while the rest are not). It is the
3926 * callers duty to clean those orphaned rings.
3927 *
3928 * Return 0 on success, negative on failure
3929 **/
3930
3931static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
3932{
3933 int i, err = 0;
3934
3935 for (i = 0; i < adapter->num_rx_queues; i++) {
3936 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
3937 if (!err)
3938 continue;
3939 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
3940 break;
3941 }
3942
3943 return err;
3944}
3945
3946/**
Auke Kok9a799d72007-09-15 14:07:45 -07003947 * ixgbe_free_tx_resources - Free Tx Resources per Queue
3948 * @adapter: board private structure
3949 * @tx_ring: Tx descriptor ring for a specific queue
3950 *
3951 * Free all transmit software resources
3952 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003953void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
3954 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003955{
3956 struct pci_dev *pdev = adapter->pdev;
3957
3958 ixgbe_clean_tx_ring(adapter, tx_ring);
3959
3960 vfree(tx_ring->tx_buffer_info);
3961 tx_ring->tx_buffer_info = NULL;
3962
3963 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
3964
3965 tx_ring->desc = NULL;
3966}
3967
3968/**
3969 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
3970 * @adapter: board private structure
3971 *
3972 * Free all transmit software resources
3973 **/
3974static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
3975{
3976 int i;
3977
3978 for (i = 0; i < adapter->num_tx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00003979 if (adapter->tx_ring[i].desc)
3980 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003981}
3982
3983/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003984 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07003985 * @adapter: board private structure
3986 * @rx_ring: ring to clean the resources from
3987 *
3988 * Free all receive software resources
3989 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003990void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
3991 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003992{
3993 struct pci_dev *pdev = adapter->pdev;
3994
3995 ixgbe_clean_rx_ring(adapter, rx_ring);
3996
3997 vfree(rx_ring->rx_buffer_info);
3998 rx_ring->rx_buffer_info = NULL;
3999
4000 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
4001
4002 rx_ring->desc = NULL;
4003}
4004
4005/**
4006 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4007 * @adapter: board private structure
4008 *
4009 * Free all receive software resources
4010 **/
4011static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4012{
4013 int i;
4014
4015 for (i = 0; i < adapter->num_rx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004016 if (adapter->rx_ring[i].desc)
4017 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004018}
4019
4020/**
Auke Kok9a799d72007-09-15 14:07:45 -07004021 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4022 * @netdev: network interface device structure
4023 * @new_mtu: new value for maximum frame size
4024 *
4025 * Returns 0 on success, negative on failure
4026 **/
4027static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4028{
4029 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4030 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4031
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004032 /* MTU < 68 is an error and causes problems on some kernels */
4033 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07004034 return -EINVAL;
4035
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004036 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004037 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004038 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004039 netdev->mtu = new_mtu;
4040
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004041 if (netif_running(netdev))
4042 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004043
4044 return 0;
4045}
4046
4047/**
4048 * ixgbe_open - Called when a network interface is made active
4049 * @netdev: network interface device structure
4050 *
4051 * Returns 0 on success, negative value on failure
4052 *
4053 * The open entry point is called when a network interface is made
4054 * active by the system (IFF_UP). At this point all resources needed
4055 * for transmit and receive operations are allocated, the interrupt
4056 * handler is registered with the OS, the watchdog timer is started,
4057 * and the stack is notified that the interface is ready.
4058 **/
4059static int ixgbe_open(struct net_device *netdev)
4060{
4061 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4062 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004063
Auke Kok4bebfaa2008-02-11 09:26:01 -08004064 /* disallow open during test */
4065 if (test_bit(__IXGBE_TESTING, &adapter->state))
4066 return -EBUSY;
4067
Jesse Brandeburg54386462009-04-17 20:44:27 +00004068 netif_carrier_off(netdev);
4069
Auke Kok9a799d72007-09-15 14:07:45 -07004070 /* allocate transmit descriptors */
4071 err = ixgbe_setup_all_tx_resources(adapter);
4072 if (err)
4073 goto err_setup_tx;
4074
Auke Kok9a799d72007-09-15 14:07:45 -07004075 /* allocate receive descriptors */
4076 err = ixgbe_setup_all_rx_resources(adapter);
4077 if (err)
4078 goto err_setup_rx;
4079
4080 ixgbe_configure(adapter);
4081
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004082 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004083 if (err)
4084 goto err_req_irq;
4085
Auke Kok9a799d72007-09-15 14:07:45 -07004086 err = ixgbe_up_complete(adapter);
4087 if (err)
4088 goto err_up;
4089
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004090 netif_tx_start_all_queues(netdev);
4091
Auke Kok9a799d72007-09-15 14:07:45 -07004092 return 0;
4093
4094err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004095 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004096 ixgbe_free_irq(adapter);
4097err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07004098err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004099 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004100err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004101 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004102 ixgbe_reset(adapter);
4103
4104 return err;
4105}
4106
4107/**
4108 * ixgbe_close - Disables a network interface
4109 * @netdev: network interface device structure
4110 *
4111 * Returns 0, this is not allowed to fail
4112 *
4113 * The close entry point is called when an interface is de-activated
4114 * by the OS. The hardware is still under the drivers control, but
4115 * needs to be disabled. A global MAC reset is issued to stop the
4116 * hardware, and all transmit and receive resources are freed.
4117 **/
4118static int ixgbe_close(struct net_device *netdev)
4119{
4120 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004121
4122 ixgbe_down(adapter);
4123 ixgbe_free_irq(adapter);
4124
4125 ixgbe_free_all_tx_resources(adapter);
4126 ixgbe_free_all_rx_resources(adapter);
4127
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004128 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004129
4130 return 0;
4131}
4132
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004133#ifdef CONFIG_PM
4134static int ixgbe_resume(struct pci_dev *pdev)
4135{
4136 struct net_device *netdev = pci_get_drvdata(pdev);
4137 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4138 u32 err;
4139
4140 pci_set_power_state(pdev, PCI_D0);
4141 pci_restore_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004142
4143 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004144 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07004145 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004146 "suspend\n");
4147 return err;
4148 }
4149 pci_set_master(pdev);
4150
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004151 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004152
4153 err = ixgbe_init_interrupt_scheme(adapter);
4154 if (err) {
4155 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
4156 "device\n");
4157 return err;
4158 }
4159
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004160 ixgbe_reset(adapter);
4161
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00004162 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4163
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004164 if (netif_running(netdev)) {
4165 err = ixgbe_open(adapter->netdev);
4166 if (err)
4167 return err;
4168 }
4169
4170 netif_device_attach(netdev);
4171
4172 return 0;
4173}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004174#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004175
4176static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004177{
4178 struct net_device *netdev = pci_get_drvdata(pdev);
4179 struct ixgbe_adapter *adapter = netdev_priv(netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004180 struct ixgbe_hw *hw = &adapter->hw;
4181 u32 ctrl, fctrl;
4182 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004183#ifdef CONFIG_PM
4184 int retval = 0;
4185#endif
4186
4187 netif_device_detach(netdev);
4188
4189 if (netif_running(netdev)) {
4190 ixgbe_down(adapter);
4191 ixgbe_free_irq(adapter);
4192 ixgbe_free_all_tx_resources(adapter);
4193 ixgbe_free_all_rx_resources(adapter);
4194 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00004195 ixgbe_clear_interrupt_scheme(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004196
4197#ifdef CONFIG_PM
4198 retval = pci_save_state(pdev);
4199 if (retval)
4200 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004201
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004202#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004203 if (wufc) {
4204 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004205
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004206 /* turn on all-multi mode if wake on multicast is enabled */
4207 if (wufc & IXGBE_WUFC_MC) {
4208 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4209 fctrl |= IXGBE_FCTRL_MPE;
4210 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4211 }
4212
4213 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4214 ctrl |= IXGBE_CTRL_GIO_DIS;
4215 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4216
4217 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4218 } else {
4219 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4220 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4221 }
4222
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004223 if (wufc && hw->mac.type == ixgbe_mac_82599EB)
4224 pci_wake_from_d3(pdev, true);
4225 else
4226 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004227
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004228 *enable_wake = !!wufc;
4229
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004230 ixgbe_release_hw_control(adapter);
4231
4232 pci_disable_device(pdev);
4233
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004234 return 0;
4235}
4236
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004237#ifdef CONFIG_PM
4238static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4239{
4240 int retval;
4241 bool wake;
4242
4243 retval = __ixgbe_shutdown(pdev, &wake);
4244 if (retval)
4245 return retval;
4246
4247 if (wake) {
4248 pci_prepare_to_sleep(pdev);
4249 } else {
4250 pci_wake_from_d3(pdev, false);
4251 pci_set_power_state(pdev, PCI_D3hot);
4252 }
4253
4254 return 0;
4255}
4256#endif /* CONFIG_PM */
4257
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004258static void ixgbe_shutdown(struct pci_dev *pdev)
4259{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004260 bool wake;
4261
4262 __ixgbe_shutdown(pdev, &wake);
4263
4264 if (system_state == SYSTEM_POWER_OFF) {
4265 pci_wake_from_d3(pdev, wake);
4266 pci_set_power_state(pdev, PCI_D3hot);
4267 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004268}
4269
4270/**
Auke Kok9a799d72007-09-15 14:07:45 -07004271 * ixgbe_update_stats - Update the board statistics counters.
4272 * @adapter: board private structure
4273 **/
4274void ixgbe_update_stats(struct ixgbe_adapter *adapter)
4275{
4276 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004277 u64 total_mpc = 0;
4278 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004279
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004280 if (hw->mac.type == ixgbe_mac_82599EB) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004281 u64 rsc_count = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004282 for (i = 0; i < 16; i++)
4283 adapter->hw_rx_no_dma_resources +=
4284 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Alexander Duyckf8212f92009-04-27 22:42:37 +00004285 for (i = 0; i < adapter->num_rx_queues; i++)
4286 rsc_count += adapter->rx_ring[i].rsc_count;
4287 adapter->rsc_count = rsc_count;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004288 }
4289
Auke Kok9a799d72007-09-15 14:07:45 -07004290 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004291 for (i = 0; i < 8; i++) {
4292 /* for packet buffers not used, the register should read 0 */
4293 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
4294 missed_rx += mpc;
4295 adapter->stats.mpc[i] += mpc;
4296 total_mpc += adapter->stats.mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004297 if (hw->mac.type == ixgbe_mac_82598EB)
4298 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004299 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
4300 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
4301 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
4302 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004303 if (hw->mac.type == ixgbe_mac_82599EB) {
4304 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4305 IXGBE_PXONRXCNT(i));
4306 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4307 IXGBE_PXOFFRXCNT(i));
4308 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004309 } else {
4310 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4311 IXGBE_PXONRXC(i));
4312 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4313 IXGBE_PXOFFRXC(i));
4314 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004315 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
4316 IXGBE_PXONTXC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004317 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004318 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004319 }
4320 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
4321 /* work around hardware counting issue */
4322 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07004323
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004324 /* 82598 hardware only has a 32 bit counter in the high register */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004325 if (hw->mac.type == ixgbe_mac_82599EB) {
4326 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
4327 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
4328 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
4329 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
4330 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
4331 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
4332 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
4333 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004334 adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
4335 adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00004336#ifdef IXGBE_FCOE
4337 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
4338 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
4339 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
4340 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
4341 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
4342 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
4343#endif /* IXGBE_FCOE */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004344 } else {
4345 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
4346 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
4347 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
4348 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
4349 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
4350 }
Auke Kok9a799d72007-09-15 14:07:45 -07004351 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
4352 adapter->stats.bprc += bprc;
4353 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004354 if (hw->mac.type == ixgbe_mac_82598EB)
4355 adapter->stats.mprc -= bprc;
Auke Kok9a799d72007-09-15 14:07:45 -07004356 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
4357 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
4358 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
4359 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
4360 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
4361 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
4362 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004363 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004364 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
4365 adapter->stats.lxontxc += lxon;
4366 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
4367 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07004368 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4369 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004370 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
4371 /*
4372 * 82598 errata - tx of flow control packets is included in tx counters
4373 */
4374 xon_off_tot = lxon + lxoff;
4375 adapter->stats.gptc -= xon_off_tot;
4376 adapter->stats.mptc -= xon_off_tot;
4377 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07004378 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4379 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
4380 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07004381 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
4382 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004383 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004384 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
4385 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
4386 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
4387 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
4388 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004389 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
4390
4391 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07004392 adapter->net_stats.multicast = adapter->stats.mprc;
4393
4394 /* Rx Errors */
4395 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004396 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07004397 adapter->net_stats.rx_dropped = 0;
4398 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
4399 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004400 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07004401}
4402
4403/**
4404 * ixgbe_watchdog - Timer Call-back
4405 * @data: pointer to adapter cast into an unsigned long
4406 **/
4407static void ixgbe_watchdog(unsigned long data)
4408{
4409 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004410 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004411 u64 eics = 0;
4412 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004413
Alexander Duyckfe49f042009-06-04 16:00:09 +00004414 /*
4415 * Do the watchdog outside of interrupt context due to the lovely
4416 * delays that some of the newer hardware requires
4417 */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004418
Alexander Duyckfe49f042009-06-04 16:00:09 +00004419 if (test_bit(__IXGBE_DOWN, &adapter->state))
4420 goto watchdog_short_circuit;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004421
Alexander Duyckfe49f042009-06-04 16:00:09 +00004422 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
4423 /*
4424 * for legacy and MSI interrupts don't set any bits
4425 * that are enabled for EIAM, because this operation
4426 * would set *both* EIMS and EICS for any bit in EIAM
4427 */
4428 IXGBE_WRITE_REG(hw, IXGBE_EICS,
4429 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
4430 goto watchdog_reschedule;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004431 }
4432
Alexander Duyckfe49f042009-06-04 16:00:09 +00004433 /* get one bit for every active tx/rx interrupt vector */
4434 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
4435 struct ixgbe_q_vector *qv = adapter->q_vector[i];
4436 if (qv->rxr_count || qv->txr_count)
4437 eics |= ((u64)1 << i);
4438 }
4439
4440 /* Cause software interrupt to ensure rx rings are cleaned */
4441 ixgbe_irq_rearm_queues(adapter, eics);
4442
4443watchdog_reschedule:
4444 /* Reset the timer */
4445 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
4446
4447watchdog_short_circuit:
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004448 schedule_work(&adapter->watchdog_task);
4449}
4450
4451/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004452 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
4453 * @work: pointer to work_struct containing our data
4454 **/
4455static void ixgbe_multispeed_fiber_task(struct work_struct *work)
4456{
4457 struct ixgbe_adapter *adapter = container_of(work,
4458 struct ixgbe_adapter,
4459 multispeed_fiber_task);
4460 struct ixgbe_hw *hw = &adapter->hw;
4461 u32 autoneg;
4462
4463 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
4464 if (hw->mac.ops.get_link_capabilities)
4465 hw->mac.ops.get_link_capabilities(hw, &autoneg,
4466 &hw->mac.autoneg);
4467 if (hw->mac.ops.setup_link_speed)
4468 hw->mac.ops.setup_link_speed(hw, autoneg, true, true);
4469 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4470 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
4471}
4472
4473/**
4474 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
4475 * @work: pointer to work_struct containing our data
4476 **/
4477static void ixgbe_sfp_config_module_task(struct work_struct *work)
4478{
4479 struct ixgbe_adapter *adapter = container_of(work,
4480 struct ixgbe_adapter,
4481 sfp_config_module_task);
4482 struct ixgbe_hw *hw = &adapter->hw;
4483 u32 err;
4484
4485 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
4486 err = hw->phy.ops.identify_sfp(hw);
4487 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4488 DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err);
4489 ixgbe_down(adapter);
4490 return;
4491 }
4492 hw->mac.ops.setup_sfp(hw);
4493
Tony Breeds8d1c3c02009-04-09 22:29:10 +00004494 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004495 /* This will also work for DA Twinax connections */
4496 schedule_work(&adapter->multispeed_fiber_task);
4497 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
4498}
4499
4500/**
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004501 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
4502 * @work: pointer to work_struct containing our data
4503 **/
4504static void ixgbe_fdir_reinit_task(struct work_struct *work)
4505{
4506 struct ixgbe_adapter *adapter = container_of(work,
4507 struct ixgbe_adapter,
4508 fdir_reinit_task);
4509 struct ixgbe_hw *hw = &adapter->hw;
4510 int i;
4511
4512 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
4513 for (i = 0; i < adapter->num_tx_queues; i++)
4514 set_bit(__IXGBE_FDIR_INIT_DONE,
4515 &(adapter->tx_ring[i].reinit_state));
4516 } else {
4517 DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, "
4518 "ignored adding FDIR ATR filters \n");
4519 }
4520 /* Done FDIR Re-initialization, enable transmits */
4521 netif_tx_start_all_queues(adapter->netdev);
4522}
4523
4524/**
Alexander Duyck69888672008-09-11 20:05:39 -07004525 * ixgbe_watchdog_task - worker thread to bring link up
4526 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004527 **/
4528static void ixgbe_watchdog_task(struct work_struct *work)
4529{
4530 struct ixgbe_adapter *adapter = container_of(work,
4531 struct ixgbe_adapter,
4532 watchdog_task);
4533 struct net_device *netdev = adapter->netdev;
4534 struct ixgbe_hw *hw = &adapter->hw;
4535 u32 link_speed = adapter->link_speed;
4536 bool link_up = adapter->link_up;
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004537 int i;
4538 struct ixgbe_ring *tx_ring;
4539 int some_tx_pending = 0;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004540
4541 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
4542
4543 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4544 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004545 if (link_up) {
4546#ifdef CONFIG_DCB
4547 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4548 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004549 hw->mac.ops.fc_enable(hw, i);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004550 } else {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004551 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004552 }
4553#else
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004554 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004555#endif
4556 }
4557
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004558 if (link_up ||
4559 time_after(jiffies, (adapter->link_check_timeout +
4560 IXGBE_TRY_LINK_TIMEOUT))) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004561 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004562 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004563 }
4564 adapter->link_up = link_up;
4565 adapter->link_speed = link_speed;
4566 }
Auke Kok9a799d72007-09-15 14:07:45 -07004567
4568 if (link_up) {
4569 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004570 bool flow_rx, flow_tx;
4571
4572 if (hw->mac.type == ixgbe_mac_82599EB) {
4573 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4574 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
4575 flow_rx = (mflcn & IXGBE_MFLCN_RFCE);
4576 flow_tx = (fccfg & IXGBE_FCCFG_TFCE_802_3X);
4577 } else {
4578 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4579 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
4580 flow_rx = (frctl & IXGBE_FCTRL_RFCE);
4581 flow_tx = (rmcs & IXGBE_RMCS_TFCE_802_3X);
4582 }
4583
Jeff Kirshera46e5342008-11-27 00:22:21 -08004584 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
4585 "Flow Control: %s\n",
4586 netdev->name,
4587 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
4588 "10 Gbps" :
4589 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
4590 "1 Gbps" : "unknown speed")),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004591 ((flow_rx && flow_tx) ? "RX/TX" :
4592 (flow_rx ? "RX" :
4593 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07004594
4595 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004596 } else {
4597 /* Force detection of hung controller */
4598 adapter->detect_tx_hung = true;
4599 }
4600 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004601 adapter->link_up = false;
4602 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004603 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08004604 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
4605 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07004606 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004607 }
4608 }
4609
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004610 if (!netif_carrier_ok(netdev)) {
4611 for (i = 0; i < adapter->num_tx_queues; i++) {
4612 tx_ring = &adapter->tx_ring[i];
4613 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
4614 some_tx_pending = 1;
4615 break;
4616 }
4617 }
4618
4619 if (some_tx_pending) {
4620 /* We've lost link, so the controller stops DMA,
4621 * but we've got queued Tx work that's never going
4622 * to get done, so reset controller to flush Tx.
4623 * (Do the reset outside of interrupt context).
4624 */
4625 schedule_work(&adapter->reset_task);
4626 }
4627 }
4628
Auke Kok9a799d72007-09-15 14:07:45 -07004629 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004630 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07004631}
4632
Auke Kok9a799d72007-09-15 14:07:45 -07004633static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004634 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
4635 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004636{
4637 struct ixgbe_adv_tx_context_desc *context_desc;
4638 unsigned int i;
4639 int err;
4640 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004641 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
4642 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07004643
4644 if (skb_is_gso(skb)) {
4645 if (skb_header_cloned(skb)) {
4646 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4647 if (err)
4648 return err;
4649 }
4650 l4len = tcp_hdrlen(skb);
4651 *hdr_len += l4len;
4652
Al Viro8327d002007-12-10 18:54:12 +00004653 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004654 struct iphdr *iph = ip_hdr(skb);
4655 iph->tot_len = 0;
4656 iph->check = 0;
4657 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004658 iph->daddr, 0,
4659 IPPROTO_TCP,
4660 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004661 adapter->hw_tso_ctxt++;
4662 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
4663 ipv6_hdr(skb)->payload_len = 0;
4664 tcp_hdr(skb)->check =
4665 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004666 &ipv6_hdr(skb)->daddr,
4667 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004668 adapter->hw_tso6_ctxt++;
4669 }
4670
4671 i = tx_ring->next_to_use;
4672
4673 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4674 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4675
4676 /* VLAN MACLEN IPLEN */
4677 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4678 vlan_macip_lens |=
4679 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4680 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004681 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004682 *hdr_len += skb_network_offset(skb);
4683 vlan_macip_lens |=
4684 (skb_transport_header(skb) - skb_network_header(skb));
4685 *hdr_len +=
4686 (skb_transport_header(skb) - skb_network_header(skb));
4687 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4688 context_desc->seqnum_seed = 0;
4689
4690 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004691 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004692 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004693
Al Viro8327d002007-12-10 18:54:12 +00004694 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004695 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4696 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
4697 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4698
4699 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004700 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07004701 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
4702 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004703 /* use index 1 for TSO */
4704 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004705 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4706
4707 tx_buffer_info->time_stamp = jiffies;
4708 tx_buffer_info->next_to_watch = i;
4709
4710 i++;
4711 if (i == tx_ring->count)
4712 i = 0;
4713 tx_ring->next_to_use = i;
4714
4715 return true;
4716 }
4717 return false;
4718}
4719
4720static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004721 struct ixgbe_ring *tx_ring,
4722 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07004723{
4724 struct ixgbe_adv_tx_context_desc *context_desc;
4725 unsigned int i;
4726 struct ixgbe_tx_buffer *tx_buffer_info;
4727 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4728
4729 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4730 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4731 i = tx_ring->next_to_use;
4732 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4733 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4734
4735 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4736 vlan_macip_lens |=
4737 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4738 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004739 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004740 if (skb->ip_summed == CHECKSUM_PARTIAL)
4741 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004742 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07004743
4744 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4745 context_desc->seqnum_seed = 0;
4746
4747 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004748 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004749
4750 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08004751 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004752 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07004753 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08004754 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4755 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004756 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004757 else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
4758 type_tucmd_mlhl |=
4759 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004760 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004761 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08004762 /* XXX what about other V6 headers?? */
4763 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4764 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004765 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004766 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
4767 type_tucmd_mlhl |=
4768 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004769 break;
Auke Kok41825d72008-02-12 15:20:33 -08004770 default:
4771 if (unlikely(net_ratelimit())) {
4772 DPRINTK(PROBE, WARNING,
4773 "partial checksum but proto=%x!\n",
4774 skb->protocol);
4775 }
4776 break;
4777 }
Auke Kok9a799d72007-09-15 14:07:45 -07004778 }
4779
4780 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004781 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07004782 context_desc->mss_l4len_idx = 0;
4783
4784 tx_buffer_info->time_stamp = jiffies;
4785 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004786
Auke Kok9a799d72007-09-15 14:07:45 -07004787 adapter->hw_csum_tx_good++;
4788 i++;
4789 if (i == tx_ring->count)
4790 i = 0;
4791 tx_ring->next_to_use = i;
4792
4793 return true;
4794 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004795
Auke Kok9a799d72007-09-15 14:07:45 -07004796 return false;
4797}
4798
4799static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004800 struct ixgbe_ring *tx_ring,
Yi Zoueacd73f2009-05-13 13:11:06 +00004801 struct sk_buff *skb, u32 tx_flags,
4802 unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07004803{
4804 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00004805 unsigned int len;
4806 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07004807 unsigned int offset = 0, size, count = 0, i;
4808 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
4809 unsigned int f;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004810 dma_addr_t *map;
Auke Kok9a799d72007-09-15 14:07:45 -07004811
4812 i = tx_ring->next_to_use;
4813
Alexander Duyck44df32c2009-03-31 21:34:23 +00004814 if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
4815 dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
4816 return 0;
4817 }
4818
4819 map = skb_shinfo(skb)->dma_maps;
4820
Yi Zoueacd73f2009-05-13 13:11:06 +00004821 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
4822 /* excluding fcoe_crc_eof for FCoE */
4823 total -= sizeof(struct fcoe_crc_eof);
4824
4825 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07004826 while (len) {
4827 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4828 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4829
4830 tx_buffer_info->length = size;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004831 tx_buffer_info->dma = map[0] + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004832 tx_buffer_info->time_stamp = jiffies;
4833 tx_buffer_info->next_to_watch = i;
4834
4835 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00004836 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07004837 offset += size;
4838 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004839
4840 if (len) {
4841 i++;
4842 if (i == tx_ring->count)
4843 i = 0;
4844 }
Auke Kok9a799d72007-09-15 14:07:45 -07004845 }
4846
4847 for (f = 0; f < nr_frags; f++) {
4848 struct skb_frag_struct *frag;
4849
4850 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00004851 len = min((unsigned int)frag->size, total);
Alexander Duyck44df32c2009-03-31 21:34:23 +00004852 offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004853
4854 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00004855 i++;
4856 if (i == tx_ring->count)
4857 i = 0;
4858
Auke Kok9a799d72007-09-15 14:07:45 -07004859 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4860 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4861
4862 tx_buffer_info->length = size;
Alexander Duyck44df32c2009-03-31 21:34:23 +00004863 tx_buffer_info->dma = map[f + 1] + offset;
Auke Kok9a799d72007-09-15 14:07:45 -07004864 tx_buffer_info->time_stamp = jiffies;
4865 tx_buffer_info->next_to_watch = i;
4866
4867 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00004868 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07004869 offset += size;
4870 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07004871 }
Yi Zoueacd73f2009-05-13 13:11:06 +00004872 if (total == 0)
4873 break;
Auke Kok9a799d72007-09-15 14:07:45 -07004874 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00004875
Auke Kok9a799d72007-09-15 14:07:45 -07004876 tx_ring->tx_buffer_info[i].skb = skb;
4877 tx_ring->tx_buffer_info[first].next_to_watch = i;
4878
4879 return count;
4880}
4881
4882static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004883 struct ixgbe_ring *tx_ring,
4884 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004885{
4886 union ixgbe_adv_tx_desc *tx_desc = NULL;
4887 struct ixgbe_tx_buffer *tx_buffer_info;
4888 u32 olinfo_status = 0, cmd_type_len = 0;
4889 unsigned int i;
4890 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
4891
4892 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
4893
4894 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
4895
4896 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4897 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
4898
4899 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
4900 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4901
4902 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004903 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004904
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004905 /* use index 1 context for tso */
4906 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004907 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
4908 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004909 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004910
4911 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
4912 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004913 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004914
Yi Zoueacd73f2009-05-13 13:11:06 +00004915 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
4916 olinfo_status |= IXGBE_ADVTXD_CC;
4917 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
4918 if (tx_flags & IXGBE_TX_FLAGS_FSO)
4919 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4920 }
4921
Auke Kok9a799d72007-09-15 14:07:45 -07004922 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
4923
4924 i = tx_ring->next_to_use;
4925 while (count--) {
4926 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4927 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
4928 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
4929 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004930 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07004931 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07004932 i++;
4933 if (i == tx_ring->count)
4934 i = 0;
4935 }
4936
4937 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
4938
4939 /*
4940 * Force memory writes to complete before letting h/w
4941 * know there are new descriptors to fetch. (Only
4942 * applicable for weak-ordered memory model archs,
4943 * such as IA-64).
4944 */
4945 wmb();
4946
4947 tx_ring->next_to_use = i;
4948 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4949}
4950
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004951static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
4952 int queue, u32 tx_flags)
4953{
4954 /* Right now, we support IPv4 only */
4955 struct ixgbe_atr_input atr_input;
4956 struct tcphdr *th;
4957 struct udphdr *uh;
4958 struct iphdr *iph = ip_hdr(skb);
4959 struct ethhdr *eth = (struct ethhdr *)skb->data;
4960 u16 vlan_id, src_port, dst_port, flex_bytes;
4961 u32 src_ipv4_addr, dst_ipv4_addr;
4962 u8 l4type = 0;
4963
4964 /* check if we're UDP or TCP */
4965 if (iph->protocol == IPPROTO_TCP) {
4966 th = tcp_hdr(skb);
4967 src_port = th->source;
4968 dst_port = th->dest;
4969 l4type |= IXGBE_ATR_L4TYPE_TCP;
4970 /* l4type IPv4 type is 0, no need to assign */
4971 } else if(iph->protocol == IPPROTO_UDP) {
4972 uh = udp_hdr(skb);
4973 src_port = uh->source;
4974 dst_port = uh->dest;
4975 l4type |= IXGBE_ATR_L4TYPE_UDP;
4976 /* l4type IPv4 type is 0, no need to assign */
4977 } else {
4978 /* Unsupported L4 header, just bail here */
4979 return;
4980 }
4981
4982 memset(&atr_input, 0, sizeof(struct ixgbe_atr_input));
4983
4984 vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >>
4985 IXGBE_TX_FLAGS_VLAN_SHIFT;
4986 src_ipv4_addr = iph->saddr;
4987 dst_ipv4_addr = iph->daddr;
4988 flex_bytes = eth->h_proto;
4989
4990 ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
4991 ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
4992 ixgbe_atr_set_dst_port_82599(&atr_input, src_port);
4993 ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes);
4994 ixgbe_atr_set_l4type_82599(&atr_input, l4type);
4995 /* src and dst are inverted, think how the receiver sees them */
4996 ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr);
4997 ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr);
4998
4999 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
5000 ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue);
5001}
5002
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005003static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005004 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005005{
5006 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5007
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005008 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005009 /* Herbert's original patch had:
5010 * smp_mb__after_netif_stop_queue();
5011 * but since that doesn't exist yet, just open code it. */
5012 smp_mb();
5013
5014 /* We need to check again in a case another CPU has just
5015 * made room available. */
5016 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
5017 return -EBUSY;
5018
5019 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07005020 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005021 ++adapter->restart_queue;
5022 return 0;
5023}
5024
5025static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005026 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005027{
5028 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
5029 return 0;
5030 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
5031}
5032
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005033static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
5034{
5035 struct ixgbe_adapter *adapter = netdev_priv(dev);
5036
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005037 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
5038 return smp_processor_id();
5039
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005040 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5041 return 0; /* All traffic should default to class 0 */
5042
5043 return skb_tx_hash(dev, skb);
5044}
5045
Auke Kok9a799d72007-09-15 14:07:45 -07005046static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
5047{
5048 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5049 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07005050 unsigned int first;
5051 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005052 u8 hdr_len = 0;
5053 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07005054 int count = 0;
5055 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005056
Wu Fengguang95615d92009-04-14 21:53:48 -07005057 r_idx = skb->queue_mapping;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005058 tx_ring = &adapter->tx_ring[r_idx];
Auke Kok9a799d72007-09-15 14:07:45 -07005059
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005060 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
5061 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005062 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5063 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
5064 tx_flags |= (skb->queue_mapping << 13);
5065 }
5066 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5067 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5068 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5069 tx_flags |= (skb->queue_mapping << 13);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005070 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5071 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07005072 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005073
5074 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
5075 (skb->protocol == htons(ETH_P_FCOE)))
5076 tx_flags |= IXGBE_TX_FLAGS_FCOE;
5077
5078 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005079 if (skb_is_gso(skb) ||
5080 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00005081 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
5082 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07005083 count++;
5084
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005085 count += TXD_USE_COUNT(skb_headlen(skb));
5086 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07005087 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
5088
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005089 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07005090 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07005091 return NETDEV_TX_BUSY;
5092 }
Auke Kok9a799d72007-09-15 14:07:45 -07005093
Auke Kok9a799d72007-09-15 14:07:45 -07005094 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00005095 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5096#ifdef IXGBE_FCOE
5097 /* setup tx offload for FCoE */
5098 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5099 if (tso < 0) {
5100 dev_kfree_skb_any(skb);
5101 return NETDEV_TX_OK;
5102 }
5103 if (tso)
5104 tx_flags |= IXGBE_TX_FLAGS_FSO;
5105#endif /* IXGBE_FCOE */
5106 } else {
5107 if (skb->protocol == htons(ETH_P_IP))
5108 tx_flags |= IXGBE_TX_FLAGS_IPV4;
5109 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5110 if (tso < 0) {
5111 dev_kfree_skb_any(skb);
5112 return NETDEV_TX_OK;
5113 }
5114
5115 if (tso)
5116 tx_flags |= IXGBE_TX_FLAGS_TSO;
5117 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
5118 (skb->ip_summed == CHECKSUM_PARTIAL))
5119 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005120 }
5121
Yi Zoueacd73f2009-05-13 13:11:06 +00005122 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005123 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005124 /* add the ATR filter if ATR is on */
5125 if (tx_ring->atr_sample_rate) {
5126 ++tx_ring->atr_count;
5127 if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) &&
5128 test_bit(__IXGBE_FDIR_INIT_DONE,
5129 &tx_ring->reinit_state)) {
5130 ixgbe_atr(adapter, skb, tx_ring->queue_index,
5131 tx_flags);
5132 tx_ring->atr_count = 0;
5133 }
5134 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00005135 ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
5136 hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005137 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07005138
Alexander Duyck44df32c2009-03-31 21:34:23 +00005139 } else {
5140 dev_kfree_skb_any(skb);
5141 tx_ring->tx_buffer_info[first].time_stamp = 0;
5142 tx_ring->next_to_use = first;
5143 }
Auke Kok9a799d72007-09-15 14:07:45 -07005144
5145 return NETDEV_TX_OK;
5146}
5147
5148/**
5149 * ixgbe_get_stats - Get System Network Statistics
5150 * @netdev: network interface device structure
5151 *
5152 * Returns the address of the device statistics structure.
5153 * The statistics are actually updated from the timer callback.
5154 **/
5155static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
5156{
5157 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5158
5159 /* only return the current stats */
5160 return &adapter->net_stats;
5161}
5162
5163/**
5164 * ixgbe_set_mac - Change the Ethernet Address of the NIC
5165 * @netdev: network interface device structure
5166 * @p: pointer to an address structure
5167 *
5168 * Returns 0 on success, negative on failure
5169 **/
5170static int ixgbe_set_mac(struct net_device *netdev, void *p)
5171{
5172 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005173 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005174 struct sockaddr *addr = p;
5175
5176 if (!is_valid_ether_addr(addr->sa_data))
5177 return -EADDRNOTAVAIL;
5178
5179 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005180 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07005181
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005182 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07005183
5184 return 0;
5185}
5186
Ben Hutchings6b73e102009-04-29 08:08:58 +00005187static int
5188ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
5189{
5190 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5191 struct ixgbe_hw *hw = &adapter->hw;
5192 u16 value;
5193 int rc;
5194
5195 if (prtad != hw->phy.mdio.prtad)
5196 return -EINVAL;
5197 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
5198 if (!rc)
5199 rc = value;
5200 return rc;
5201}
5202
5203static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
5204 u16 addr, u16 value)
5205{
5206 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5207 struct ixgbe_hw *hw = &adapter->hw;
5208
5209 if (prtad != hw->phy.mdio.prtad)
5210 return -EINVAL;
5211 return hw->phy.ops.write_reg(hw, addr, devad, value);
5212}
5213
5214static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
5215{
5216 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5217
5218 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
5219}
5220
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005221/**
5222 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
5223 * netdev->dev_addr_list
5224 * @netdev: network interface device structure
5225 *
5226 * Returns non-zero on failure
5227 **/
5228static int ixgbe_add_sanmac_netdev(struct net_device *dev)
5229{
5230 int err = 0;
5231 struct ixgbe_adapter *adapter = netdev_priv(dev);
5232 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5233
5234 if (is_valid_ether_addr(mac->san_addr)) {
5235 rtnl_lock();
5236 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5237 rtnl_unlock();
5238 }
5239 return err;
5240}
5241
5242/**
5243 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
5244 * netdev->dev_addr_list
5245 * @netdev: network interface device structure
5246 *
5247 * Returns non-zero on failure
5248 **/
5249static int ixgbe_del_sanmac_netdev(struct net_device *dev)
5250{
5251 int err = 0;
5252 struct ixgbe_adapter *adapter = netdev_priv(dev);
5253 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5254
5255 if (is_valid_ether_addr(mac->san_addr)) {
5256 rtnl_lock();
5257 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5258 rtnl_unlock();
5259 }
5260 return err;
5261}
5262
Auke Kok9a799d72007-09-15 14:07:45 -07005263#ifdef CONFIG_NET_POLL_CONTROLLER
5264/*
5265 * Polling 'interrupt' - used by things like netconsole to send skbs
5266 * without having to re-enable interrupts. It's not called while
5267 * the interrupt routine is executing.
5268 */
5269static void ixgbe_netpoll(struct net_device *netdev)
5270{
5271 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5272
5273 disable_irq(adapter->pdev->irq);
5274 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
5275 ixgbe_intr(adapter->pdev->irq, netdev);
5276 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
5277 enable_irq(adapter->pdev->irq);
5278}
5279#endif
5280
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005281static const struct net_device_ops ixgbe_netdev_ops = {
5282 .ndo_open = ixgbe_open,
5283 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005284 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005285 .ndo_select_queue = ixgbe_select_queue,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005286 .ndo_get_stats = ixgbe_get_stats,
Chris Leeche90d4002009-03-10 16:00:24 +00005287 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005288 .ndo_set_multicast_list = ixgbe_set_rx_mode,
5289 .ndo_validate_addr = eth_validate_addr,
5290 .ndo_set_mac_address = ixgbe_set_mac,
5291 .ndo_change_mtu = ixgbe_change_mtu,
5292 .ndo_tx_timeout = ixgbe_tx_timeout,
5293 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
5294 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
5295 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00005296 .ndo_do_ioctl = ixgbe_ioctl,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005297#ifdef CONFIG_NET_POLL_CONTROLLER
5298 .ndo_poll_controller = ixgbe_netpoll,
5299#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005300#ifdef IXGBE_FCOE
5301 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
5302 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
5303#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005304};
5305
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005306/**
Auke Kok9a799d72007-09-15 14:07:45 -07005307 * ixgbe_probe - Device Initialization Routine
5308 * @pdev: PCI device information struct
5309 * @ent: entry in ixgbe_pci_tbl
5310 *
5311 * Returns 0 on success, negative on failure
5312 *
5313 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
5314 * The OS initialization, configuring of the adapter private structure,
5315 * and a hardware reset occur.
5316 **/
5317static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005318 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07005319{
5320 struct net_device *netdev;
5321 struct ixgbe_adapter *adapter = NULL;
5322 struct ixgbe_hw *hw;
5323 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07005324 static int cards_found;
5325 int i, err, pci_using_dac;
Yi Zoueacd73f2009-05-13 13:11:06 +00005326#ifdef IXGBE_FCOE
5327 u16 device_caps;
5328#endif
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005329 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07005330
gouji-new9ce77662009-05-06 10:44:45 +00005331 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005332 if (err)
5333 return err;
5334
Yang Hongyang6a355282009-04-06 19:01:13 -07005335 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
5336 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07005337 pci_using_dac = 1;
5338 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07005339 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005340 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -07005341 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005342 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005343 dev_err(&pdev->dev, "No usable DMA "
5344 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005345 goto err_dma;
5346 }
5347 }
5348 pci_using_dac = 0;
5349 }
5350
gouji-new9ce77662009-05-06 10:44:45 +00005351 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
5352 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07005353 if (err) {
gouji-new9ce77662009-05-06 10:44:45 +00005354 dev_err(&pdev->dev,
5355 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07005356 goto err_pci_reg;
5357 }
5358
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005359 err = pci_enable_pcie_error_reporting(pdev);
5360 if (err) {
5361 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
5362 "0x%x\n", err);
5363 /* non-fatal, continue */
5364 }
5365
Auke Kok9a799d72007-09-15 14:07:45 -07005366 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07005367 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005368
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005369 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07005370 if (!netdev) {
5371 err = -ENOMEM;
5372 goto err_alloc_etherdev;
5373 }
5374
Auke Kok9a799d72007-09-15 14:07:45 -07005375 SET_NETDEV_DEV(netdev, &pdev->dev);
5376
5377 pci_set_drvdata(pdev, netdev);
5378 adapter = netdev_priv(netdev);
5379
5380 adapter->netdev = netdev;
5381 adapter->pdev = pdev;
5382 hw = &adapter->hw;
5383 hw->back = adapter;
5384 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
5385
Jeff Kirsher05857982008-09-11 19:57:00 -07005386 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
5387 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07005388 if (!hw->hw_addr) {
5389 err = -EIO;
5390 goto err_ioremap;
5391 }
5392
5393 for (i = 1; i <= 5; i++) {
5394 if (pci_resource_len(pdev, i) == 0)
5395 continue;
5396 }
5397
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005398 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07005399 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005400 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07005401 strcpy(netdev->name, pci_name(pdev));
5402
Auke Kok9a799d72007-09-15 14:07:45 -07005403 adapter->bd_number = cards_found;
5404
Auke Kok9a799d72007-09-15 14:07:45 -07005405 /* Setup hw api */
5406 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005407 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07005408
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005409 /* EEPROM */
5410 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
5411 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
5412 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
5413 if (!(eec & (1 << 8)))
5414 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
5415
5416 /* PHY */
5417 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08005418 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00005419 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
5420 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
5421 hw->phy.mdio.mmds = 0;
5422 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
5423 hw->phy.mdio.dev = netdev;
5424 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
5425 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08005426
5427 /* set up this timer and work struct before calling get_invariants
5428 * which might start the timer
5429 */
5430 init_timer(&adapter->sfp_timer);
5431 adapter->sfp_timer.function = &ixgbe_sfp_timer;
5432 adapter->sfp_timer.data = (unsigned long) adapter;
5433
5434 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005435
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005436 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
5437 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
5438
5439 /* a new SFP+ module arrival, called from GPI SDP2 context */
5440 INIT_WORK(&adapter->sfp_config_module_task,
5441 ixgbe_sfp_config_module_task);
5442
Don Skidmore8ca783a2009-05-26 20:40:47 -07005443 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005444
5445 /* setup the private structure */
5446 err = ixgbe_sw_init(adapter);
5447 if (err)
5448 goto err_sw_init;
5449
Don Skidmorebf069c92009-05-07 10:39:54 +00005450 /*
5451 * If there is a fan on this device and it has failed log the
5452 * failure.
5453 */
5454 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5455 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5456 if (esdp & IXGBE_ESDP_SDP1)
5457 DPRINTK(PROBE, CRIT,
5458 "Fan has stopped, replace the adapter\n");
5459 }
5460
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005461 /* reset_hw fills in the perm_addr as well */
5462 err = hw->mac.ops.reset_hw(hw);
Don Skidmore8ca783a2009-05-26 20:40:47 -07005463 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
5464 hw->mac.type == ixgbe_mac_82598EB) {
5465 /*
5466 * Start a kernel thread to watch for a module to arrive.
5467 * Only do this for 82598, since 82599 will generate
5468 * interrupts on module arrival.
5469 */
5470 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5471 mod_timer(&adapter->sfp_timer,
5472 round_jiffies(jiffies + (2 * HZ)));
5473 err = 0;
5474 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005475 dev_err(&adapter->pdev->dev, "failed to load because an "
5476 "unsupported SFP+ module type was detected.\n");
5477 goto err_sw_init;
5478 } else if (err) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005479 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
5480 goto err_sw_init;
5481 }
5482
Auke Kok9a799d72007-09-15 14:07:45 -07005483 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005484 NETIF_F_IP_CSUM |
5485 NETIF_F_HW_VLAN_TX |
5486 NETIF_F_HW_VLAN_RX |
5487 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07005488
Jesse Brandeburge9990a92008-08-26 04:27:24 -07005489 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005490 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07005491 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08005492 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005493
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00005494 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
5495 netdev->features |= NETIF_F_SCTP_CSUM;
5496
Jeff Kirsherad31c402008-06-05 04:05:30 -07005497 netdev->vlan_features |= NETIF_F_TSO;
5498 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07005499 netdev->vlan_features |= NETIF_F_IP_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005500 netdev->vlan_features |= NETIF_F_SG;
5501
Alexander Duyck2f90b862008-11-20 20:52:10 -08005502 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5503 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
5504
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005505#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005506 netdev->dcbnl_ops = &dcbnl_ops;
5507#endif
5508
Yi Zoueacd73f2009-05-13 13:11:06 +00005509#ifdef IXGBE_FCOE
5510 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
5511 if (hw->mac.ops.get_device_caps) {
5512 hw->mac.ops.get_device_caps(hw, &device_caps);
5513 if (!(device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)) {
5514 netdev->features |= NETIF_F_FCOE_CRC;
5515 netdev->features |= NETIF_F_FSO;
Yi Zou332d4a72009-05-13 13:11:53 +00005516 netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005517 DPRINTK(DRV, INFO, "FCoE enabled, "
5518 "disabling Flow Director\n");
5519 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
5520 adapter->flags &=
5521 ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
5522 adapter->atr_sample_rate = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00005523 } else {
5524 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5525 }
5526 }
5527 }
5528#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005529 if (pci_using_dac)
5530 netdev->features |= NETIF_F_HIGHDMA;
5531
Peter P Waskiewicz Jrdf647b52009-06-04 16:00:47 +00005532 if (adapter->flags & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00005533 netdev->features |= NETIF_F_LRO;
5534
Auke Kok9a799d72007-09-15 14:07:45 -07005535 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005536 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07005537 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
5538 err = -EIO;
5539 goto err_eeprom;
5540 }
5541
5542 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
5543 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
5544
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005545 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
5546 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005547 err = -EIO;
5548 goto err_eeprom;
5549 }
5550
5551 init_timer(&adapter->watchdog_timer);
5552 adapter->watchdog_timer.function = &ixgbe_watchdog;
5553 adapter->watchdog_timer.data = (unsigned long)adapter;
5554
5555 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005556 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005557
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005558 err = ixgbe_init_interrupt_scheme(adapter);
5559 if (err)
5560 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07005561
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005562 switch (pdev->device) {
5563 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005564 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
5565 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
Peter P Waskiewicz Jrbdf0a552009-06-04 11:09:58 +00005566 /* Enable ACPI wakeup in GRC */
5567 IXGBE_WRITE_REG(hw, IXGBE_GRC,
5568 (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005569 break;
5570 default:
5571 adapter->wol = 0;
5572 break;
5573 }
5574 device_init_wakeup(&adapter->pdev->dev, true);
5575 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
5576
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005577 /* pick up the PCI bus settings for reporting later */
5578 hw->mac.ops.get_bus_info(hw);
5579
Auke Kok9a799d72007-09-15 14:07:45 -07005580 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07005581 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005582 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
5583 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
5584 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
5585 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
5586 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005587 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07005588 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005589 ixgbe_read_pba_num_generic(hw, &part_num);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005590 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
5591 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
5592 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
5593 (part_num >> 8), (part_num & 0xff));
5594 else
5595 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
5596 hw->mac.type, hw->phy.type,
5597 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07005598
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005599 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Auke Kok0c254d82008-02-11 09:25:56 -08005600 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005601 "this card is not sufficient for optimal "
5602 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005603 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005604 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005605 }
5606
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08005607 /* save off EEPROM version number */
5608 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
5609
Auke Kok9a799d72007-09-15 14:07:45 -07005610 /* reset the hardware with the new settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005611 hw->mac.ops.start_hw(hw);
5612
Auke Kok9a799d72007-09-15 14:07:45 -07005613 strcpy(netdev->name, "eth%d");
5614 err = register_netdev(netdev);
5615 if (err)
5616 goto err_register;
5617
Jesse Brandeburg54386462009-04-17 20:44:27 +00005618 /* carrier off reporting is important to ethtool even BEFORE open */
5619 netif_carrier_off(netdev);
5620
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005621 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5622 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5623 INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
5624
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005625#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03005626 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005627 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005628 ixgbe_setup_dca(adapter);
5629 }
5630#endif
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005631 /* add san mac addr to netdev */
5632 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005633
5634 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
5635 cards_found++;
5636 return 0;
5637
5638err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005639 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005640 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005641err_sw_init:
5642err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08005643 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5644 del_timer_sync(&adapter->sfp_timer);
5645 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005646 cancel_work_sync(&adapter->multispeed_fiber_task);
5647 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005648 iounmap(hw->hw_addr);
5649err_ioremap:
5650 free_netdev(netdev);
5651err_alloc_etherdev:
gouji-new9ce77662009-05-06 10:44:45 +00005652 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5653 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005654err_pci_reg:
5655err_dma:
5656 pci_disable_device(pdev);
5657 return err;
5658}
5659
5660/**
5661 * ixgbe_remove - Device Removal Routine
5662 * @pdev: PCI device information struct
5663 *
5664 * ixgbe_remove is called by the PCI subsystem to alert the driver
5665 * that it should release a PCI device. The could be caused by a
5666 * Hot-Plug event, or because the driver is going to be removed from
5667 * memory.
5668 **/
5669static void __devexit ixgbe_remove(struct pci_dev *pdev)
5670{
5671 struct net_device *netdev = pci_get_drvdata(pdev);
5672 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005673 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005674
5675 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08005676 /* clear the module not found bit to make sure the worker won't
5677 * reschedule
5678 */
5679 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07005680 del_timer_sync(&adapter->watchdog_timer);
5681
Donald Skidmorec4900be2008-11-20 21:11:42 -08005682 del_timer_sync(&adapter->sfp_timer);
5683 cancel_work_sync(&adapter->watchdog_task);
5684 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005685 cancel_work_sync(&adapter->multispeed_fiber_task);
5686 cancel_work_sync(&adapter->sfp_config_module_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005687 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5688 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5689 cancel_work_sync(&adapter->fdir_reinit_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005690 flush_scheduled_work();
5691
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005692#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005693 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
5694 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
5695 dca_remove_requester(&pdev->dev);
5696 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
5697 }
5698
5699#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005700#ifdef IXGBE_FCOE
5701 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
5702 ixgbe_cleanup_fcoe(adapter);
5703
5704#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005705
5706 /* remove the added san mac */
5707 ixgbe_del_sanmac_netdev(netdev);
5708
Donald Skidmorec4900be2008-11-20 21:11:42 -08005709 if (netdev->reg_state == NETREG_REGISTERED)
5710 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005711
Alexander Duyck7a921c92009-05-06 10:43:28 +00005712 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005713
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005714 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005715
5716 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00005717 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5718 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005719
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005720 DPRINTK(PROBE, INFO, "complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005721
Auke Kok9a799d72007-09-15 14:07:45 -07005722 free_netdev(netdev);
5723
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005724 err = pci_disable_pcie_error_reporting(pdev);
5725 if (err)
5726 dev_err(&pdev->dev,
5727 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
5728
Auke Kok9a799d72007-09-15 14:07:45 -07005729 pci_disable_device(pdev);
5730}
5731
5732/**
5733 * ixgbe_io_error_detected - called when PCI error is detected
5734 * @pdev: Pointer to PCI device
5735 * @state: The current pci connection state
5736 *
5737 * This function is called after a PCI bus error affecting
5738 * this device has been detected.
5739 */
5740static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005741 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07005742{
5743 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005744 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005745
5746 netif_device_detach(netdev);
5747
Breno Leitao3044b8d2009-05-06 10:44:26 +00005748 if (state == pci_channel_io_perm_failure)
5749 return PCI_ERS_RESULT_DISCONNECT;
5750
Auke Kok9a799d72007-09-15 14:07:45 -07005751 if (netif_running(netdev))
5752 ixgbe_down(adapter);
5753 pci_disable_device(pdev);
5754
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005755 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07005756 return PCI_ERS_RESULT_NEED_RESET;
5757}
5758
5759/**
5760 * ixgbe_io_slot_reset - called after the pci bus has been reset.
5761 * @pdev: Pointer to PCI device
5762 *
5763 * Restart the card from scratch, as if from a cold-boot.
5764 */
5765static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
5766{
5767 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005768 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005769 pci_ers_result_t result;
5770 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005771
gouji-new9ce77662009-05-06 10:44:45 +00005772 if (pci_enable_device_mem(pdev)) {
Auke Kok9a799d72007-09-15 14:07:45 -07005773 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005774 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005775 result = PCI_ERS_RESULT_DISCONNECT;
5776 } else {
5777 pci_set_master(pdev);
5778 pci_restore_state(pdev);
5779
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005780 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005781
5782 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00005783 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005784 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07005785 }
Auke Kok9a799d72007-09-15 14:07:45 -07005786
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005787 err = pci_cleanup_aer_uncorrect_error_status(pdev);
5788 if (err) {
5789 dev_err(&pdev->dev,
5790 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
5791 /* non-fatal, continue */
5792 }
Auke Kok9a799d72007-09-15 14:07:45 -07005793
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005794 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07005795}
5796
5797/**
5798 * ixgbe_io_resume - called when traffic can start flowing again.
5799 * @pdev: Pointer to PCI device
5800 *
5801 * This callback is called when the error recovery driver tells us that
5802 * its OK to resume normal operation.
5803 */
5804static void ixgbe_io_resume(struct pci_dev *pdev)
5805{
5806 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08005807 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005808
5809 if (netif_running(netdev)) {
5810 if (ixgbe_up(adapter)) {
5811 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
5812 return;
5813 }
5814 }
5815
5816 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005817}
5818
5819static struct pci_error_handlers ixgbe_err_handler = {
5820 .error_detected = ixgbe_io_error_detected,
5821 .slot_reset = ixgbe_io_slot_reset,
5822 .resume = ixgbe_io_resume,
5823};
5824
5825static struct pci_driver ixgbe_driver = {
5826 .name = ixgbe_driver_name,
5827 .id_table = ixgbe_pci_tbl,
5828 .probe = ixgbe_probe,
5829 .remove = __devexit_p(ixgbe_remove),
5830#ifdef CONFIG_PM
5831 .suspend = ixgbe_suspend,
5832 .resume = ixgbe_resume,
5833#endif
5834 .shutdown = ixgbe_shutdown,
5835 .err_handler = &ixgbe_err_handler
5836};
5837
5838/**
5839 * ixgbe_init_module - Driver Registration Routine
5840 *
5841 * ixgbe_init_module is the first routine called when the driver is
5842 * loaded. All it does is register with the PCI subsystem.
5843 **/
5844static int __init ixgbe_init_module(void)
5845{
5846 int ret;
5847 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
5848 ixgbe_driver_string, ixgbe_driver_version);
5849
5850 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
5851
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005852#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005853 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005854#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005855
Auke Kok9a799d72007-09-15 14:07:45 -07005856 ret = pci_register_driver(&ixgbe_driver);
5857 return ret;
5858}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005859
Auke Kok9a799d72007-09-15 14:07:45 -07005860module_init(ixgbe_init_module);
5861
5862/**
5863 * ixgbe_exit_module - Driver Exit Cleanup Routine
5864 *
5865 * ixgbe_exit_module is called just before the driver is removed
5866 * from memory.
5867 **/
5868static void __exit ixgbe_exit_module(void)
5869{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005870#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005871 dca_unregister_notify(&dca_notifier);
5872#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005873 pci_unregister_driver(&ixgbe_driver);
5874}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005875
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005876#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005877static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005878 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005879{
5880 int ret_val;
5881
5882 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005883 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005884
5885 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
5886}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005887
Alexander Duyckb4533682009-03-31 21:32:42 +00005888#endif /* CONFIG_IXGBE_DCA */
5889#ifdef DEBUG
5890/**
5891 * ixgbe_get_hw_dev_name - return device name string
5892 * used by hardware layer to print debugging information
5893 **/
5894char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
5895{
5896 struct ixgbe_adapter *adapter = hw->back;
5897 return adapter->netdev->name;
5898}
5899
5900#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005901module_exit(ixgbe_exit_module);
5902
5903/* ixgbe_main.c */