blob: 3e981a1b0cd6d9612c9161c9f195e07e8cdefb09 [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>
42
43#include "ixgbe.h"
44#include "ixgbe_common.h"
45
46char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070047static const char ixgbe_driver_string[] =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070048 "Intel(R) 10 Gigabit PCI Express Network Driver";
Auke Kok9a799d72007-09-15 14:07:45 -070049
PJ Waskiewicze8e26352009-02-27 15:45:05 +000050#define DRV_VERSION "2.0.8-k2"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070051const char ixgbe_driver_version[] = DRV_VERSION;
Peter P Waskiewicz Jr3efac5a2009-02-01 01:19:20 -080052static char ixgbe_copyright[] = "Copyright (c) 1999-2009 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070053
54static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070055 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000056 [board_82599] = &ixgbe_82599_info,
Auke Kok9a799d72007-09-15 14:07:45 -070057};
58
59/* ixgbe_pci_tbl - PCI Device ID Table
60 *
61 * Wildcard entries (PCI_ANY_ID) should come last
62 * Last entry must be all 0s
63 *
64 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
65 * Class, Class Mask, private data (not used) }
66 */
67static struct pci_device_id ixgbe_pci_tbl[] = {
Don Skidmore1e336d02009-01-26 20:57:51 -080068 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
69 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070070 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070071 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070072 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070073 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070074 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
75 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070076 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070077 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070078 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
79 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080080 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
81 board_82598 },
82 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
83 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070084 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
85 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080086 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
87 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -080088 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
89 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +000090 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
91 board_82599 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
93 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -070094
95 /* required last entry */
96 {0, }
97};
98MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
99
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400100#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800101static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700102 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800103static struct notifier_block dca_notifier = {
104 .notifier_call = ixgbe_notify_dca,
105 .next = NULL,
106 .priority = 0
107};
108#endif
109
Auke Kok9a799d72007-09-15 14:07:45 -0700110MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
111MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
112MODULE_LICENSE("GPL");
113MODULE_VERSION(DRV_VERSION);
114
115#define DEFAULT_DEBUG_LEVEL_SHIFT 3
116
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800117static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
118{
119 u32 ctrl_ext;
120
121 /* Let firmware take over control of h/w */
122 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
123 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700124 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800125}
126
127static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
128{
129 u32 ctrl_ext;
130
131 /* Let firmware know the driver has taken over */
132 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
133 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700134 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800135}
Auke Kok9a799d72007-09-15 14:07:45 -0700136
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000137/*
138 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
139 * @adapter: pointer to adapter struct
140 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
141 * @queue: queue to map the corresponding interrupt to
142 * @msix_vector: the vector to map to the corresponding queue
143 *
144 */
145static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
146 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700147{
148 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000149 struct ixgbe_hw *hw = &adapter->hw;
150 switch (hw->mac.type) {
151 case ixgbe_mac_82598EB:
152 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
153 if (direction == -1)
154 direction = 0;
155 index = (((direction * 64) + queue) >> 2) & 0x1F;
156 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
157 ivar &= ~(0xFF << (8 * (queue & 0x3)));
158 ivar |= (msix_vector << (8 * (queue & 0x3)));
159 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
160 break;
161 case ixgbe_mac_82599EB:
162 if (direction == -1) {
163 /* other causes */
164 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
165 index = ((queue & 1) * 8);
166 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
167 ivar &= ~(0xFF << index);
168 ivar |= (msix_vector << index);
169 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
170 break;
171 } else {
172 /* tx or rx causes */
173 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
174 index = ((16 * (queue & 1)) + (8 * direction));
175 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
176 ivar &= ~(0xFF << index);
177 ivar |= (msix_vector << index);
178 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
179 break;
180 }
181 default:
182 break;
183 }
Auke Kok9a799d72007-09-15 14:07:45 -0700184}
185
186static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700187 struct ixgbe_tx_buffer
188 *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700189{
190 if (tx_buffer_info->dma) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700191 pci_unmap_page(adapter->pdev, tx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700192 tx_buffer_info->length, PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700193 tx_buffer_info->dma = 0;
194 }
195 if (tx_buffer_info->skb) {
196 dev_kfree_skb_any(tx_buffer_info->skb);
197 tx_buffer_info->skb = NULL;
198 }
199 /* tx_buffer_info must be completely set up in the transmit path */
200}
201
202static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700203 struct ixgbe_ring *tx_ring,
204 unsigned int eop)
Auke Kok9a799d72007-09-15 14:07:45 -0700205{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700206 struct ixgbe_hw *hw = &adapter->hw;
207 u32 head, tail;
208
Auke Kok9a799d72007-09-15 14:07:45 -0700209 /* Detect a transmit hang in hardware, this serializes the
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700210 * check with the clearing of time_stamp and movement of eop */
211 head = IXGBE_READ_REG(hw, tx_ring->head);
212 tail = IXGBE_READ_REG(hw, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -0700213 adapter->detect_tx_hung = false;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700214 if ((head != tail) &&
215 tx_ring->tx_buffer_info[eop].time_stamp &&
Auke Kok9a799d72007-09-15 14:07:45 -0700216 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
217 !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) {
218 /* detected Tx unit hang */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700219 union ixgbe_adv_tx_desc *tx_desc;
220 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
Auke Kok9a799d72007-09-15 14:07:45 -0700221 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700222 " Tx Queue <%d>\n"
223 " TDH, TDT <%x>, <%x>\n"
Auke Kok9a799d72007-09-15 14:07:45 -0700224 " next_to_use <%x>\n"
225 " next_to_clean <%x>\n"
226 "tx_buffer_info[next_to_clean]\n"
227 " time_stamp <%lx>\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700228 " jiffies <%lx>\n",
229 tx_ring->queue_index,
230 head, tail,
231 tx_ring->next_to_use, eop,
232 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
Auke Kok9a799d72007-09-15 14:07:45 -0700233 return true;
234 }
235
236 return false;
237}
238
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700239#define IXGBE_MAX_TXD_PWR 14
240#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800241
242/* Tx Descriptors needed, worst case */
243#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
244 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
245#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700246 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800247
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700248static void ixgbe_tx_timeout(struct net_device *netdev);
249
Auke Kok9a799d72007-09-15 14:07:45 -0700250/**
251 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
252 * @adapter: board private structure
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700253 * @tx_ring: tx ring to clean
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000254 *
255 * returns true if transmit work is done
Auke Kok9a799d72007-09-15 14:07:45 -0700256 **/
257static bool ixgbe_clean_tx_irq(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700258 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700259{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700260 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800261 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
262 struct ixgbe_tx_buffer *tx_buffer_info;
263 unsigned int i, eop, count = 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700264 unsigned int total_bytes = 0, total_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700265
266 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800267 eop = tx_ring->tx_buffer_info[i].next_to_watch;
268 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
269
270 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000271 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800272 bool cleaned = false;
273 for ( ; !cleaned; count++) {
274 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700275 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
276 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800277 cleaned = (i == eop);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700278 skb = tx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700279
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800280 if (cleaned && skb) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800281 unsigned int segs, bytecount;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700282
283 /* gso_segs is currently only valid for tcp */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800284 segs = skb_shinfo(skb)->gso_segs ?: 1;
285 /* multiply data chunks by size of headers */
286 bytecount = ((segs - 1) * skb_headlen(skb)) +
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700287 skb->len;
288 total_packets += segs;
289 total_bytes += bytecount;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800290 }
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700291
Auke Kok9a799d72007-09-15 14:07:45 -0700292 ixgbe_unmap_and_free_tx_resource(adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700293 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700294
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800295 tx_desc->wb.status = 0;
296
Auke Kok9a799d72007-09-15 14:07:45 -0700297 i++;
298 if (i == tx_ring->count)
299 i = 0;
300 }
301
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800302 eop = tx_ring->tx_buffer_info[i].next_to_watch;
303 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
304 }
305
Auke Kok9a799d72007-09-15 14:07:45 -0700306 tx_ring->next_to_clean = i;
307
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800308#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700309 if (unlikely(count && netif_carrier_ok(netdev) &&
310 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800311 /* Make sure that anybody stopping the queue after this
312 * sees the new next_to_clean.
313 */
314 smp_mb();
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800315 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
316 !test_bit(__IXGBE_DOWN, &adapter->state)) {
317 netif_wake_subqueue(netdev, tx_ring->queue_index);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700318 ++adapter->restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800319 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800320 }
Auke Kok9a799d72007-09-15 14:07:45 -0700321
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700322 if (adapter->detect_tx_hung) {
323 if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
324 /* schedule immediate reset if we believe we hung */
325 DPRINTK(PROBE, INFO,
326 "tx hang %d detected, resetting adapter\n",
327 adapter->tx_timeout_count + 1);
328 ixgbe_tx_timeout(adapter->netdev);
329 }
330 }
Auke Kok9a799d72007-09-15 14:07:45 -0700331
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700332 /* re-arm the interrupt */
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000333 if (count >= tx_ring->work_limit)
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700334 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, tx_ring->v_idx);
Auke Kok9a799d72007-09-15 14:07:45 -0700335
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700336 tx_ring->total_bytes += total_bytes;
337 tx_ring->total_packets += total_packets;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700338 tx_ring->stats.packets += total_packets;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800339 tx_ring->stats.bytes += total_bytes;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700340 adapter->net_stats.tx_bytes += total_bytes;
341 adapter->net_stats.tx_packets += total_packets;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000342 return (count < tx_ring->work_limit);
Auke Kok9a799d72007-09-15 14:07:45 -0700343}
344
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400345#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800346static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700347 struct ixgbe_ring *rx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800348{
349 u32 rxctrl;
350 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700351 int q = rx_ring - adapter->rx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800352
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700353 if (rx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800354 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000355 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
356 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
357 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
358 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
359 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
360 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
361 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
362 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800363 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
364 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
Don Skidmore15005a32009-01-19 16:54:13 -0800365 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
366 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000367 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800368 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700369 rx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800370 }
371 put_cpu();
372}
373
374static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700375 struct ixgbe_ring *tx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800376{
377 u32 txctrl;
378 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700379 int q = tx_ring - adapter->tx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800380
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700381 if (tx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800382 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000383 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
384 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
385 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
386 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
387 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
388 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
389 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
390 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800391 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
392 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700393 tx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800394 }
395 put_cpu();
396}
397
398static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
399{
400 int i;
401
402 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
403 return;
404
405 for (i = 0; i < adapter->num_tx_queues; i++) {
406 adapter->tx_ring[i].cpu = -1;
407 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
408 }
409 for (i = 0; i < adapter->num_rx_queues; i++) {
410 adapter->rx_ring[i].cpu = -1;
411 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
412 }
413}
414
415static int __ixgbe_notify_dca(struct device *dev, void *data)
416{
417 struct net_device *netdev = dev_get_drvdata(dev);
418 struct ixgbe_adapter *adapter = netdev_priv(netdev);
419 unsigned long event = *(unsigned long *)data;
420
421 switch (event) {
422 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700423 /* if we're already enabled, don't do it again */
424 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
425 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800426 /* Always use CB2 mode, difference is masked
427 * in the CB driver. */
428 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
Denis V. Lunev652f0932008-03-27 14:39:17 +0300429 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700430 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800431 ixgbe_setup_dca(adapter);
432 break;
433 }
434 /* Fall Through since DCA is disabled. */
435 case DCA_PROVIDER_REMOVE:
436 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
437 dca_remove_requester(dev);
438 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
439 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
440 }
441 break;
442 }
443
Denis V. Lunev652f0932008-03-27 14:39:17 +0300444 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800445}
446
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400447#endif /* CONFIG_IXGBE_DCA */
Auke Kok9a799d72007-09-15 14:07:45 -0700448/**
449 * ixgbe_receive_skb - Send a completed packet up the stack
450 * @adapter: board private structure
451 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700452 * @status: hardware indication of status of receive
453 * @rx_ring: rx descriptor ring (for a specific queue) to setup
454 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -0700455 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800456static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700457 struct sk_buff *skb, u8 status,
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700458 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -0700459{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800460 struct ixgbe_adapter *adapter = q_vector->adapter;
461 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700462 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
463 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -0700464
David S. Miller0c8dfc82009-01-27 16:22:32 -0800465 skb_record_rx_queue(skb, q_vector - &adapter->q_vector[0]);
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800466 if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800467 if (adapter->vlgrp && is_vlan && (tag != 0))
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800468 vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700469 else
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800470 napi_gro_receive(napi, skb);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700471 } else {
472 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800473 if (adapter->vlgrp && is_vlan && (tag != 0))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700474 vlan_hwaccel_receive_skb(skb, adapter->vlgrp, tag);
475 else
476 netif_receive_skb(skb);
477 } else {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800478 if (adapter->vlgrp && is_vlan && (tag != 0))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700479 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
480 else
481 netif_rx(skb);
482 }
Auke Kok9a799d72007-09-15 14:07:45 -0700483 }
484}
485
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800486/**
487 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
488 * @adapter: address of board private structure
489 * @status_err: hardware indication of status of receive
490 * @skb: skb currently being received and modified
491 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700492static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700493 u32 status_err, struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700494{
495 skb->ip_summed = CHECKSUM_NONE;
496
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700497 /* Rx csum disabled */
498 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -0700499 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800500
501 /* if IP and error */
502 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
503 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700504 adapter->hw_csum_rx_error++;
505 return;
506 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800507
508 if (!(status_err & IXGBE_RXD_STAT_L4CS))
509 return;
510
511 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
512 adapter->hw_csum_rx_error++;
513 return;
514 }
515
Auke Kok9a799d72007-09-15 14:07:45 -0700516 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800517 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -0700518 adapter->hw_csum_rx_good++;
519}
520
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000521static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
522 struct ixgbe_ring *rx_ring, u32 val)
523{
524 /*
525 * Force memory writes to complete before letting h/w
526 * know there are new descriptors to fetch. (Only
527 * applicable for weak-ordered memory model archs,
528 * such as IA-64).
529 */
530 wmb();
531 IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
532}
533
Auke Kok9a799d72007-09-15 14:07:45 -0700534/**
535 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
536 * @adapter: address of board private structure
537 **/
538static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700539 struct ixgbe_ring *rx_ring,
540 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700541{
Auke Kok9a799d72007-09-15 14:07:45 -0700542 struct pci_dev *pdev = adapter->pdev;
543 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700544 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700545 unsigned int i;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000546 unsigned int bufsz = rx_ring->rx_buf_len + NET_IP_ALIGN;
Auke Kok9a799d72007-09-15 14:07:45 -0700547
548 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700549 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700550
551 while (cleaned_count--) {
552 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
553
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700554 if (!bi->page_dma &&
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700555 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700556 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700557 bi->page = alloc_page(GFP_ATOMIC);
558 if (!bi->page) {
559 adapter->alloc_rx_page_failed++;
560 goto no_buffers;
561 }
562 bi->page_offset = 0;
563 } else {
564 /* use a half page if we're re-using */
565 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700566 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700567
568 bi->page_dma = pci_map_page(pdev, bi->page,
569 bi->page_offset,
570 (PAGE_SIZE / 2),
571 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700572 }
573
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700574 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800575 struct sk_buff *skb;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000576 skb = netdev_alloc_skb(adapter->netdev, bufsz);
Auke Kok9a799d72007-09-15 14:07:45 -0700577
578 if (!skb) {
579 adapter->alloc_rx_buff_failed++;
580 goto no_buffers;
581 }
582
583 /*
584 * Make buffer alignment 2 beyond a 16 byte boundary
585 * this will result in a 16 byte aligned IP header after
586 * the 14 byte MAC header is removed
587 */
588 skb_reserve(skb, NET_IP_ALIGN);
589
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700590 bi->skb = skb;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000591 bi->dma = pci_map_single(pdev, skb->data, bufsz,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700592 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700593 }
594 /* Refresh the desc even if buffer_addrs didn't change because
595 * each write-back erases this info. */
596 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700597 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
598 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700599 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700600 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700601 }
602
603 i++;
604 if (i == rx_ring->count)
605 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700606 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700607 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700608
Auke Kok9a799d72007-09-15 14:07:45 -0700609no_buffers:
610 if (rx_ring->next_to_use != i) {
611 rx_ring->next_to_use = i;
612 if (i-- == 0)
613 i = (rx_ring->count - 1);
614
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000615 ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700616 }
617}
618
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700619static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
620{
621 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
622}
623
624static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
625{
626 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
627}
628
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800629static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700630 struct ixgbe_ring *rx_ring,
631 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700632{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800633 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -0700634 struct pci_dev *pdev = adapter->pdev;
635 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
636 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
637 struct sk_buff *skb;
638 unsigned int i;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700639 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700640 u16 hdr_info;
641 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700642 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800643 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700644
645 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700646 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
647 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
648 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700649
650 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700651 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700652 if (*work_done >= work_to_do)
653 break;
654 (*work_done)++;
655
656 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700657 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
658 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700659 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700660 if (hdr_info & IXGBE_RXDADV_SPH)
661 adapter->rx_hdr_split++;
662 if (len > IXGBE_RX_HDR_SIZE)
663 len = IXGBE_RX_HDR_SIZE;
664 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700665 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700666 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700667 }
Auke Kok9a799d72007-09-15 14:07:45 -0700668
669 cleaned = true;
670 skb = rx_buffer_info->skb;
671 prefetch(skb->data - NET_IP_ALIGN);
672 rx_buffer_info->skb = NULL;
673
674 if (len && !skb_shinfo(skb)->nr_frags) {
675 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800676 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700677 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700678 skb_put(skb, len);
679 }
680
681 if (upper_len) {
682 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700683 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700684 rx_buffer_info->page_dma = 0;
685 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700686 rx_buffer_info->page,
687 rx_buffer_info->page_offset,
688 upper_len);
689
690 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
691 (page_count(rx_buffer_info->page) != 1))
692 rx_buffer_info->page = NULL;
693 else
694 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700695
696 skb->len += upper_len;
697 skb->data_len += upper_len;
698 skb->truesize += upper_len;
699 }
700
701 i++;
702 if (i == rx_ring->count)
703 i = 0;
704 next_buffer = &rx_ring->rx_buffer_info[i];
705
706 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
707 prefetch(next_rxd);
708
709 cleaned_count++;
710 if (staterr & IXGBE_RXD_STAT_EOP) {
711 rx_ring->stats.packets++;
712 rx_ring->stats.bytes += skb->len;
713 } else {
714 rx_buffer_info->skb = next_buffer->skb;
715 rx_buffer_info->dma = next_buffer->dma;
716 next_buffer->skb = skb;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700717 next_buffer->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700718 adapter->non_eop_descs++;
719 goto next_desc;
720 }
721
722 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
723 dev_kfree_skb_irq(skb);
724 goto next_desc;
725 }
726
727 ixgbe_rx_checksum(adapter, staterr, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800728
729 /* probably a little skewed due to removing CRC */
730 total_rx_bytes += skb->len;
731 total_rx_packets++;
732
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700733 skb->protocol = eth_type_trans(skb, adapter->netdev);
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800734 ixgbe_receive_skb(q_vector, skb, staterr, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700735
736next_desc:
737 rx_desc->wb.upper.status_error = 0;
738
739 /* return some buffers to hardware, one at a time is too slow */
740 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
741 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
742 cleaned_count = 0;
743 }
744
745 /* use prefetched values */
746 rx_desc = next_rxd;
747 rx_buffer_info = next_buffer;
748
749 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700750 }
751
Auke Kok9a799d72007-09-15 14:07:45 -0700752 rx_ring->next_to_clean = i;
753 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
754
755 if (cleaned_count)
756 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
757
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800758 rx_ring->total_packets += total_rx_packets;
759 rx_ring->total_bytes += total_rx_bytes;
760 adapter->net_stats.rx_bytes += total_rx_bytes;
761 adapter->net_stats.rx_packets += total_rx_packets;
762
Auke Kok9a799d72007-09-15 14:07:45 -0700763 return cleaned;
764}
765
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800766static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700767/**
768 * ixgbe_configure_msix - Configure MSI-X hardware
769 * @adapter: board private structure
770 *
771 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
772 * interrupts.
773 **/
774static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
775{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800776 struct ixgbe_q_vector *q_vector;
777 int i, j, q_vectors, v_idx, r_idx;
778 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700779
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800780 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
781
782 /* Populate the IVAR table and set the ITR values to the
783 * corresponding register.
784 */
785 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
786 q_vector = &adapter->q_vector[v_idx];
787 /* XXX for_each_bit(...) */
788 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700789 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800790
791 for (i = 0; i < q_vector->rxr_count; i++) {
792 j = adapter->rx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000793 ixgbe_set_ivar(adapter, 0, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800794 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700795 adapter->num_rx_queues,
796 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800797 }
798 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700799 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800800
801 for (i = 0; i < q_vector->txr_count; i++) {
802 j = adapter->tx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000803 ixgbe_set_ivar(adapter, 1, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800804 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700805 adapter->num_tx_queues,
806 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800807 }
808
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700809 /* if this is a tx only vector halve the interrupt rate */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800810 if (q_vector->txr_count && !q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700811 q_vector->eitr = (adapter->eitr_param >> 1);
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000812 else if (q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700813 /* rx only */
814 q_vector->eitr = adapter->eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800815
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000816 /*
817 * since ths is initial set up don't need to call
818 * ixgbe_write_eitr helper
819 */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800820 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx),
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700821 EITR_INTS_PER_SEC_TO_REG(q_vector->eitr));
Auke Kok9a799d72007-09-15 14:07:45 -0700822 }
823
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000824 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
825 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
826 v_idx);
827 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
828 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800829 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -0700830
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700831 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800832 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700833 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800834 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -0700835}
836
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800837enum latency_range {
838 lowest_latency = 0,
839 low_latency = 1,
840 bulk_latency = 2,
841 latency_invalid = 255
842};
843
844/**
845 * ixgbe_update_itr - update the dynamic ITR value based on statistics
846 * @adapter: pointer to adapter
847 * @eitr: eitr setting (ints per sec) to give last timeslice
848 * @itr_setting: current throttle rate in ints/second
849 * @packets: the number of packets during this measurement interval
850 * @bytes: the number of bytes during this measurement interval
851 *
852 * Stores a new ITR value based on packets and byte
853 * counts during the last interrupt. The advantage of per interrupt
854 * computation is faster updates and more accurate ITR for the current
855 * traffic pattern. Constants in this function were computed
856 * based on theoretical maximum wire speed and thresholds were set based
857 * on testing data as well as attempting to minimize response time
858 * while increasing bulk throughput.
859 * this functionality is controlled by the InterruptThrottleRate module
860 * parameter (see ixgbe_param.c)
861 **/
862static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700863 u32 eitr, u8 itr_setting,
864 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800865{
866 unsigned int retval = itr_setting;
867 u32 timepassed_us;
868 u64 bytes_perint;
869
870 if (packets == 0)
871 goto update_itr_done;
872
873
874 /* simple throttlerate management
875 * 0-20MB/s lowest (100000 ints/s)
876 * 20-100MB/s low (20000 ints/s)
877 * 100-1249MB/s bulk (8000 ints/s)
878 */
879 /* what was last interrupt timeslice? */
880 timepassed_us = 1000000/eitr;
881 bytes_perint = bytes / timepassed_us; /* bytes/usec */
882
883 switch (itr_setting) {
884 case lowest_latency:
885 if (bytes_perint > adapter->eitr_low)
886 retval = low_latency;
887 break;
888 case low_latency:
889 if (bytes_perint > adapter->eitr_high)
890 retval = bulk_latency;
891 else if (bytes_perint <= adapter->eitr_low)
892 retval = lowest_latency;
893 break;
894 case bulk_latency:
895 if (bytes_perint <= adapter->eitr_high)
896 retval = low_latency;
897 break;
898 }
899
900update_itr_done:
901 return retval;
902}
903
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000904/**
905 * ixgbe_write_eitr - write EITR register in hardware specific way
906 * @adapter: pointer to adapter struct
907 * @v_idx: vector index into q_vector array
908 * @itr_reg: new value to be written in *register* format, not ints/s
909 *
910 * This function is made to be called by ethtool and by the driver
911 * when it needs to update EITR registers at runtime. Hardware
912 * specific quirks/differences are taken care of here.
913 */
914void ixgbe_write_eitr(struct ixgbe_adapter *adapter, int v_idx, u32 itr_reg)
915{
916 struct ixgbe_hw *hw = &adapter->hw;
917 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
918 /* must write high and low 16 bits to reset counter */
919 itr_reg |= (itr_reg << 16);
920 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
921 /*
922 * set the WDIS bit to not clear the timer bits and cause an
923 * immediate assertion of the interrupt
924 */
925 itr_reg |= IXGBE_EITR_CNT_WDIS;
926 }
927 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
928}
929
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800930static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
931{
932 struct ixgbe_adapter *adapter = q_vector->adapter;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800933 u32 new_itr;
934 u8 current_itr, ret_itr;
935 int i, r_idx, v_idx = ((void *)q_vector - (void *)(adapter->q_vector)) /
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700936 sizeof(struct ixgbe_q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800937 struct ixgbe_ring *rx_ring, *tx_ring;
938
939 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
940 for (i = 0; i < q_vector->txr_count; i++) {
941 tx_ring = &(adapter->tx_ring[r_idx]);
942 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700943 q_vector->tx_itr,
944 tx_ring->total_packets,
945 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800946 /* if the result for this queue would decrease interrupt
947 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700948 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700949 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800950 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700951 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800952 }
953
954 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
955 for (i = 0; i < q_vector->rxr_count; i++) {
956 rx_ring = &(adapter->rx_ring[r_idx]);
957 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700958 q_vector->rx_itr,
959 rx_ring->total_packets,
960 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800961 /* if the result for this queue would decrease interrupt
962 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700963 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700964 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800965 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700966 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800967 }
968
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700969 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800970
971 switch (current_itr) {
972 /* counts and packets in update_itr are dependent on these numbers */
973 case lowest_latency:
974 new_itr = 100000;
975 break;
976 case low_latency:
977 new_itr = 20000; /* aka hwitr = ~200 */
978 break;
979 case bulk_latency:
980 default:
981 new_itr = 8000;
982 break;
983 }
984
985 if (new_itr != q_vector->eitr) {
986 u32 itr_reg;
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000987
988 /* save the algorithm value here, not the smoothed one */
989 q_vector->eitr = new_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800990 /* do an exponential smoothing */
991 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800992 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +0000993 ixgbe_write_eitr(adapter, v_idx, itr_reg);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800994 }
995
996 return;
997}
998
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700999static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1000{
1001 struct ixgbe_hw *hw = &adapter->hw;
1002
1003 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1004 (eicr & IXGBE_EICR_GPI_SDP1)) {
1005 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
1006 /* write to clear the interrupt */
1007 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1008 }
1009}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001010
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001011static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1012{
1013 struct ixgbe_hw *hw = &adapter->hw;
1014
1015 if (eicr & IXGBE_EICR_GPI_SDP1) {
1016 /* Clear the interrupt */
1017 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1018 schedule_work(&adapter->multispeed_fiber_task);
1019 } else if (eicr & IXGBE_EICR_GPI_SDP2) {
1020 /* Clear the interrupt */
1021 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1022 schedule_work(&adapter->sfp_config_module_task);
1023 } else {
1024 /* Interrupt isn't for us... */
1025 return;
1026 }
1027}
1028
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001029static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1030{
1031 struct ixgbe_hw *hw = &adapter->hw;
1032
1033 adapter->lsc_int++;
1034 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1035 adapter->link_check_timeout = jiffies;
1036 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1037 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
1038 schedule_work(&adapter->watchdog_task);
1039 }
1040}
1041
Auke Kok9a799d72007-09-15 14:07:45 -07001042static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1043{
1044 struct net_device *netdev = data;
1045 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1046 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001047 u32 eicr;
1048
1049 /*
1050 * Workaround for Silicon errata. Use clear-by-write instead
1051 * of clear-by-read. Reading with EICS will return the
1052 * interrupt causes without clearing, which later be done
1053 * with the write to EICR.
1054 */
1055 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1056 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001057
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001058 if (eicr & IXGBE_EICR_LSC)
1059 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001060
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001061 if (hw->mac.type == ixgbe_mac_82598EB)
1062 ixgbe_check_fan_failure(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001063
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001064 if (hw->mac.type == ixgbe_mac_82599EB)
1065 ixgbe_check_sfp_event(adapter, eicr);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001066 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1067 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -07001068
1069 return IRQ_HANDLED;
1070}
1071
1072static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1073{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001074 struct ixgbe_q_vector *q_vector = data;
1075 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001076 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001077 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001078
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001079 if (!q_vector->txr_count)
1080 return IRQ_HANDLED;
1081
1082 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1083 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001084 tx_ring = &(adapter->tx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001085#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001086 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001087 ixgbe_update_tx_dca(adapter, tx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001088#endif
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001089 tx_ring->total_bytes = 0;
1090 tx_ring->total_packets = 0;
1091 ixgbe_clean_tx_irq(adapter, tx_ring);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001092 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001093 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001094 }
1095
Auke Kok9a799d72007-09-15 14:07:45 -07001096 return IRQ_HANDLED;
1097}
1098
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001099/**
1100 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1101 * @irq: unused
1102 * @data: pointer to our q_vector struct for this interrupt vector
1103 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001104static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1105{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001106 struct ixgbe_q_vector *q_vector = data;
1107 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001108 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001109 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001110 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001111
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001112 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001113 for (i = 0; i < q_vector->rxr_count; i++) {
1114 rx_ring = &(adapter->rx_ring[r_idx]);
1115 rx_ring->total_bytes = 0;
1116 rx_ring->total_packets = 0;
1117 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1118 r_idx + 1);
1119 }
1120
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001121 if (!q_vector->rxr_count)
1122 return IRQ_HANDLED;
1123
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001124 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001125 rx_ring = &(adapter->rx_ring[r_idx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001126 /* disable interrupts on this vector only */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001127 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rx_ring->v_idx);
Ben Hutchings288379f2009-01-19 16:43:59 -08001128 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001129
Auke Kok9a799d72007-09-15 14:07:45 -07001130 return IRQ_HANDLED;
1131}
1132
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001133static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1134{
1135 ixgbe_msix_clean_rx(irq, data);
1136 ixgbe_msix_clean_tx(irq, data);
1137
1138 return IRQ_HANDLED;
1139}
1140
1141/**
1142 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1143 * @napi: napi struct with our devices info in it
1144 * @budget: amount of work driver is allowed to do this pass, in packets
1145 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001146 * This function is optimized for cleaning one queue only on a single
1147 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001148 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001149static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1150{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001151 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001152 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001153 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001154 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001155 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001156 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001157
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001158 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001159 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001160#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001161 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001162 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001163#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001164
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001165 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001166
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001167 /* If all Rx work done, exit the polling mode */
1168 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001169 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001170 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001171 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001172 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001173 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rx_ring->v_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07001174 }
1175
1176 return work_done;
1177}
1178
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001179/**
1180 * ixgbe_clean_rxonly_many - msix (aka one shot) rx clean routine
1181 * @napi: napi struct with our devices info in it
1182 * @budget: amount of work driver is allowed to do this pass, in packets
1183 *
1184 * This function will clean more than one rx queue associated with a
1185 * q_vector.
1186 **/
1187static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget)
1188{
1189 struct ixgbe_q_vector *q_vector =
1190 container_of(napi, struct ixgbe_q_vector, napi);
1191 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001192 struct ixgbe_ring *rx_ring = NULL;
1193 int work_done = 0, i;
1194 long r_idx;
1195 u16 enable_mask = 0;
1196
1197 /* attempt to distribute budget to each queue fairly, but don't allow
1198 * the budget to go below 1 because we'll exit polling */
1199 budget /= (q_vector->rxr_count ?: 1);
1200 budget = max(budget, 1);
1201 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1202 for (i = 0; i < q_vector->rxr_count; i++) {
1203 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001204#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001205 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1206 ixgbe_update_rx_dca(adapter, rx_ring);
1207#endif
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001208 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001209 enable_mask |= rx_ring->v_idx;
1210 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1211 r_idx + 1);
1212 }
1213
1214 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1215 rx_ring = &(adapter->rx_ring[r_idx]);
1216 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001217 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001218 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001219 if (adapter->itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001220 ixgbe_set_itr_msix(q_vector);
1221 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1222 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, enable_mask);
1223 return 0;
1224 }
1225
1226 return work_done;
1227}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001228static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001229 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001230{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001231 a->q_vector[v_idx].adapter = a;
1232 set_bit(r_idx, a->q_vector[v_idx].rxr_idx);
1233 a->q_vector[v_idx].rxr_count++;
1234 a->rx_ring[r_idx].v_idx = 1 << v_idx;
1235}
Auke Kok9a799d72007-09-15 14:07:45 -07001236
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001237static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001238 int r_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001239{
1240 a->q_vector[v_idx].adapter = a;
1241 set_bit(r_idx, a->q_vector[v_idx].txr_idx);
1242 a->q_vector[v_idx].txr_count++;
1243 a->tx_ring[r_idx].v_idx = 1 << v_idx;
1244}
Auke Kok9a799d72007-09-15 14:07:45 -07001245
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001246/**
1247 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1248 * @adapter: board private structure to initialize
1249 * @vectors: allotted vector count for descriptor rings
1250 *
1251 * This function maps descriptor rings to the queue-specific vectors
1252 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1253 * one vector per ring/queue, but on a constrained vector budget, we
1254 * group the rings as "efficiently" as possible. You would add new
1255 * mapping configurations in here.
1256 **/
1257static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001258 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001259{
1260 int v_start = 0;
1261 int rxr_idx = 0, txr_idx = 0;
1262 int rxr_remaining = adapter->num_rx_queues;
1263 int txr_remaining = adapter->num_tx_queues;
1264 int i, j;
1265 int rqpv, tqpv;
1266 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001267
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001268 /* No mapping required if MSI-X is disabled. */
1269 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001270 goto out;
1271
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001272 /*
1273 * The ideal configuration...
1274 * We have enough vectors to map one per queue.
1275 */
1276 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1277 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1278 map_vector_to_rxq(adapter, v_start, rxr_idx);
1279
1280 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1281 map_vector_to_txq(adapter, v_start, txr_idx);
1282
1283 goto out;
1284 }
1285
1286 /*
1287 * If we don't have enough vectors for a 1-to-1
1288 * mapping, we'll have to group them so there are
1289 * multiple queues per vector.
1290 */
1291 /* Re-adjusting *qpv takes care of the remainder. */
1292 for (i = v_start; i < vectors; i++) {
1293 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1294 for (j = 0; j < rqpv; j++) {
1295 map_vector_to_rxq(adapter, i, rxr_idx);
1296 rxr_idx++;
1297 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001298 }
Auke Kok9a799d72007-09-15 14:07:45 -07001299 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001300 for (i = v_start; i < vectors; i++) {
1301 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1302 for (j = 0; j < tqpv; j++) {
1303 map_vector_to_txq(adapter, i, txr_idx);
1304 txr_idx++;
1305 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001306 }
Auke Kok9a799d72007-09-15 14:07:45 -07001307 }
1308
Auke Kok9a799d72007-09-15 14:07:45 -07001309out:
Auke Kok9a799d72007-09-15 14:07:45 -07001310 return err;
1311}
1312
1313/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001314 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1315 * @adapter: board private structure
1316 *
1317 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1318 * interrupts from the kernel.
1319 **/
1320static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1321{
1322 struct net_device *netdev = adapter->netdev;
1323 irqreturn_t (*handler)(int, void *);
1324 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001325 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001326
1327 /* Decrement for Other and TCP Timer vectors */
1328 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1329
1330 /* Map the Tx/Rx rings to the vectors we were allotted. */
1331 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1332 if (err)
1333 goto out;
1334
1335#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001336 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1337 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001338 for (vector = 0; vector < q_vectors; vector++) {
1339 handler = SET_HANDLER(&adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001340
1341 if(handler == &ixgbe_msix_clean_rx) {
1342 sprintf(adapter->name[vector], "%s-%s-%d",
1343 netdev->name, "rx", ri++);
1344 }
1345 else if(handler == &ixgbe_msix_clean_tx) {
1346 sprintf(adapter->name[vector], "%s-%s-%d",
1347 netdev->name, "tx", ti++);
1348 }
1349 else
1350 sprintf(adapter->name[vector], "%s-%s-%d",
1351 netdev->name, "TxRx", vector);
1352
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001353 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001354 handler, 0, adapter->name[vector],
1355 &(adapter->q_vector[vector]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001356 if (err) {
1357 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001358 "request_irq failed for MSIX interrupt "
1359 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001360 goto free_queue_irqs;
1361 }
1362 }
1363
1364 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1365 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001366 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001367 if (err) {
1368 DPRINTK(PROBE, ERR,
1369 "request_irq for msix_lsc failed: %d\n", err);
1370 goto free_queue_irqs;
1371 }
1372
1373 return 0;
1374
1375free_queue_irqs:
1376 for (i = vector - 1; i >= 0; i--)
1377 free_irq(adapter->msix_entries[--vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001378 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001379 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1380 pci_disable_msix(adapter->pdev);
1381 kfree(adapter->msix_entries);
1382 adapter->msix_entries = NULL;
1383out:
1384 return err;
1385}
1386
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001387static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1388{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001389 struct ixgbe_q_vector *q_vector = adapter->q_vector;
1390 u8 current_itr;
1391 u32 new_itr = q_vector->eitr;
1392 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1393 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1394
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001395 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001396 q_vector->tx_itr,
1397 tx_ring->total_packets,
1398 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001399 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001400 q_vector->rx_itr,
1401 rx_ring->total_packets,
1402 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001403
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001404 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001405
1406 switch (current_itr) {
1407 /* counts and packets in update_itr are dependent on these numbers */
1408 case lowest_latency:
1409 new_itr = 100000;
1410 break;
1411 case low_latency:
1412 new_itr = 20000; /* aka hwitr = ~200 */
1413 break;
1414 case bulk_latency:
1415 new_itr = 8000;
1416 break;
1417 default:
1418 break;
1419 }
1420
1421 if (new_itr != q_vector->eitr) {
1422 u32 itr_reg;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001423
1424 /* save the algorithm value here, not the smoothed one */
1425 q_vector->eitr = new_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001426 /* do an exponential smoothing */
1427 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001428 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001429 ixgbe_write_eitr(adapter, 0, itr_reg);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001430 }
1431
1432 return;
1433}
1434
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001435/**
1436 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1437 * @adapter: board private structure
1438 **/
1439static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1440{
1441 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001442 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1443 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
1444 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(2), ~0);
1445 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001446 IXGBE_WRITE_FLUSH(&adapter->hw);
1447 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1448 int i;
1449 for (i = 0; i < adapter->num_msix_vectors; i++)
1450 synchronize_irq(adapter->msix_entries[i].vector);
1451 } else {
1452 synchronize_irq(adapter->pdev->irq);
1453 }
1454}
1455
1456/**
1457 * ixgbe_irq_enable - Enable default interrupt generation settings
1458 * @adapter: board private structure
1459 **/
1460static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1461{
1462 u32 mask;
1463 mask = IXGBE_EIMS_ENABLE_MASK;
David S. Miller6ab33d52008-11-20 16:44:00 -08001464 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1465 mask |= IXGBE_EIMS_GPI_SDP1;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001466 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001467 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001468 mask |= IXGBE_EIMS_GPI_SDP1;
1469 mask |= IXGBE_EIMS_GPI_SDP2;
1470 }
1471
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001472 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001473 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1474 /* enable the rest of the queue vectors */
1475 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1),
1476 (IXGBE_EIMS_RTX_QUEUE << 16));
1477 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(2),
1478 ((IXGBE_EIMS_RTX_QUEUE << 16) |
1479 IXGBE_EIMS_RTX_QUEUE));
1480 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001481 IXGBE_WRITE_FLUSH(&adapter->hw);
1482}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001483
1484/**
1485 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001486 * @irq: interrupt number
1487 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001488 **/
1489static irqreturn_t ixgbe_intr(int irq, void *data)
1490{
1491 struct net_device *netdev = data;
1492 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1493 struct ixgbe_hw *hw = &adapter->hw;
1494 u32 eicr;
1495
Don Skidmore54037502009-02-21 15:42:56 -08001496 /*
1497 * Workaround for silicon errata. Mask the interrupts
1498 * before the read of EICR.
1499 */
1500 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1501
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001502 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1503 * therefore no explict interrupt disable is necessary */
1504 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001505 if (!eicr) {
1506 /* shared interrupt alert!
1507 * make sure interrupts are enabled because the read will
1508 * have disabled interrupts due to EIAM */
1509 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001510 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001511 }
Auke Kok9a799d72007-09-15 14:07:45 -07001512
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001513 if (eicr & IXGBE_EICR_LSC)
1514 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001515
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001516 if (hw->mac.type == ixgbe_mac_82599EB)
1517 ixgbe_check_sfp_event(adapter, eicr);
1518
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001519 ixgbe_check_fan_failure(adapter, eicr);
1520
Ben Hutchings288379f2009-01-19 16:43:59 -08001521 if (napi_schedule_prep(&adapter->q_vector[0].napi)) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001522 adapter->tx_ring[0].total_packets = 0;
1523 adapter->tx_ring[0].total_bytes = 0;
1524 adapter->rx_ring[0].total_packets = 0;
1525 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001526 /* would disable interrupts here but EIAM disabled it */
Ben Hutchings288379f2009-01-19 16:43:59 -08001527 __napi_schedule(&adapter->q_vector[0].napi);
Auke Kok9a799d72007-09-15 14:07:45 -07001528 }
1529
1530 return IRQ_HANDLED;
1531}
1532
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001533static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1534{
1535 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1536
1537 for (i = 0; i < q_vectors; i++) {
1538 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
1539 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1540 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1541 q_vector->rxr_count = 0;
1542 q_vector->txr_count = 0;
1543 }
1544}
1545
Auke Kok9a799d72007-09-15 14:07:45 -07001546/**
1547 * ixgbe_request_irq - initialize interrupts
1548 * @adapter: board private structure
1549 *
1550 * Attempts to configure interrupts using the best available
1551 * capabilities of the hardware and kernel.
1552 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001553static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001554{
1555 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001556 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001557
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001558 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1559 err = ixgbe_request_msix_irqs(adapter);
1560 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1561 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001562 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001563 } else {
1564 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001565 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001566 }
1567
Auke Kok9a799d72007-09-15 14:07:45 -07001568 if (err)
1569 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1570
Auke Kok9a799d72007-09-15 14:07:45 -07001571 return err;
1572}
1573
1574static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1575{
1576 struct net_device *netdev = adapter->netdev;
1577
1578 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001579 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001580
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001581 q_vectors = adapter->num_msix_vectors;
1582
1583 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001584 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001585
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001586 i--;
1587 for (; i >= 0; i--) {
1588 free_irq(adapter->msix_entries[i].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001589 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001590 }
1591
1592 ixgbe_reset_q_vectors(adapter);
1593 } else {
1594 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001595 }
1596}
1597
1598/**
Auke Kok9a799d72007-09-15 14:07:45 -07001599 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1600 *
1601 **/
1602static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1603{
Auke Kok9a799d72007-09-15 14:07:45 -07001604 struct ixgbe_hw *hw = &adapter->hw;
1605
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001606 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001607 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001608
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001609 ixgbe_set_ivar(adapter, 0, 0, 0);
1610 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001611
1612 map_vector_to_rxq(adapter, 0, 0);
1613 map_vector_to_txq(adapter, 0, 0);
1614
1615 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001616}
1617
1618/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001619 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001620 * @adapter: board private structure
1621 *
1622 * Configure the Tx unit of the MAC after a reset.
1623 **/
1624static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1625{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001626 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001627 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001628 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001629
1630 /* Setup the HW Tx Head and Tail descriptor pointers */
1631 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001632 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1633 j = ring->reg_idx;
1634 tdba = ring->dma;
1635 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001636 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001637 (tdba & DMA_32BIT_MASK));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001638 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1639 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1640 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1641 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1642 adapter->tx_ring[i].head = IXGBE_TDH(j);
1643 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1644 /* Disable Tx Head Writeback RO bit, since this hoses
1645 * bookkeeping if things aren't delivered in order.
1646 */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001647 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001648 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001649 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001650 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001651 if (hw->mac.type == ixgbe_mac_82599EB) {
1652 /* We enable 8 traffic classes, DCB only */
1653 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1654 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1655 IXGBE_MTQC_8TC_8TQ));
1656 }
Auke Kok9a799d72007-09-15 14:07:45 -07001657}
1658
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001659#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07001660
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001661static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1662{
1663 struct ixgbe_ring *rx_ring;
1664 u32 srrctl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001665 int queue0 = 0;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001666 unsigned long mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001667
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001668 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1669 queue0 = index;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001670 } else {
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001671 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1672 queue0 = index & mask;
1673 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001674 }
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001675
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001676 rx_ring = &adapter->rx_ring[queue0];
1677
1678 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1679
1680 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1681 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1682
1683 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg32344a32009-02-24 16:37:31 -08001684 u16 bufsz = IXGBE_RXBUFFER_2048;
1685 /* grow the amount we can receive on large page machines */
1686 if (bufsz < (PAGE_SIZE / 2))
1687 bufsz = (PAGE_SIZE / 2);
1688 /* cap the bufsz at our largest descriptor size */
1689 bufsz = min((u16)IXGBE_MAX_RXBUFFER, bufsz);
1690
1691 srrctl |= bufsz >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001692 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1693 srrctl |= ((IXGBE_RX_HDR_SIZE <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001694 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1695 IXGBE_SRRCTL_BSIZEHDR_MASK);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001696 } else {
1697 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1698
1699 if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1700 srrctl |= IXGBE_RXBUFFER_2048 >>
1701 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1702 else
1703 srrctl |= rx_ring->rx_buf_len >>
1704 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1705 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001706
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001707 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1708}
1709
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001710/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001711 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001712 * @adapter: board private structure
1713 *
1714 * Configure the Rx unit of the MAC after a reset.
1715 **/
1716static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1717{
1718 u64 rdba;
1719 struct ixgbe_hw *hw = &adapter->hw;
1720 struct net_device *netdev = adapter->netdev;
1721 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001722 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001723 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001724 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1725 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1726 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001727 u32 fctrl, hlreg0;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001728 u32 reta = 0, mrqc = 0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001729 u32 rdrxctl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001730 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07001731
1732 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001733 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07001734
1735 /* Set the RX buffer length according to the mode */
1736 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001737 rx_buf_len = IXGBE_RX_HDR_SIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001738 if (hw->mac.type == ixgbe_mac_82599EB) {
1739 /* PSRTYPE must be initialized in 82599 */
1740 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
1741 IXGBE_PSRTYPE_UDPHDR |
1742 IXGBE_PSRTYPE_IPV4HDR |
1743 IXGBE_PSRTYPE_IPV6HDR;
1744 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
1745 }
Auke Kok9a799d72007-09-15 14:07:45 -07001746 } else {
1747 if (netdev->mtu <= ETH_DATA_LEN)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001748 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001749 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001750 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07001751 }
1752
1753 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1754 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001755 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001756 fctrl |= IXGBE_FCTRL_PMCF;
Auke Kok9a799d72007-09-15 14:07:45 -07001757 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1758
1759 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1760 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1761 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1762 else
1763 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1764 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1765
Auke Kok9a799d72007-09-15 14:07:45 -07001766 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1767 /* disable receives while setting up the descriptors */
1768 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1769 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1770
1771 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1772 * the Base and Length of the Rx Descriptor Ring */
1773 for (i = 0; i < adapter->num_rx_queues; i++) {
1774 rdba = adapter->rx_ring[i].dma;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001775 j = adapter->rx_ring[i].reg_idx;
1776 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_32BIT_MASK));
1777 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
1778 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
1779 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
1780 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
1781 adapter->rx_ring[i].head = IXGBE_RDH(j);
1782 adapter->rx_ring[i].tail = IXGBE_RDT(j);
1783 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001784
1785 ixgbe_configure_srrctl(adapter, j);
Auke Kok9a799d72007-09-15 14:07:45 -07001786 }
1787
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001788 if (hw->mac.type == ixgbe_mac_82598EB) {
1789 /*
1790 * For VMDq support of different descriptor types or
1791 * buffer sizes through the use of multiple SRRCTL
1792 * registers, RDRXCTL.MVMEN must be set to 1
1793 *
1794 * also, the manual doesn't mention it clearly but DCA hints
1795 * will only use queue 0's tags unless this bit is set. Side
1796 * effects of setting this bit are only that SRRCTL must be
1797 * fully programmed [0..15]
1798 */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001799 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1800 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
1801 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
Alexander Duyck2f90b862008-11-20 20:52:10 -08001802 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001803
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001804 /* Program MRQC for the distribution of queues */
1805 if (hw->mac.type == ixgbe_mac_82599EB) {
1806 int mask = adapter->flags & (
1807 IXGBE_FLAG_RSS_ENABLED
1808 | IXGBE_FLAG_DCB_ENABLED
1809 );
1810
1811 switch (mask) {
1812 case (IXGBE_FLAG_RSS_ENABLED):
1813 mrqc = IXGBE_MRQC_RSSEN;
1814 break;
1815 case (IXGBE_FLAG_DCB_ENABLED):
1816 mrqc = IXGBE_MRQC_RT8TCEN;
1817 break;
1818 default:
1819 break;
1820 }
1821 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001822 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07001823 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001824 for (i = 0, j = 0; i < 128; i++, j++) {
1825 if (j == adapter->ring_feature[RING_F_RSS].indices)
1826 j = 0;
1827 /* reta = 4-byte sliding window of
1828 * 0x00..(indices-1)(indices-1)00..etc. */
1829 reta = (reta << 8) | (j * 0x11);
1830 if ((i & 3) == 3)
1831 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07001832 }
1833
1834 /* Fill out hash function seeds */
1835 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001836 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07001837
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001838 if (hw->mac.type == ixgbe_mac_82598EB)
1839 mrqc |= IXGBE_MRQC_RSSEN;
Auke Kok9a799d72007-09-15 14:07:45 -07001840 /* Perform hash on these packet types */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001841 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
1842 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1843 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1844 | IXGBE_MRQC_RSS_FIELD_IPV6
1845 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1846 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07001847 }
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001848 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001849
1850 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1851
1852 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
1853 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
1854 /* Disable indicating checksum in descriptor, enables
1855 * RSS hash */
1856 rxcsum |= IXGBE_RXCSUM_PCSD;
1857 }
1858 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
1859 /* Enable IPv4 payload checksum for UDP fragments
1860 * if PCSD is not set */
1861 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1862 }
1863
1864 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001865
1866 if (hw->mac.type == ixgbe_mac_82599EB) {
1867 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1868 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
1869 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
1870 }
Auke Kok9a799d72007-09-15 14:07:45 -07001871}
1872
Auke Kok9a799d72007-09-15 14:07:45 -07001873static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1874{
1875 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001876 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001877
1878 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001879 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07001880}
1881
1882static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1883{
1884 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001885 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001886
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001887 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1888 ixgbe_irq_disable(adapter);
1889
Auke Kok9a799d72007-09-15 14:07:45 -07001890 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001891
1892 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1893 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001894
1895 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001896 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07001897}
1898
Don Skidmore068c89b2009-01-19 16:54:36 -08001899static void ixgbe_vlan_rx_register(struct net_device *netdev,
1900 struct vlan_group *grp)
1901{
1902 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1903 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001904 int i, j;
Don Skidmore068c89b2009-01-19 16:54:36 -08001905
1906 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1907 ixgbe_irq_disable(adapter);
1908 adapter->vlgrp = grp;
1909
1910 /*
1911 * For a DCB driver, always enable VLAN tag stripping so we can
1912 * still receive traffic from a DCB-enabled host even if we're
1913 * not in DCB mode.
1914 */
1915 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001916 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1917 ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
Don Skidmore068c89b2009-01-19 16:54:36 -08001918 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1919 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001920 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1921 ctrl |= IXGBE_VLNCTRL_VFE;
1922 /* enable VLAN tag insert/strip */
1923 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1924 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1925 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1926 for (i = 0; i < adapter->num_rx_queues; i++) {
1927 j = adapter->rx_ring[i].reg_idx;
1928 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
1929 ctrl |= IXGBE_RXDCTL_VME;
1930 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
1931 }
Don Skidmore068c89b2009-01-19 16:54:36 -08001932 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001933 ixgbe_vlan_rx_add_vid(netdev, 0);
Don Skidmore068c89b2009-01-19 16:54:36 -08001934
1935 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1936 ixgbe_irq_enable(adapter);
1937}
1938
Auke Kok9a799d72007-09-15 14:07:45 -07001939static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
1940{
1941 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1942
1943 if (adapter->vlgrp) {
1944 u16 vid;
1945 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1946 if (!vlan_group_get_device(adapter->vlgrp, vid))
1947 continue;
1948 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
1949 }
1950 }
1951}
1952
Christopher Leech2c5645c2008-08-26 04:27:02 -07001953static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
1954{
1955 struct dev_mc_list *mc_ptr;
1956 u8 *addr = *mc_addr_ptr;
1957 *vmdq = 0;
1958
1959 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
1960 if (mc_ptr->next)
1961 *mc_addr_ptr = mc_ptr->next->dmi_addr;
1962 else
1963 *mc_addr_ptr = NULL;
1964
1965 return addr;
1966}
1967
Auke Kok9a799d72007-09-15 14:07:45 -07001968/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07001969 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07001970 * @netdev: network interface device structure
1971 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07001972 * The set_rx_method entry point is called whenever the unicast/multicast
1973 * address list or the network interface flags are updated. This routine is
1974 * responsible for configuring the hardware for proper unicast, multicast and
1975 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07001976 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07001977static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001978{
1979 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1980 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07001981 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001982 u8 *addr_list = NULL;
1983 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001984
1985 /* Check for Promiscuous and All Multicast modes */
1986
1987 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07001988 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07001989
1990 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07001991 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001992 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07001993 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07001994 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07001995 if (netdev->flags & IFF_ALLMULTI) {
1996 fctrl |= IXGBE_FCTRL_MPE;
1997 fctrl &= ~IXGBE_FCTRL_UPE;
1998 } else {
1999 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2000 }
Alexander Duyck3d016252008-08-26 18:30:04 -07002001 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002002 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002003 }
2004
2005 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07002006 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07002007
Christopher Leech2c5645c2008-08-26 04:27:02 -07002008 /* reprogram secondary unicast list */
2009 addr_count = netdev->uc_count;
2010 if (addr_count)
2011 addr_list = netdev->uc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002012 hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count,
2013 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002014
Christopher Leech2c5645c2008-08-26 04:27:02 -07002015 /* reprogram multicast list */
2016 addr_count = netdev->mc_count;
2017 if (addr_count)
2018 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002019 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2020 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002021}
2022
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002023static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2024{
2025 int q_idx;
2026 struct ixgbe_q_vector *q_vector;
2027 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2028
2029 /* legacy and MSI only use one vector */
2030 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2031 q_vectors = 1;
2032
2033 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002034 struct napi_struct *napi;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002035 q_vector = &adapter->q_vector[q_idx];
2036 if (!q_vector->rxr_count)
2037 continue;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002038 napi = &q_vector->napi;
2039 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) &&
2040 (q_vector->rxr_count > 1))
2041 napi->poll = &ixgbe_clean_rxonly_many;
2042
2043 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002044 }
2045}
2046
2047static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2048{
2049 int q_idx;
2050 struct ixgbe_q_vector *q_vector;
2051 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2052
2053 /* legacy and MSI only use one vector */
2054 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2055 q_vectors = 1;
2056
2057 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
2058 q_vector = &adapter->q_vector[q_idx];
2059 if (!q_vector->rxr_count)
2060 continue;
2061 napi_disable(&q_vector->napi);
2062 }
2063}
2064
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002065#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002066/*
2067 * ixgbe_configure_dcb - Configure DCB hardware
2068 * @adapter: ixgbe adapter struct
2069 *
2070 * This is called by the driver on open to configure the DCB hardware.
2071 * This is also called by the gennetlink interface when reconfiguring
2072 * the DCB state.
2073 */
2074static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2075{
2076 struct ixgbe_hw *hw = &adapter->hw;
2077 u32 txdctl, vlnctrl;
2078 int i, j;
2079
2080 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2081 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2082 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2083
2084 /* reconfigure the hardware */
2085 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2086
2087 for (i = 0; i < adapter->num_tx_queues; i++) {
2088 j = adapter->tx_ring[i].reg_idx;
2089 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2090 /* PThresh workaround for Tx hang with DFP enabled. */
2091 txdctl |= 32;
2092 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2093 }
2094 /* Enable VLAN tag insert/strip */
2095 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002096 if (hw->mac.type == ixgbe_mac_82598EB) {
2097 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2098 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2099 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2100 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2101 vlnctrl |= IXGBE_VLNCTRL_VFE;
2102 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2103 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2104 for (i = 0; i < adapter->num_rx_queues; i++) {
2105 j = adapter->rx_ring[i].reg_idx;
2106 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2107 vlnctrl |= IXGBE_RXDCTL_VME;
2108 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2109 }
2110 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08002111 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2112}
2113
2114#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002115static void ixgbe_configure(struct ixgbe_adapter *adapter)
2116{
2117 struct net_device *netdev = adapter->netdev;
2118 int i;
2119
Christopher Leech2c5645c2008-08-26 04:27:02 -07002120 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002121
2122 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002123#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002124 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2125 netif_set_gso_max_size(netdev, 32768);
2126 ixgbe_configure_dcb(adapter);
2127 } else {
2128 netif_set_gso_max_size(netdev, 65536);
2129 }
2130#else
2131 netif_set_gso_max_size(netdev, 65536);
2132#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002133
2134 ixgbe_configure_tx(adapter);
2135 ixgbe_configure_rx(adapter);
2136 for (i = 0; i < adapter->num_rx_queues; i++)
2137 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002138 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07002139}
2140
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002141static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2142{
2143 switch (hw->phy.type) {
2144 case ixgbe_phy_sfp_avago:
2145 case ixgbe_phy_sfp_ftl:
2146 case ixgbe_phy_sfp_intel:
2147 case ixgbe_phy_sfp_unknown:
2148 case ixgbe_phy_tw_tyco:
2149 case ixgbe_phy_tw_unknown:
2150 return true;
2151 default:
2152 return false;
2153 }
2154}
2155
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002156/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002157 * ixgbe_sfp_link_config - set up SFP+ link
2158 * @adapter: pointer to private adapter struct
2159 **/
2160static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2161{
2162 struct ixgbe_hw *hw = &adapter->hw;
2163
2164 if (hw->phy.multispeed_fiber) {
2165 /*
2166 * In multispeed fiber setups, the device may not have
2167 * had a physical connection when the driver loaded.
2168 * If that's the case, the initial link configuration
2169 * couldn't get the MAC into 10G or 1G mode, so we'll
2170 * never have a link status change interrupt fire.
2171 * We need to try and force an autonegotiation
2172 * session, then bring up link.
2173 */
2174 hw->mac.ops.setup_sfp(hw);
2175 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2176 schedule_work(&adapter->multispeed_fiber_task);
2177 } else {
2178 /*
2179 * Direct Attach Cu and non-multispeed fiber modules
2180 * still need to be configured properly prior to
2181 * attempting link.
2182 */
2183 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2184 schedule_work(&adapter->sfp_config_module_task);
2185 }
2186}
2187
2188/**
2189 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002190 * @hw: pointer to private hardware struct
2191 *
2192 * Returns 0 on success, negative on failure
2193 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002194static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002195{
2196 u32 autoneg;
2197 bool link_up = false;
2198 u32 ret = IXGBE_ERR_LINK_SETUP;
2199
2200 if (hw->mac.ops.check_link)
2201 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2202
2203 if (ret)
2204 goto link_cfg_out;
2205
2206 if (hw->mac.ops.get_link_capabilities)
2207 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
2208 &hw->mac.autoneg);
2209 if (ret)
2210 goto link_cfg_out;
2211
2212 if (hw->mac.ops.setup_link_speed)
2213 ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002214link_cfg_out:
2215 return ret;
2216}
2217
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002218#define IXGBE_MAX_RX_DESC_POLL 10
2219static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2220 int rxr)
2221{
2222 int j = adapter->rx_ring[rxr].reg_idx;
2223 int k;
2224
2225 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2226 if (IXGBE_READ_REG(&adapter->hw,
2227 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2228 break;
2229 else
2230 msleep(1);
2231 }
2232 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2233 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2234 "not set within the polling period\n", rxr);
2235 }
2236 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2237 (adapter->rx_ring[rxr].count - 1));
2238}
2239
Auke Kok9a799d72007-09-15 14:07:45 -07002240static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2241{
2242 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07002243 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002244 int i, j = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002245 int num_rx_rings = adapter->num_rx_queues;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002246 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002247 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002248 u32 txdctl, rxdctl, mhadd;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002249 u32 dmatxctl;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002250 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002251
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002252 ixgbe_get_hw_control(adapter);
2253
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002254 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2255 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002256 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2257 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002258 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002259 } else {
2260 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002261 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002262 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002263 /* XXX: to interrupt immediately for EICS writes, enable this */
2264 /* gpie |= IXGBE_GPIE_EIMEN; */
2265 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2266 }
2267
2268 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2269 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2270 * specifically only auto mask tx and rx interrupts */
2271 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002272 }
2273
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002274 /* Enable fan failure interrupt if media type is copper */
2275 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2276 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2277 gpie |= IXGBE_SDP1_GPIEN;
2278 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2279 }
2280
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002281 if (hw->mac.type == ixgbe_mac_82599EB) {
2282 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2283 gpie |= IXGBE_SDP1_GPIEN;
2284 gpie |= IXGBE_SDP2_GPIEN;
2285 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2286 }
2287
Auke Kok9a799d72007-09-15 14:07:45 -07002288 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002289 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2290 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2291 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2292
2293 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2294 }
2295
2296 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002297 j = adapter->tx_ring[i].reg_idx;
2298 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002299 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2300 txdctl |= (8 << 16);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002301 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2302 }
2303
2304 if (hw->mac.type == ixgbe_mac_82599EB) {
2305 /* DMATXCTL.EN must be set after all Tx queue config is done */
2306 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2307 dmatxctl |= IXGBE_DMATXCTL_TE;
2308 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2309 }
2310 for (i = 0; i < adapter->num_tx_queues; i++) {
2311 j = adapter->tx_ring[i].reg_idx;
2312 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Auke Kok9a799d72007-09-15 14:07:45 -07002313 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002314 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002315 }
2316
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002317 for (i = 0; i < num_rx_rings; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002318 j = adapter->rx_ring[i].reg_idx;
2319 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2320 /* enable PTHRESH=32 descriptors (half the internal cache)
2321 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2322 * this also removes a pesky rx_no_buffer_count increment */
2323 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002324 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002325 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002326 if (hw->mac.type == ixgbe_mac_82599EB)
2327 ixgbe_rx_desc_queue_enable(adapter, i);
Auke Kok9a799d72007-09-15 14:07:45 -07002328 }
2329 /* enable all receives */
2330 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002331 if (hw->mac.type == ixgbe_mac_82598EB)
2332 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2333 else
2334 rxdctl |= IXGBE_RXCTRL_RXEN;
2335 hw->mac.ops.enable_rx_dma(hw, rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002336
2337 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2338 ixgbe_configure_msix(adapter);
2339 else
2340 ixgbe_configure_msi_and_legacy(adapter);
2341
2342 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002343 ixgbe_napi_enable_all(adapter);
2344
2345 /* clear any pending interrupts, may auto mask */
2346 IXGBE_READ_REG(hw, IXGBE_EICR);
2347
Auke Kok9a799d72007-09-15 14:07:45 -07002348 ixgbe_irq_enable(adapter);
2349
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002350 /*
2351 * For hot-pluggable SFP+ devices, a new SFP+ module may have
2352 * arrived before interrupts were enabled. We need to kick off
2353 * the SFP+ module setup first, then try to bring up link.
2354 * If we're not hot-pluggable SFP+, we just need to configure link
2355 * and bring it up.
2356 */
2357 err = hw->phy.ops.identify(hw);
2358 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2359 DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err);
2360 ixgbe_down(adapter);
2361 return err;
2362 }
2363
2364 if (ixgbe_is_sfp(hw)) {
2365 ixgbe_sfp_link_config(adapter);
2366 } else {
2367 err = ixgbe_non_sfp_link_config(hw);
2368 if (err)
2369 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2370 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002371
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002372 /* enable transmits */
2373 netif_tx_start_all_queues(netdev);
2374
Auke Kok9a799d72007-09-15 14:07:45 -07002375 /* bring the link up in the watchdog, this could race with our first
2376 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002377 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2378 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002379 mod_timer(&adapter->watchdog_timer, jiffies);
2380 return 0;
2381}
2382
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002383void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2384{
2385 WARN_ON(in_interrupt());
2386 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2387 msleep(1);
2388 ixgbe_down(adapter);
2389 ixgbe_up(adapter);
2390 clear_bit(__IXGBE_RESETTING, &adapter->state);
2391}
2392
Auke Kok9a799d72007-09-15 14:07:45 -07002393int ixgbe_up(struct ixgbe_adapter *adapter)
2394{
2395 /* hardware has been reset, we need to reload some things */
2396 ixgbe_configure(adapter);
2397
Jesse Brandeburg4dd64df2009-03-13 22:13:49 +00002398 ixgbe_napi_add_all(adapter);
2399
Auke Kok9a799d72007-09-15 14:07:45 -07002400 return ixgbe_up_complete(adapter);
2401}
2402
2403void ixgbe_reset(struct ixgbe_adapter *adapter)
2404{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002405 struct ixgbe_hw *hw = &adapter->hw;
2406 if (hw->mac.ops.init_hw(hw))
2407 dev_err(&adapter->pdev->dev, "Hardware Error\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002408
2409 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002410 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002411
2412}
2413
Auke Kok9a799d72007-09-15 14:07:45 -07002414/**
2415 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2416 * @adapter: board private structure
2417 * @rx_ring: ring to free buffers from
2418 **/
2419static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002420 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002421{
2422 struct pci_dev *pdev = adapter->pdev;
2423 unsigned long size;
2424 unsigned int i;
2425
2426 /* Free all the Rx ring sk_buffs */
2427
2428 for (i = 0; i < rx_ring->count; i++) {
2429 struct ixgbe_rx_buffer *rx_buffer_info;
2430
2431 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2432 if (rx_buffer_info->dma) {
2433 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002434 rx_ring->rx_buf_len,
2435 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002436 rx_buffer_info->dma = 0;
2437 }
2438 if (rx_buffer_info->skb) {
2439 dev_kfree_skb(rx_buffer_info->skb);
2440 rx_buffer_info->skb = NULL;
2441 }
2442 if (!rx_buffer_info->page)
2443 continue;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002444 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2445 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002446 rx_buffer_info->page_dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002447 put_page(rx_buffer_info->page);
2448 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002449 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002450 }
2451
2452 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2453 memset(rx_ring->rx_buffer_info, 0, size);
2454
2455 /* Zero out the descriptor ring */
2456 memset(rx_ring->desc, 0, rx_ring->size);
2457
2458 rx_ring->next_to_clean = 0;
2459 rx_ring->next_to_use = 0;
2460
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002461 if (rx_ring->head)
2462 writel(0, adapter->hw.hw_addr + rx_ring->head);
2463 if (rx_ring->tail)
2464 writel(0, adapter->hw.hw_addr + rx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002465}
2466
2467/**
2468 * ixgbe_clean_tx_ring - Free Tx Buffers
2469 * @adapter: board private structure
2470 * @tx_ring: ring to be cleaned
2471 **/
2472static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002473 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002474{
2475 struct ixgbe_tx_buffer *tx_buffer_info;
2476 unsigned long size;
2477 unsigned int i;
2478
2479 /* Free all the Tx ring sk_buffs */
2480
2481 for (i = 0; i < tx_ring->count; i++) {
2482 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2483 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2484 }
2485
2486 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2487 memset(tx_ring->tx_buffer_info, 0, size);
2488
2489 /* Zero out the descriptor ring */
2490 memset(tx_ring->desc, 0, tx_ring->size);
2491
2492 tx_ring->next_to_use = 0;
2493 tx_ring->next_to_clean = 0;
2494
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002495 if (tx_ring->head)
2496 writel(0, adapter->hw.hw_addr + tx_ring->head);
2497 if (tx_ring->tail)
2498 writel(0, adapter->hw.hw_addr + tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002499}
2500
2501/**
Auke Kok9a799d72007-09-15 14:07:45 -07002502 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2503 * @adapter: board private structure
2504 **/
2505static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2506{
2507 int i;
2508
2509 for (i = 0; i < adapter->num_rx_queues; i++)
2510 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2511}
2512
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002513/**
2514 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2515 * @adapter: board private structure
2516 **/
2517static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2518{
2519 int i;
2520
2521 for (i = 0; i < adapter->num_tx_queues; i++)
2522 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2523}
2524
Auke Kok9a799d72007-09-15 14:07:45 -07002525void ixgbe_down(struct ixgbe_adapter *adapter)
2526{
2527 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002528 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002529 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002530 u32 txdctl;
2531 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002532
2533 /* signal that we are down to the interrupt handler */
2534 set_bit(__IXGBE_DOWN, &adapter->state);
2535
2536 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002537 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2538 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002539
2540 netif_tx_disable(netdev);
2541
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002542 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002543 msleep(10);
2544
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002545 netif_tx_stop_all_queues(netdev);
2546
Auke Kok9a799d72007-09-15 14:07:45 -07002547 ixgbe_irq_disable(adapter);
2548
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002549 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002550
Auke Kok9a799d72007-09-15 14:07:45 -07002551 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002552 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002553
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002554 /* disable transmits in the hardware now that interrupts are off */
2555 for (i = 0; i < adapter->num_tx_queues; i++) {
2556 j = adapter->tx_ring[i].reg_idx;
2557 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2558 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2559 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2560 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00002561 /* Disable the Tx DMA engine on 82599 */
2562 if (hw->mac.type == ixgbe_mac_82599EB)
2563 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
2564 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
2565 ~IXGBE_DMATXCTL_TE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002566
Auke Kok9a799d72007-09-15 14:07:45 -07002567 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002568
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002569#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002570 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2571 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
2572 dca_remove_requester(&adapter->pdev->dev);
2573 }
2574
2575#endif
Paul Larson6f4a0e42008-06-24 17:00:56 -07002576 if (!pci_channel_offline(adapter->pdev))
2577 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002578 ixgbe_clean_all_tx_rings(adapter);
2579 ixgbe_clean_all_rx_rings(adapter);
2580
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002581#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002582 /* since we reset the hardware DCA settings were cleared */
2583 if (dca_add_requester(&adapter->pdev->dev) == 0) {
2584 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
2585 /* always use CB2 mode, difference is masked
2586 * in the CB driver */
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002587 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002588 ixgbe_setup_dca(adapter);
2589 }
2590#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002591}
2592
Auke Kok9a799d72007-09-15 14:07:45 -07002593/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002594 * ixgbe_poll - NAPI Rx polling callback
2595 * @napi: structure for representing this polling device
2596 * @budget: how many packets driver is allowed to clean
2597 *
2598 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002599 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002600static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002601{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002602 struct ixgbe_q_vector *q_vector =
2603 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002604 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002605 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002606
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002607#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002608 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2609 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2610 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2611 }
2612#endif
2613
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002614 tx_clean_complete = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002615 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002616
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00002617 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002618 work_done = budget;
2619
David S. Miller53e52c72008-01-07 21:06:12 -08002620 /* If budget not fully consumed, exit the polling mode */
2621 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002622 napi_complete(napi);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002623 if (adapter->itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002624 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002625 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2626 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002627 }
Auke Kok9a799d72007-09-15 14:07:45 -07002628 return work_done;
2629}
2630
2631/**
2632 * ixgbe_tx_timeout - Respond to a Tx Hang
2633 * @netdev: network interface device structure
2634 **/
2635static void ixgbe_tx_timeout(struct net_device *netdev)
2636{
2637 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2638
2639 /* Do the reset outside of interrupt context */
2640 schedule_work(&adapter->reset_task);
2641}
2642
2643static void ixgbe_reset_task(struct work_struct *work)
2644{
2645 struct ixgbe_adapter *adapter;
2646 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2647
Alexander Duyck2f90b862008-11-20 20:52:10 -08002648 /* If we're already down or resetting, just bail */
2649 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2650 test_bit(__IXGBE_RESETTING, &adapter->state))
2651 return;
2652
Auke Kok9a799d72007-09-15 14:07:45 -07002653 adapter->tx_timeout_count++;
2654
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002655 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002656}
2657
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002658#ifdef CONFIG_IXGBE_DCB
2659static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002660{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002661 bool ret = false;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002662
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002663 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2664 adapter->ring_feature[RING_F_DCB].mask = 0x7 << 3;
2665 adapter->num_rx_queues =
2666 adapter->ring_feature[RING_F_DCB].indices;
2667 adapter->num_tx_queues =
2668 adapter->ring_feature[RING_F_DCB].indices;
2669 ret = true;
2670 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002671 ret = false;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002672 }
2673
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002674 return ret;
2675}
2676#endif
2677
2678static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
2679{
2680 bool ret = false;
2681
2682 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2683 adapter->ring_feature[RING_F_RSS].mask = 0xF;
2684 adapter->num_rx_queues =
2685 adapter->ring_feature[RING_F_RSS].indices;
2686 adapter->num_tx_queues =
2687 adapter->ring_feature[RING_F_RSS].indices;
2688 ret = true;
2689 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002690 ret = false;
2691 }
2692
2693 return ret;
2694}
2695
2696static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2697{
2698 /* Start with base case */
2699 adapter->num_rx_queues = 1;
2700 adapter->num_tx_queues = 1;
2701
2702#ifdef CONFIG_IXGBE_DCB
2703 if (ixgbe_set_dcb_queues(adapter))
2704 return;
2705
2706#endif
2707 if (ixgbe_set_rss_queues(adapter))
2708 return;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002709}
2710
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002711static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002712 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002713{
2714 int err, vector_threshold;
2715
2716 /* We'll want at least 3 (vector_threshold):
2717 * 1) TxQ[0] Cleanup
2718 * 2) RxQ[0] Cleanup
2719 * 3) Other (Link Status Change, etc.)
2720 * 4) TCP Timer (optional)
2721 */
2722 vector_threshold = MIN_MSIX_COUNT;
2723
2724 /* The more we get, the more we will assign to Tx/Rx Cleanup
2725 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2726 * Right now, we simply care about how many we'll get; we'll
2727 * set them up later while requesting irq's.
2728 */
2729 while (vectors >= vector_threshold) {
2730 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002731 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002732 if (!err) /* Success in acquiring all requested vectors. */
2733 break;
2734 else if (err < 0)
2735 vectors = 0; /* Nasty failure, quit now */
2736 else /* err == number of vectors we should try again with */
2737 vectors = err;
2738 }
2739
2740 if (vectors < vector_threshold) {
2741 /* Can't allocate enough MSI-X interrupts? Oh well.
2742 * This just means we'll go with either a single MSI
2743 * vector or fall back to legacy interrupts.
2744 */
2745 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2746 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2747 kfree(adapter->msix_entries);
2748 adapter->msix_entries = NULL;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002749 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002750 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002751 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002752 } else {
2753 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08002754 /*
2755 * Adjust for only the vectors we'll use, which is minimum
2756 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
2757 * vectors we were allocated.
2758 */
2759 adapter->num_msix_vectors = min(vectors,
2760 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002761 }
2762}
2763
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002764/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002765 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002766 * @adapter: board private structure to initialize
2767 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002768 * Cache the descriptor ring offsets for RSS to the assigned rings.
2769 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002770 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002771static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002772{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002773 int i;
2774 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002775
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002776 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2777 for (i = 0; i < adapter->num_rx_queues; i++)
2778 adapter->rx_ring[i].reg_idx = i;
2779 for (i = 0; i < adapter->num_tx_queues; i++)
2780 adapter->tx_ring[i].reg_idx = i;
2781 ret = true;
2782 } else {
2783 ret = false;
2784 }
2785
2786 return ret;
2787}
2788
2789#ifdef CONFIG_IXGBE_DCB
2790/**
2791 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
2792 * @adapter: board private structure to initialize
2793 *
2794 * Cache the descriptor ring offsets for DCB to the assigned rings.
2795 *
2796 **/
2797static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
2798{
2799 int i;
2800 bool ret = false;
2801 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2802
2803 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2804 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002805 /* the number of queues is assumed to be symmetric */
2806 for (i = 0; i < dcb_i; i++) {
2807 adapter->rx_ring[i].reg_idx = i << 3;
2808 adapter->tx_ring[i].reg_idx = i << 2;
2809 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002810 ret = true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002811 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
2812 for (i = 0; i < dcb_i; i++) {
2813 adapter->rx_ring[i].reg_idx = i << 4;
2814 adapter->tx_ring[i].reg_idx = i << 4;
2815 }
2816 ret = true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002817 } else {
2818 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002819 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002820 } else {
2821 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002822 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002823
2824 return ret;
2825}
2826#endif
2827
2828/**
2829 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2830 * @adapter: board private structure to initialize
2831 *
2832 * Once we know the feature-set enabled for the device, we'll cache
2833 * the register offset the descriptor ring is assigned to.
2834 *
2835 * Note, the order the various feature calls is important. It must start with
2836 * the "most" features enabled at the same time, then trickle down to the
2837 * least amount of features turned on at once.
2838 **/
2839static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
2840{
2841 /* start with default case */
2842 adapter->rx_ring[0].reg_idx = 0;
2843 adapter->tx_ring[0].reg_idx = 0;
2844
2845#ifdef CONFIG_IXGBE_DCB
2846 if (ixgbe_cache_ring_dcb(adapter))
2847 return;
2848
2849#endif
2850 if (ixgbe_cache_ring_rss(adapter))
2851 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002852}
2853
Auke Kok9a799d72007-09-15 14:07:45 -07002854/**
2855 * ixgbe_alloc_queues - Allocate memory for all rings
2856 * @adapter: board private structure to initialize
2857 *
2858 * We allocate one ring per queue at run-time since we don't know the
Wang Chena4d2f342008-12-03 22:05:58 -08002859 * number of queues at compile-time.
Auke Kok9a799d72007-09-15 14:07:45 -07002860 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002861static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002862{
2863 int i;
2864
2865 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002866 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07002867 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002868 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07002869
2870 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002871 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002872 if (!adapter->rx_ring)
2873 goto err_rx_ring_allocation;
2874
2875 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002876 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002877 adapter->tx_ring[i].queue_index = i;
2878 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002879
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002880 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002881 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002882 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07002883 }
2884
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002885 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002886
2887 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002888
2889err_rx_ring_allocation:
2890 kfree(adapter->tx_ring);
2891err_tx_ring_allocation:
2892 return -ENOMEM;
2893}
2894
2895/**
2896 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
2897 * @adapter: board private structure to initialize
2898 *
2899 * Attempt to configure the interrupts using the best available
2900 * capabilities of the hardware and the kernel.
2901 **/
Al Virofeea6a52008-11-27 15:34:07 -08002902static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002903{
2904 int err = 0;
2905 int vector, v_budget;
2906
2907 /*
2908 * It's easy to be greedy for MSI-X vectors, but it really
2909 * doesn't do us much good if we have a lot more vectors
2910 * than CPU's. So let's be conservative and only ask for
2911 * (roughly) twice the number of vectors as there are CPU's.
2912 */
2913 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002914 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002915
2916 /*
2917 * At the same time, hardware can only support a maximum of
2918 * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq,
2919 * we can easily reach upwards of 64 Rx descriptor queues and
2920 * 32 Tx queues. Thus, we cap it off in those rare cases where
2921 * the cpu count also exceeds our vector limit.
2922 */
2923 v_budget = min(v_budget, MAX_MSIX_COUNT);
2924
2925 /* A failure in MSI-X entry allocation isn't fatal, but it does
2926 * mean we disable MSI-X capabilities of the adapter. */
2927 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002928 sizeof(struct msix_entry), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002929 if (!adapter->msix_entries) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002930 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002931 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2932 ixgbe_set_num_queues(adapter);
2933 kfree(adapter->tx_ring);
2934 kfree(adapter->rx_ring);
2935 err = ixgbe_alloc_queues(adapter);
2936 if (err) {
2937 DPRINTK(PROBE, ERR, "Unable to allocate memory "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002938 "for queues\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002939 goto out;
2940 }
2941
2942 goto try_msi;
2943 }
2944
2945 for (vector = 0; vector < v_budget; vector++)
2946 adapter->msix_entries[vector].entry = vector;
2947
2948 ixgbe_acquire_msix_vectors(adapter, v_budget);
2949
2950 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2951 goto out;
2952
2953try_msi:
2954 err = pci_enable_msi(adapter->pdev);
2955 if (!err) {
2956 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
2957 } else {
2958 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002959 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002960 /* reset err */
2961 err = 0;
2962 }
2963
2964out:
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08002965 /* Notify the stack of the (possibly) reduced Tx Queue count. */
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002966 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002967
2968 return err;
2969}
2970
Alexander Duyck2f90b862008-11-20 20:52:10 -08002971void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002972{
2973 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2974 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2975 pci_disable_msix(adapter->pdev);
2976 kfree(adapter->msix_entries);
2977 adapter->msix_entries = NULL;
2978 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2979 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
2980 pci_disable_msi(adapter->pdev);
2981 }
2982 return;
2983}
2984
2985/**
2986 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
2987 * @adapter: board private structure to initialize
2988 *
2989 * We determine which interrupt scheme to use based on...
2990 * - Kernel support (MSI, MSI-X)
2991 * - which can be user-defined (via MODULE_PARAM)
2992 * - Hardware queue count (num_*_queues)
2993 * - defined by miscellaneous hardware support/features (RSS, etc.)
2994 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002995int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002996{
2997 int err;
2998
2999 /* Number of supported queues */
3000 ixgbe_set_num_queues(adapter);
3001
3002 err = ixgbe_alloc_queues(adapter);
3003 if (err) {
3004 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3005 goto err_alloc_queues;
3006 }
3007
3008 err = ixgbe_set_interrupt_capability(adapter);
3009 if (err) {
3010 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3011 goto err_set_interrupt;
3012 }
3013
3014 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003015 "Tx Queue count = %u\n",
3016 (adapter->num_rx_queues > 1) ? "Enabled" :
3017 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003018
3019 set_bit(__IXGBE_DOWN, &adapter->state);
3020
3021 return 0;
3022
3023err_set_interrupt:
3024 kfree(adapter->tx_ring);
3025 kfree(adapter->rx_ring);
3026err_alloc_queues:
3027 return err;
Auke Kok9a799d72007-09-15 14:07:45 -07003028}
3029
3030/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08003031 * ixgbe_sfp_timer - worker thread to find a missing module
3032 * @data: pointer to our adapter struct
3033 **/
3034static void ixgbe_sfp_timer(unsigned long data)
3035{
3036 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3037
3038 /* Do the sfp_timer outside of interrupt context due to the
3039 * delays that sfp+ detection requires
3040 */
3041 schedule_work(&adapter->sfp_task);
3042}
3043
3044/**
3045 * ixgbe_sfp_task - worker thread to find a missing module
3046 * @work: pointer to work_struct containing our data
3047 **/
3048static void ixgbe_sfp_task(struct work_struct *work)
3049{
3050 struct ixgbe_adapter *adapter = container_of(work,
3051 struct ixgbe_adapter,
3052 sfp_task);
3053 struct ixgbe_hw *hw = &adapter->hw;
3054
3055 if ((hw->phy.type == ixgbe_phy_nl) &&
3056 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3057 s32 ret = hw->phy.ops.identify_sfp(hw);
3058 if (ret)
3059 goto reschedule;
3060 ret = hw->phy.ops.reset(hw);
3061 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
3062 DPRINTK(PROBE, ERR, "failed to initialize because an "
3063 "unsupported SFP+ module type was detected.\n"
3064 "Reload the driver after installing a "
3065 "supported module.\n");
3066 unregister_netdev(adapter->netdev);
3067 } else {
3068 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3069 hw->phy.sfp_type);
3070 }
3071 /* don't need this routine any more */
3072 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3073 }
3074 return;
3075reschedule:
3076 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3077 mod_timer(&adapter->sfp_timer,
3078 round_jiffies(jiffies + (2 * HZ)));
3079}
3080
3081/**
Auke Kok9a799d72007-09-15 14:07:45 -07003082 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3083 * @adapter: board private structure to initialize
3084 *
3085 * ixgbe_sw_init initializes the Adapter private data structure.
3086 * Fields are initialized based on PCI device information and
3087 * OS network device settings (MTU size).
3088 **/
3089static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3090{
3091 struct ixgbe_hw *hw = &adapter->hw;
3092 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003093 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003094#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003095 int j;
3096 struct tc_configuration *tc;
3097#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003098
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003099 /* PCI config space info */
3100
3101 hw->vendor_id = pdev->vendor;
3102 hw->device_id = pdev->device;
3103 hw->revision_id = pdev->revision;
3104 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3105 hw->subsystem_device_id = pdev->subsystem_device;
3106
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003107 /* Set capability flags */
3108 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3109 adapter->ring_feature[RING_F_RSS].indices = rss;
3110 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003111 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003112 if (hw->mac.type == ixgbe_mac_82598EB)
3113 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
3114 else if (hw->mac.type == ixgbe_mac_82599EB)
3115 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003116
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003117#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003118 /* Configure DCB traffic classes */
3119 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3120 tc = &adapter->dcb_cfg.tc_config[j];
3121 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3122 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3123 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3124 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3125 tc->dcb_pfc = pfc_disabled;
3126 }
3127 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3128 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3129 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
3130 adapter->dcb_cfg.round_robin_enable = false;
3131 adapter->dcb_set_bitmap = 0x00;
3132 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3133 adapter->ring_feature[RING_F_DCB].indices);
3134
3135#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003136
3137 /* default flow control settings */
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003138 hw->fc.requested_mode = ixgbe_fc_none;
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07003139 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3140 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3141 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3142 hw->fc.send_xon = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003143
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07003144 /* enable itr by default in dynamic mode */
3145 adapter->itr_setting = 1;
3146 adapter->eitr_param = 20000;
3147
3148 /* set defaults for eitr in MegaBytes */
3149 adapter->eitr_low = 10;
3150 adapter->eitr_high = 20;
3151
3152 /* set default ring sizes */
3153 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
3154 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
3155
Auke Kok9a799d72007-09-15 14:07:45 -07003156 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003157 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003158 dev_err(&pdev->dev, "EEPROM initialization failed\n");
3159 return -EIO;
3160 }
3161
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003162 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07003163 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
3164
Auke Kok9a799d72007-09-15 14:07:45 -07003165 set_bit(__IXGBE_DOWN, &adapter->state);
3166
3167 return 0;
3168}
3169
3170/**
3171 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
3172 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003173 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003174 *
3175 * Return 0 on success, negative on failure
3176 **/
3177int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003178 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003179{
3180 struct pci_dev *pdev = adapter->pdev;
3181 int size;
3182
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003183 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3184 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003185 if (!tx_ring->tx_buffer_info)
3186 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003187 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003188
3189 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08003190 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003191 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003192
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003193 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
3194 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003195 if (!tx_ring->desc)
3196 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07003197
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003198 tx_ring->next_to_use = 0;
3199 tx_ring->next_to_clean = 0;
3200 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07003201 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07003202
3203err:
3204 vfree(tx_ring->tx_buffer_info);
3205 tx_ring->tx_buffer_info = NULL;
3206 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
3207 "descriptor ring\n");
3208 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003209}
3210
3211/**
Alexander Duyck69888672008-09-11 20:05:39 -07003212 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
3213 * @adapter: board private structure
3214 *
3215 * If this function returns with an error, then it's possible one or
3216 * more of the rings is populated (while the rest are not). It is the
3217 * callers duty to clean those orphaned rings.
3218 *
3219 * Return 0 on success, negative on failure
3220 **/
3221static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
3222{
3223 int i, err = 0;
3224
3225 for (i = 0; i < adapter->num_tx_queues; i++) {
3226 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
3227 if (!err)
3228 continue;
3229 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
3230 break;
3231 }
3232
3233 return err;
3234}
3235
3236/**
Auke Kok9a799d72007-09-15 14:07:45 -07003237 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
3238 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003239 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07003240 *
3241 * Returns 0 on success, negative on failure
3242 **/
3243int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003244 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003245{
3246 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003247 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07003248
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003249 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
3250 rx_ring->rx_buffer_info = vmalloc(size);
3251 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07003252 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003253 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003254 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003255 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003256 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07003257
Auke Kok9a799d72007-09-15 14:07:45 -07003258 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003259 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
3260 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07003261
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003262 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07003263
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003264 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07003265 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003266 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003267 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003268 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07003269 }
3270
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003271 rx_ring->next_to_clean = 0;
3272 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003273
3274 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003275
3276alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003277 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07003278}
3279
3280/**
Alexander Duyck69888672008-09-11 20:05:39 -07003281 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
3282 * @adapter: board private structure
3283 *
3284 * If this function returns with an error, then it's possible one or
3285 * more of the rings is populated (while the rest are not). It is the
3286 * callers duty to clean those orphaned rings.
3287 *
3288 * Return 0 on success, negative on failure
3289 **/
3290
3291static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
3292{
3293 int i, err = 0;
3294
3295 for (i = 0; i < adapter->num_rx_queues; i++) {
3296 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
3297 if (!err)
3298 continue;
3299 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
3300 break;
3301 }
3302
3303 return err;
3304}
3305
3306/**
Auke Kok9a799d72007-09-15 14:07:45 -07003307 * ixgbe_free_tx_resources - Free Tx Resources per Queue
3308 * @adapter: board private structure
3309 * @tx_ring: Tx descriptor ring for a specific queue
3310 *
3311 * Free all transmit software resources
3312 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003313void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
3314 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003315{
3316 struct pci_dev *pdev = adapter->pdev;
3317
3318 ixgbe_clean_tx_ring(adapter, tx_ring);
3319
3320 vfree(tx_ring->tx_buffer_info);
3321 tx_ring->tx_buffer_info = NULL;
3322
3323 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
3324
3325 tx_ring->desc = NULL;
3326}
3327
3328/**
3329 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
3330 * @adapter: board private structure
3331 *
3332 * Free all transmit software resources
3333 **/
3334static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
3335{
3336 int i;
3337
3338 for (i = 0; i < adapter->num_tx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00003339 if (adapter->tx_ring[i].desc)
3340 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003341}
3342
3343/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003344 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07003345 * @adapter: board private structure
3346 * @rx_ring: ring to clean the resources from
3347 *
3348 * Free all receive software resources
3349 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003350void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
3351 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003352{
3353 struct pci_dev *pdev = adapter->pdev;
3354
3355 ixgbe_clean_rx_ring(adapter, rx_ring);
3356
3357 vfree(rx_ring->rx_buffer_info);
3358 rx_ring->rx_buffer_info = NULL;
3359
3360 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
3361
3362 rx_ring->desc = NULL;
3363}
3364
3365/**
3366 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
3367 * @adapter: board private structure
3368 *
3369 * Free all receive software resources
3370 **/
3371static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
3372{
3373 int i;
3374
3375 for (i = 0; i < adapter->num_rx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00003376 if (adapter->rx_ring[i].desc)
3377 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003378}
3379
3380/**
Auke Kok9a799d72007-09-15 14:07:45 -07003381 * ixgbe_change_mtu - Change the Maximum Transfer Unit
3382 * @netdev: network interface device structure
3383 * @new_mtu: new value for maximum frame size
3384 *
3385 * Returns 0 on success, negative on failure
3386 **/
3387static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
3388{
3389 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3390 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3391
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07003392 /* MTU < 68 is an error and causes problems on some kernels */
3393 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07003394 return -EINVAL;
3395
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003396 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003397 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003398 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07003399 netdev->mtu = new_mtu;
3400
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003401 if (netif_running(netdev))
3402 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003403
3404 return 0;
3405}
3406
3407/**
3408 * ixgbe_open - Called when a network interface is made active
3409 * @netdev: network interface device structure
3410 *
3411 * Returns 0 on success, negative value on failure
3412 *
3413 * The open entry point is called when a network interface is made
3414 * active by the system (IFF_UP). At this point all resources needed
3415 * for transmit and receive operations are allocated, the interrupt
3416 * handler is registered with the OS, the watchdog timer is started,
3417 * and the stack is notified that the interface is ready.
3418 **/
3419static int ixgbe_open(struct net_device *netdev)
3420{
3421 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3422 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003423
Auke Kok4bebfaa2008-02-11 09:26:01 -08003424 /* disallow open during test */
3425 if (test_bit(__IXGBE_TESTING, &adapter->state))
3426 return -EBUSY;
3427
Auke Kok9a799d72007-09-15 14:07:45 -07003428 /* allocate transmit descriptors */
3429 err = ixgbe_setup_all_tx_resources(adapter);
3430 if (err)
3431 goto err_setup_tx;
3432
Auke Kok9a799d72007-09-15 14:07:45 -07003433 /* allocate receive descriptors */
3434 err = ixgbe_setup_all_rx_resources(adapter);
3435 if (err)
3436 goto err_setup_rx;
3437
3438 ixgbe_configure(adapter);
3439
Jesse Brandeburg4dd64df2009-03-13 22:13:49 +00003440 ixgbe_napi_add_all(adapter);
3441
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003442 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003443 if (err)
3444 goto err_req_irq;
3445
Auke Kok9a799d72007-09-15 14:07:45 -07003446 err = ixgbe_up_complete(adapter);
3447 if (err)
3448 goto err_up;
3449
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003450 netif_tx_start_all_queues(netdev);
3451
Auke Kok9a799d72007-09-15 14:07:45 -07003452 return 0;
3453
3454err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003455 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003456 ixgbe_free_irq(adapter);
3457err_req_irq:
3458 ixgbe_free_all_rx_resources(adapter);
3459err_setup_rx:
3460 ixgbe_free_all_tx_resources(adapter);
3461err_setup_tx:
3462 ixgbe_reset(adapter);
3463
3464 return err;
3465}
3466
3467/**
3468 * ixgbe_close - Disables a network interface
3469 * @netdev: network interface device structure
3470 *
3471 * Returns 0, this is not allowed to fail
3472 *
3473 * The close entry point is called when an interface is de-activated
3474 * by the OS. The hardware is still under the drivers control, but
3475 * needs to be disabled. A global MAC reset is issued to stop the
3476 * hardware, and all transmit and receive resources are freed.
3477 **/
3478static int ixgbe_close(struct net_device *netdev)
3479{
3480 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003481
3482 ixgbe_down(adapter);
3483 ixgbe_free_irq(adapter);
3484
3485 ixgbe_free_all_tx_resources(adapter);
3486 ixgbe_free_all_rx_resources(adapter);
3487
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003488 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003489
3490 return 0;
3491}
3492
3493/**
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003494 * ixgbe_napi_add_all - prep napi structs for use
3495 * @adapter: private struct
Jesse Brandeburg4dd64df2009-03-13 22:13:49 +00003496 *
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003497 * helper function to napi_add each possible q_vector->napi
3498 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08003499void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003500{
3501 int q_idx, q_vectors;
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003502 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003503 int (*poll)(struct napi_struct *, int);
3504
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003505 /* check if we already have our netdev->napi_list populated */
3506 if (&netdev->napi_list != netdev->napi_list.next)
3507 return;
3508
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003509 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3510 poll = &ixgbe_clean_rxonly;
3511 /* Only enable as many vectors as we have rx queues. */
3512 q_vectors = adapter->num_rx_queues;
3513 } else {
3514 poll = &ixgbe_poll;
3515 /* only one q_vector for legacy modes */
3516 q_vectors = 1;
3517 }
3518
3519 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3520 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3521 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
3522 }
3523}
3524
Alexander Duyck2f90b862008-11-20 20:52:10 -08003525void ixgbe_napi_del_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003526{
3527 int q_idx;
3528 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3529
3530 /* legacy and MSI only use one vector */
3531 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3532 q_vectors = 1;
3533
3534 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3535 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3536 if (!q_vector->rxr_count)
3537 continue;
3538 netif_napi_del(&q_vector->napi);
3539 }
3540}
3541
3542#ifdef CONFIG_PM
3543static int ixgbe_resume(struct pci_dev *pdev)
3544{
3545 struct net_device *netdev = pci_get_drvdata(pdev);
3546 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3547 u32 err;
3548
3549 pci_set_power_state(pdev, PCI_D0);
3550 pci_restore_state(pdev);
3551 err = pci_enable_device(pdev);
3552 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07003553 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003554 "suspend\n");
3555 return err;
3556 }
3557 pci_set_master(pdev);
3558
3559 pci_enable_wake(pdev, PCI_D3hot, 0);
3560 pci_enable_wake(pdev, PCI_D3cold, 0);
3561
3562 err = ixgbe_init_interrupt_scheme(adapter);
3563 if (err) {
3564 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
3565 "device\n");
3566 return err;
3567 }
3568
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003569 ixgbe_reset(adapter);
3570
3571 if (netif_running(netdev)) {
3572 err = ixgbe_open(adapter->netdev);
3573 if (err)
3574 return err;
3575 }
3576
3577 netif_device_attach(netdev);
3578
3579 return 0;
3580}
3581
3582#endif /* CONFIG_PM */
3583static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
3584{
3585 struct net_device *netdev = pci_get_drvdata(pdev);
3586 struct ixgbe_adapter *adapter = netdev_priv(netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003587 struct ixgbe_hw *hw = &adapter->hw;
3588 u32 ctrl, fctrl;
3589 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003590#ifdef CONFIG_PM
3591 int retval = 0;
3592#endif
3593
3594 netif_device_detach(netdev);
3595
3596 if (netif_running(netdev)) {
3597 ixgbe_down(adapter);
3598 ixgbe_free_irq(adapter);
3599 ixgbe_free_all_tx_resources(adapter);
3600 ixgbe_free_all_rx_resources(adapter);
3601 }
3602 ixgbe_reset_interrupt_capability(adapter);
3603 ixgbe_napi_del_all(adapter);
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003604 INIT_LIST_HEAD(&netdev->napi_list);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003605 kfree(adapter->tx_ring);
3606 kfree(adapter->rx_ring);
3607
3608#ifdef CONFIG_PM
3609 retval = pci_save_state(pdev);
3610 if (retval)
3611 return retval;
3612#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003613 if (wufc) {
3614 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003615
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003616 /* turn on all-multi mode if wake on multicast is enabled */
3617 if (wufc & IXGBE_WUFC_MC) {
3618 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3619 fctrl |= IXGBE_FCTRL_MPE;
3620 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
3621 }
3622
3623 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
3624 ctrl |= IXGBE_CTRL_GIO_DIS;
3625 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
3626
3627 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
3628 } else {
3629 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
3630 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
3631 }
3632
3633 if (wufc && hw->mac.type == ixgbe_mac_82599EB) {
3634 pci_enable_wake(pdev, PCI_D3hot, 1);
3635 pci_enable_wake(pdev, PCI_D3cold, 1);
3636 } else {
3637 pci_enable_wake(pdev, PCI_D3hot, 0);
3638 pci_enable_wake(pdev, PCI_D3cold, 0);
3639 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003640
3641 ixgbe_release_hw_control(adapter);
3642
3643 pci_disable_device(pdev);
3644
3645 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3646
3647 return 0;
3648}
3649
3650static void ixgbe_shutdown(struct pci_dev *pdev)
3651{
3652 ixgbe_suspend(pdev, PMSG_SUSPEND);
3653}
3654
3655/**
Auke Kok9a799d72007-09-15 14:07:45 -07003656 * ixgbe_update_stats - Update the board statistics counters.
3657 * @adapter: board private structure
3658 **/
3659void ixgbe_update_stats(struct ixgbe_adapter *adapter)
3660{
3661 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003662 u64 total_mpc = 0;
3663 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003664
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00003665 if (hw->mac.type == ixgbe_mac_82599EB) {
3666 for (i = 0; i < 16; i++)
3667 adapter->hw_rx_no_dma_resources +=
3668 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
3669 }
3670
Auke Kok9a799d72007-09-15 14:07:45 -07003671 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003672 for (i = 0; i < 8; i++) {
3673 /* for packet buffers not used, the register should read 0 */
3674 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
3675 missed_rx += mpc;
3676 adapter->stats.mpc[i] += mpc;
3677 total_mpc += adapter->stats.mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003678 if (hw->mac.type == ixgbe_mac_82598EB)
3679 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08003680 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
3681 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
3682 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
3683 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003684 if (hw->mac.type == ixgbe_mac_82599EB) {
3685 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3686 IXGBE_PXONRXCNT(i));
3687 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3688 IXGBE_PXOFFRXCNT(i));
3689 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003690 } else {
3691 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3692 IXGBE_PXONRXC(i));
3693 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3694 IXGBE_PXOFFRXC(i));
3695 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003696 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
3697 IXGBE_PXONTXC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08003698 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003699 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003700 }
3701 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
3702 /* work around hardware counting issue */
3703 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07003704
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003705 /* 82598 hardware only has a 32 bit counter in the high register */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003706 if (hw->mac.type == ixgbe_mac_82599EB) {
3707 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
3708 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
3709 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
3710 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
3711 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
3712 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
3713 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
3714 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
3715 } else {
3716 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
3717 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
3718 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
3719 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
3720 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
3721 }
Auke Kok9a799d72007-09-15 14:07:45 -07003722 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
3723 adapter->stats.bprc += bprc;
3724 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003725 if (hw->mac.type == ixgbe_mac_82598EB)
3726 adapter->stats.mprc -= bprc;
Auke Kok9a799d72007-09-15 14:07:45 -07003727 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
3728 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
3729 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
3730 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
3731 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
3732 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
3733 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003734 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003735 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
3736 adapter->stats.lxontxc += lxon;
3737 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
3738 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07003739 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3740 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003741 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
3742 /*
3743 * 82598 errata - tx of flow control packets is included in tx counters
3744 */
3745 xon_off_tot = lxon + lxoff;
3746 adapter->stats.gptc -= xon_off_tot;
3747 adapter->stats.mptc -= xon_off_tot;
3748 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07003749 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3750 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
3751 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07003752 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
3753 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003754 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003755 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3756 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3757 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3758 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3759 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003760 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3761
3762 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07003763 adapter->net_stats.multicast = adapter->stats.mprc;
3764
3765 /* Rx Errors */
3766 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003767 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07003768 adapter->net_stats.rx_dropped = 0;
3769 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3770 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003771 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07003772}
3773
3774/**
3775 * ixgbe_watchdog - Timer Call-back
3776 * @data: pointer to adapter cast into an unsigned long
3777 **/
3778static void ixgbe_watchdog(unsigned long data)
3779{
3780 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003781 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003782
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003783 /* Do the watchdog outside of interrupt context due to the lovely
3784 * delays that some of the newer hardware requires */
3785 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
3786 /* Cause software interrupt to ensure rx rings are cleaned */
3787 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3788 u32 eics =
3789 (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1;
3790 IXGBE_WRITE_REG(hw, IXGBE_EICS, eics);
3791 } else {
3792 /* For legacy and MSI interrupts don't set any bits that
3793 * are enabled for EIAM, because this operation would
3794 * set *both* EIMS and EICS for any bit in EIAM */
3795 IXGBE_WRITE_REG(hw, IXGBE_EICS,
3796 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
3797 }
3798 /* Reset the timer */
3799 mod_timer(&adapter->watchdog_timer,
3800 round_jiffies(jiffies + 2 * HZ));
3801 }
3802
3803 schedule_work(&adapter->watchdog_task);
3804}
3805
3806/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003807 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
3808 * @work: pointer to work_struct containing our data
3809 **/
3810static void ixgbe_multispeed_fiber_task(struct work_struct *work)
3811{
3812 struct ixgbe_adapter *adapter = container_of(work,
3813 struct ixgbe_adapter,
3814 multispeed_fiber_task);
3815 struct ixgbe_hw *hw = &adapter->hw;
3816 u32 autoneg;
3817
3818 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
3819 if (hw->mac.ops.get_link_capabilities)
3820 hw->mac.ops.get_link_capabilities(hw, &autoneg,
3821 &hw->mac.autoneg);
3822 if (hw->mac.ops.setup_link_speed)
3823 hw->mac.ops.setup_link_speed(hw, autoneg, true, true);
3824 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3825 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
3826}
3827
3828/**
3829 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
3830 * @work: pointer to work_struct containing our data
3831 **/
3832static void ixgbe_sfp_config_module_task(struct work_struct *work)
3833{
3834 struct ixgbe_adapter *adapter = container_of(work,
3835 struct ixgbe_adapter,
3836 sfp_config_module_task);
3837 struct ixgbe_hw *hw = &adapter->hw;
3838 u32 err;
3839
3840 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
3841 err = hw->phy.ops.identify_sfp(hw);
3842 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
3843 DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err);
3844 ixgbe_down(adapter);
3845 return;
3846 }
3847 hw->mac.ops.setup_sfp(hw);
3848
3849 if (!adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)
3850 /* This will also work for DA Twinax connections */
3851 schedule_work(&adapter->multispeed_fiber_task);
3852 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
3853}
3854
3855/**
Alexander Duyck69888672008-09-11 20:05:39 -07003856 * ixgbe_watchdog_task - worker thread to bring link up
3857 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003858 **/
3859static void ixgbe_watchdog_task(struct work_struct *work)
3860{
3861 struct ixgbe_adapter *adapter = container_of(work,
3862 struct ixgbe_adapter,
3863 watchdog_task);
3864 struct net_device *netdev = adapter->netdev;
3865 struct ixgbe_hw *hw = &adapter->hw;
3866 u32 link_speed = adapter->link_speed;
3867 bool link_up = adapter->link_up;
3868
3869 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
3870
3871 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3872 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
3873 if (link_up ||
3874 time_after(jiffies, (adapter->link_check_timeout +
3875 IXGBE_TRY_LINK_TIMEOUT))) {
3876 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
3877 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
3878 }
3879 adapter->link_up = link_up;
3880 adapter->link_speed = link_speed;
3881 }
Auke Kok9a799d72007-09-15 14:07:45 -07003882
3883 if (link_up) {
3884 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003885 bool flow_rx, flow_tx;
3886
3887 if (hw->mac.type == ixgbe_mac_82599EB) {
3888 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
3889 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
3890 flow_rx = (mflcn & IXGBE_MFLCN_RFCE);
3891 flow_tx = (fccfg & IXGBE_FCCFG_TFCE_802_3X);
3892 } else {
3893 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3894 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
3895 flow_rx = (frctl & IXGBE_FCTRL_RFCE);
3896 flow_tx = (rmcs & IXGBE_RMCS_TFCE_802_3X);
3897 }
3898
Jeff Kirshera46e5342008-11-27 00:22:21 -08003899 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
3900 "Flow Control: %s\n",
3901 netdev->name,
3902 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
3903 "10 Gbps" :
3904 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
3905 "1 Gbps" : "unknown speed")),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003906 ((flow_rx && flow_tx) ? "RX/TX" :
3907 (flow_rx ? "RX" :
3908 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07003909
3910 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003911 } else {
3912 /* Force detection of hung controller */
3913 adapter->detect_tx_hung = true;
3914 }
3915 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003916 adapter->link_up = false;
3917 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003918 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08003919 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
3920 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07003921 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003922 }
3923 }
3924
3925 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003926 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07003927}
3928
Auke Kok9a799d72007-09-15 14:07:45 -07003929static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003930 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
3931 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07003932{
3933 struct ixgbe_adv_tx_context_desc *context_desc;
3934 unsigned int i;
3935 int err;
3936 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003937 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
3938 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07003939
3940 if (skb_is_gso(skb)) {
3941 if (skb_header_cloned(skb)) {
3942 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3943 if (err)
3944 return err;
3945 }
3946 l4len = tcp_hdrlen(skb);
3947 *hdr_len += l4len;
3948
Al Viro8327d002007-12-10 18:54:12 +00003949 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003950 struct iphdr *iph = ip_hdr(skb);
3951 iph->tot_len = 0;
3952 iph->check = 0;
3953 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003954 iph->daddr, 0,
3955 IPPROTO_TCP,
3956 0);
Auke Kok9a799d72007-09-15 14:07:45 -07003957 adapter->hw_tso_ctxt++;
3958 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3959 ipv6_hdr(skb)->payload_len = 0;
3960 tcp_hdr(skb)->check =
3961 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003962 &ipv6_hdr(skb)->daddr,
3963 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07003964 adapter->hw_tso6_ctxt++;
3965 }
3966
3967 i = tx_ring->next_to_use;
3968
3969 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3970 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3971
3972 /* VLAN MACLEN IPLEN */
3973 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3974 vlan_macip_lens |=
3975 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3976 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003977 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003978 *hdr_len += skb_network_offset(skb);
3979 vlan_macip_lens |=
3980 (skb_transport_header(skb) - skb_network_header(skb));
3981 *hdr_len +=
3982 (skb_transport_header(skb) - skb_network_header(skb));
3983 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3984 context_desc->seqnum_seed = 0;
3985
3986 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003987 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003988 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07003989
Al Viro8327d002007-12-10 18:54:12 +00003990 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07003991 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3992 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3993 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3994
3995 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003996 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07003997 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
3998 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003999 /* use index 1 for TSO */
4000 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004001 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4002
4003 tx_buffer_info->time_stamp = jiffies;
4004 tx_buffer_info->next_to_watch = i;
4005
4006 i++;
4007 if (i == tx_ring->count)
4008 i = 0;
4009 tx_ring->next_to_use = i;
4010
4011 return true;
4012 }
4013 return false;
4014}
4015
4016static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004017 struct ixgbe_ring *tx_ring,
4018 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07004019{
4020 struct ixgbe_adv_tx_context_desc *context_desc;
4021 unsigned int i;
4022 struct ixgbe_tx_buffer *tx_buffer_info;
4023 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4024
4025 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4026 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4027 i = tx_ring->next_to_use;
4028 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4029 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4030
4031 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4032 vlan_macip_lens |=
4033 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4034 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004035 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004036 if (skb->ip_summed == CHECKSUM_PARTIAL)
4037 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004038 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07004039
4040 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4041 context_desc->seqnum_seed = 0;
4042
4043 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004044 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004045
4046 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08004047 switch (skb->protocol) {
Harvey Harrison09640e632009-02-01 00:45:17 -08004048 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07004049 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08004050 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4051 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004052 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08004053 break;
Harvey Harrison09640e632009-02-01 00:45:17 -08004054 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08004055 /* XXX what about other V6 headers?? */
4056 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
4057 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004058 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08004059 break;
Auke Kok41825d72008-02-12 15:20:33 -08004060 default:
4061 if (unlikely(net_ratelimit())) {
4062 DPRINTK(PROBE, WARNING,
4063 "partial checksum but proto=%x!\n",
4064 skb->protocol);
4065 }
4066 break;
4067 }
Auke Kok9a799d72007-09-15 14:07:45 -07004068 }
4069
4070 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004071 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07004072 context_desc->mss_l4len_idx = 0;
4073
4074 tx_buffer_info->time_stamp = jiffies;
4075 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004076
Auke Kok9a799d72007-09-15 14:07:45 -07004077 adapter->hw_csum_tx_good++;
4078 i++;
4079 if (i == tx_ring->count)
4080 i = 0;
4081 tx_ring->next_to_use = i;
4082
4083 return true;
4084 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004085
Auke Kok9a799d72007-09-15 14:07:45 -07004086 return false;
4087}
4088
4089static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004090 struct ixgbe_ring *tx_ring,
4091 struct sk_buff *skb, unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07004092{
4093 struct ixgbe_tx_buffer *tx_buffer_info;
4094 unsigned int len = skb->len;
4095 unsigned int offset = 0, size, count = 0, i;
4096 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
4097 unsigned int f;
4098
4099 len -= skb->data_len;
4100
4101 i = tx_ring->next_to_use;
4102
4103 while (len) {
4104 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4105 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4106
4107 tx_buffer_info->length = size;
4108 tx_buffer_info->dma = pci_map_single(adapter->pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004109 skb->data + offset,
4110 size, PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004111 tx_buffer_info->time_stamp = jiffies;
4112 tx_buffer_info->next_to_watch = i;
4113
4114 len -= size;
4115 offset += size;
4116 count++;
4117 i++;
4118 if (i == tx_ring->count)
4119 i = 0;
4120 }
4121
4122 for (f = 0; f < nr_frags; f++) {
4123 struct skb_frag_struct *frag;
4124
4125 frag = &skb_shinfo(skb)->frags[f];
4126 len = frag->size;
4127 offset = frag->page_offset;
4128
4129 while (len) {
4130 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4131 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
4132
4133 tx_buffer_info->length = size;
4134 tx_buffer_info->dma = pci_map_page(adapter->pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004135 frag->page,
4136 offset,
4137 size,
4138 PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004139 tx_buffer_info->time_stamp = jiffies;
4140 tx_buffer_info->next_to_watch = i;
4141
4142 len -= size;
4143 offset += size;
4144 count++;
4145 i++;
4146 if (i == tx_ring->count)
4147 i = 0;
4148 }
4149 }
4150 if (i == 0)
4151 i = tx_ring->count - 1;
4152 else
4153 i = i - 1;
4154 tx_ring->tx_buffer_info[i].skb = skb;
4155 tx_ring->tx_buffer_info[first].next_to_watch = i;
4156
4157 return count;
4158}
4159
4160static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004161 struct ixgbe_ring *tx_ring,
4162 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004163{
4164 union ixgbe_adv_tx_desc *tx_desc = NULL;
4165 struct ixgbe_tx_buffer *tx_buffer_info;
4166 u32 olinfo_status = 0, cmd_type_len = 0;
4167 unsigned int i;
4168 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
4169
4170 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
4171
4172 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
4173
4174 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4175 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
4176
4177 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
4178 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
4179
4180 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004181 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004182
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004183 /* use index 1 context for tso */
4184 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004185 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
4186 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004187 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004188
4189 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
4190 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004191 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07004192
4193 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
4194
4195 i = tx_ring->next_to_use;
4196 while (count--) {
4197 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4198 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
4199 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
4200 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004201 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07004202 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07004203 i++;
4204 if (i == tx_ring->count)
4205 i = 0;
4206 }
4207
4208 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
4209
4210 /*
4211 * Force memory writes to complete before letting h/w
4212 * know there are new descriptors to fetch. (Only
4213 * applicable for weak-ordered memory model archs,
4214 * such as IA-64).
4215 */
4216 wmb();
4217
4218 tx_ring->next_to_use = i;
4219 writel(i, adapter->hw.hw_addr + tx_ring->tail);
4220}
4221
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004222static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004223 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004224{
4225 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4226
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004227 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004228 /* Herbert's original patch had:
4229 * smp_mb__after_netif_stop_queue();
4230 * but since that doesn't exist yet, just open code it. */
4231 smp_mb();
4232
4233 /* We need to check again in a case another CPU has just
4234 * made room available. */
4235 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
4236 return -EBUSY;
4237
4238 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07004239 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004240 ++adapter->restart_queue;
4241 return 0;
4242}
4243
4244static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004245 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004246{
4247 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
4248 return 0;
4249 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
4250}
4251
Auke Kok9a799d72007-09-15 14:07:45 -07004252static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
4253{
4254 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4255 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004256 unsigned int first;
4257 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004258 u8 hdr_len = 0;
4259 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07004260 int count = 0;
4261 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004262
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004263 r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004264 tx_ring = &adapter->tx_ring[r_idx];
Auke Kok9a799d72007-09-15 14:07:45 -07004265
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004266 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
4267 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004268 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4269 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
4270 tx_flags |= (skb->queue_mapping << 13);
4271 }
4272 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
4273 tx_flags |= IXGBE_TX_FLAGS_VLAN;
4274 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4275 tx_flags |= (skb->queue_mapping << 13);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004276 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
4277 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07004278 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004279 /* three things can cause us to need a context descriptor */
4280 if (skb_is_gso(skb) ||
4281 (skb->ip_summed == CHECKSUM_PARTIAL) ||
4282 (tx_flags & IXGBE_TX_FLAGS_VLAN))
Auke Kok9a799d72007-09-15 14:07:45 -07004283 count++;
4284
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004285 count += TXD_USE_COUNT(skb_headlen(skb));
4286 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07004287 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
4288
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004289 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004290 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07004291 return NETDEV_TX_BUSY;
4292 }
Auke Kok9a799d72007-09-15 14:07:45 -07004293
Al Viro8327d002007-12-10 18:54:12 +00004294 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004295 tx_flags |= IXGBE_TX_FLAGS_IPV4;
4296 first = tx_ring->next_to_use;
4297 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
4298 if (tso < 0) {
4299 dev_kfree_skb_any(skb);
4300 return NETDEV_TX_OK;
4301 }
4302
4303 if (tso)
4304 tx_flags |= IXGBE_TX_FLAGS_TSO;
4305 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004306 (skb->ip_summed == CHECKSUM_PARTIAL))
Auke Kok9a799d72007-09-15 14:07:45 -07004307 tx_flags |= IXGBE_TX_FLAGS_CSUM;
4308
4309 ixgbe_tx_queue(adapter, tx_ring, tx_flags,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004310 ixgbe_tx_map(adapter, tx_ring, skb, first),
4311 skb->len, hdr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07004312
4313 netdev->trans_start = jiffies;
4314
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08004315 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07004316
4317 return NETDEV_TX_OK;
4318}
4319
4320/**
4321 * ixgbe_get_stats - Get System Network Statistics
4322 * @netdev: network interface device structure
4323 *
4324 * Returns the address of the device statistics structure.
4325 * The statistics are actually updated from the timer callback.
4326 **/
4327static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
4328{
4329 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4330
4331 /* only return the current stats */
4332 return &adapter->net_stats;
4333}
4334
4335/**
4336 * ixgbe_set_mac - Change the Ethernet Address of the NIC
4337 * @netdev: network interface device structure
4338 * @p: pointer to an address structure
4339 *
4340 * Returns 0 on success, negative on failure
4341 **/
4342static int ixgbe_set_mac(struct net_device *netdev, void *p)
4343{
4344 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004345 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004346 struct sockaddr *addr = p;
4347
4348 if (!is_valid_ether_addr(addr->sa_data))
4349 return -EADDRNOTAVAIL;
4350
4351 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004352 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07004353
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004354 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004355
4356 return 0;
4357}
4358
4359#ifdef CONFIG_NET_POLL_CONTROLLER
4360/*
4361 * Polling 'interrupt' - used by things like netconsole to send skbs
4362 * without having to re-enable interrupts. It's not called while
4363 * the interrupt routine is executing.
4364 */
4365static void ixgbe_netpoll(struct net_device *netdev)
4366{
4367 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4368
4369 disable_irq(adapter->pdev->irq);
4370 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
4371 ixgbe_intr(adapter->pdev->irq, netdev);
4372 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
4373 enable_irq(adapter->pdev->irq);
4374}
4375#endif
4376
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004377static const struct net_device_ops ixgbe_netdev_ops = {
4378 .ndo_open = ixgbe_open,
4379 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08004380 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004381 .ndo_get_stats = ixgbe_get_stats,
4382 .ndo_set_multicast_list = ixgbe_set_rx_mode,
4383 .ndo_validate_addr = eth_validate_addr,
4384 .ndo_set_mac_address = ixgbe_set_mac,
4385 .ndo_change_mtu = ixgbe_change_mtu,
4386 .ndo_tx_timeout = ixgbe_tx_timeout,
4387 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
4388 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
4389 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
4390#ifdef CONFIG_NET_POLL_CONTROLLER
4391 .ndo_poll_controller = ixgbe_netpoll,
4392#endif
4393};
4394
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004395/**
Auke Kok9a799d72007-09-15 14:07:45 -07004396 * ixgbe_probe - Device Initialization Routine
4397 * @pdev: PCI device information struct
4398 * @ent: entry in ixgbe_pci_tbl
4399 *
4400 * Returns 0 on success, negative on failure
4401 *
4402 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
4403 * The OS initialization, configuring of the adapter private structure,
4404 * and a hardware reset occur.
4405 **/
4406static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004407 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07004408{
4409 struct net_device *netdev;
4410 struct ixgbe_adapter *adapter = NULL;
4411 struct ixgbe_hw *hw;
4412 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07004413 static int cards_found;
4414 int i, err, pci_using_dac;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004415 u16 pm_value = 0;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004416 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07004417
4418 err = pci_enable_device(pdev);
4419 if (err)
4420 return err;
4421
4422 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4423 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
4424 pci_using_dac = 1;
4425 } else {
4426 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4427 if (err) {
4428 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
4429 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004430 dev_err(&pdev->dev, "No usable DMA "
4431 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004432 goto err_dma;
4433 }
4434 }
4435 pci_using_dac = 0;
4436 }
4437
4438 err = pci_request_regions(pdev, ixgbe_driver_name);
4439 if (err) {
4440 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
4441 goto err_pci_reg;
4442 }
4443
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004444 err = pci_enable_pcie_error_reporting(pdev);
4445 if (err) {
4446 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
4447 "0x%x\n", err);
4448 /* non-fatal, continue */
4449 }
4450
Auke Kok9a799d72007-09-15 14:07:45 -07004451 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07004452 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004453
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004454 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07004455 if (!netdev) {
4456 err = -ENOMEM;
4457 goto err_alloc_etherdev;
4458 }
4459
Auke Kok9a799d72007-09-15 14:07:45 -07004460 SET_NETDEV_DEV(netdev, &pdev->dev);
4461
4462 pci_set_drvdata(pdev, netdev);
4463 adapter = netdev_priv(netdev);
4464
4465 adapter->netdev = netdev;
4466 adapter->pdev = pdev;
4467 hw = &adapter->hw;
4468 hw->back = adapter;
4469 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
4470
Jeff Kirsher05857982008-09-11 19:57:00 -07004471 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
4472 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07004473 if (!hw->hw_addr) {
4474 err = -EIO;
4475 goto err_ioremap;
4476 }
4477
4478 for (i = 1; i <= 5; i++) {
4479 if (pci_resource_len(pdev, i) == 0)
4480 continue;
4481 }
4482
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004483 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07004484 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004485 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07004486 strcpy(netdev->name, pci_name(pdev));
4487
Auke Kok9a799d72007-09-15 14:07:45 -07004488 adapter->bd_number = cards_found;
4489
Auke Kok9a799d72007-09-15 14:07:45 -07004490 /* Setup hw api */
4491 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004492 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07004493
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004494 /* EEPROM */
4495 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
4496 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
4497 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
4498 if (!(eec & (1 << 8)))
4499 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
4500
4501 /* PHY */
4502 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08004503 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
4504
4505 /* set up this timer and work struct before calling get_invariants
4506 * which might start the timer
4507 */
4508 init_timer(&adapter->sfp_timer);
4509 adapter->sfp_timer.function = &ixgbe_sfp_timer;
4510 adapter->sfp_timer.data = (unsigned long) adapter;
4511
4512 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004513
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004514 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
4515 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
4516
4517 /* a new SFP+ module arrival, called from GPI SDP2 context */
4518 INIT_WORK(&adapter->sfp_config_module_task,
4519 ixgbe_sfp_config_module_task);
4520
Auke Kok9a799d72007-09-15 14:07:45 -07004521 err = ii->get_invariants(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004522 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
4523 /* start a kernel thread to watch for a module to arrive */
4524 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4525 mod_timer(&adapter->sfp_timer,
4526 round_jiffies(jiffies + (2 * HZ)));
4527 err = 0;
4528 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4529 DPRINTK(PROBE, ERR, "failed to load because an "
4530 "unsupported SFP+ module type was detected.\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004531 goto err_hw_init;
Donald Skidmorec4900be2008-11-20 21:11:42 -08004532 } else if (err) {
4533 goto err_hw_init;
4534 }
Auke Kok9a799d72007-09-15 14:07:45 -07004535
4536 /* setup the private structure */
4537 err = ixgbe_sw_init(adapter);
4538 if (err)
4539 goto err_sw_init;
4540
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004541 /* reset_hw fills in the perm_addr as well */
4542 err = hw->mac.ops.reset_hw(hw);
4543 if (err) {
4544 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
4545 goto err_sw_init;
4546 }
4547
Auke Kok9a799d72007-09-15 14:07:45 -07004548 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004549 NETIF_F_IP_CSUM |
4550 NETIF_F_HW_VLAN_TX |
4551 NETIF_F_HW_VLAN_RX |
4552 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004553
Jesse Brandeburge9990a92008-08-26 04:27:24 -07004554 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07004555 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07004556 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08004557 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004558
4559 netdev->vlan_features |= NETIF_F_TSO;
4560 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07004561 netdev->vlan_features |= NETIF_F_IP_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004562 netdev->vlan_features |= NETIF_F_SG;
4563
Alexander Duyck2f90b862008-11-20 20:52:10 -08004564 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4565 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4566
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004567#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004568 netdev->dcbnl_ops = &dcbnl_ops;
4569#endif
4570
Auke Kok9a799d72007-09-15 14:07:45 -07004571 if (pci_using_dac)
4572 netdev->features |= NETIF_F_HIGHDMA;
4573
Auke Kok9a799d72007-09-15 14:07:45 -07004574 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004575 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07004576 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
4577 err = -EIO;
4578 goto err_eeprom;
4579 }
4580
4581 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
4582 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
4583
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004584 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
4585 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004586 err = -EIO;
4587 goto err_eeprom;
4588 }
4589
4590 init_timer(&adapter->watchdog_timer);
4591 adapter->watchdog_timer.function = &ixgbe_watchdog;
4592 adapter->watchdog_timer.data = (unsigned long)adapter;
4593
4594 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004595 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004596
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004597 err = ixgbe_init_interrupt_scheme(adapter);
4598 if (err)
4599 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07004600
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004601 switch (pdev->device) {
4602 case IXGBE_DEV_ID_82599_KX4:
4603#define IXGBE_PCIE_PMCSR 0x44
4604 adapter->wol = IXGBE_WUFC_MAG;
4605 pci_read_config_word(pdev, IXGBE_PCIE_PMCSR, &pm_value);
4606 pci_write_config_word(pdev, IXGBE_PCIE_PMCSR,
4607 (pm_value | (1 << 8)));
4608 break;
4609 default:
4610 adapter->wol = 0;
4611 break;
4612 }
4613 device_init_wakeup(&adapter->pdev->dev, true);
4614 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
4615
Auke Kok9a799d72007-09-15 14:07:45 -07004616 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07004617 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004618 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
4619 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
4620 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
4621 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
4622 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004623 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07004624 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004625 ixgbe_read_pba_num_generic(hw, &part_num);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004626 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
4627 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
4628 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
4629 (part_num >> 8), (part_num & 0xff));
4630 else
4631 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
4632 hw->mac.type, hw->phy.type,
4633 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07004634
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004635 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Auke Kok0c254d82008-02-11 09:25:56 -08004636 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004637 "this card is not sufficient for optimal "
4638 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004639 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004640 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004641 }
4642
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08004643 /* save off EEPROM version number */
4644 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
4645
Auke Kok9a799d72007-09-15 14:07:45 -07004646 /* reset the hardware with the new settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004647 hw->mac.ops.start_hw(hw);
4648
Auke Kok9a799d72007-09-15 14:07:45 -07004649 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004650
4651 strcpy(netdev->name, "eth%d");
4652 err = register_netdev(netdev);
4653 if (err)
4654 goto err_register;
4655
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004656#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03004657 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004658 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
4659 /* always use CB2 mode, difference is masked
4660 * in the CB driver */
4661 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
4662 ixgbe_setup_dca(adapter);
4663 }
4664#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004665
4666 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
4667 cards_found++;
4668 return 0;
4669
4670err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004671 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004672err_hw_init:
4673err_sw_init:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004674 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004675err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08004676 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4677 del_timer_sync(&adapter->sfp_timer);
4678 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004679 cancel_work_sync(&adapter->multispeed_fiber_task);
4680 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004681 iounmap(hw->hw_addr);
4682err_ioremap:
4683 free_netdev(netdev);
4684err_alloc_etherdev:
4685 pci_release_regions(pdev);
4686err_pci_reg:
4687err_dma:
4688 pci_disable_device(pdev);
4689 return err;
4690}
4691
4692/**
4693 * ixgbe_remove - Device Removal Routine
4694 * @pdev: PCI device information struct
4695 *
4696 * ixgbe_remove is called by the PCI subsystem to alert the driver
4697 * that it should release a PCI device. The could be caused by a
4698 * Hot-Plug event, or because the driver is going to be removed from
4699 * memory.
4700 **/
4701static void __devexit ixgbe_remove(struct pci_dev *pdev)
4702{
4703 struct net_device *netdev = pci_get_drvdata(pdev);
4704 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004705 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004706
4707 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004708 /* clear the module not found bit to make sure the worker won't
4709 * reschedule
4710 */
4711 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07004712 del_timer_sync(&adapter->watchdog_timer);
4713
Donald Skidmorec4900be2008-11-20 21:11:42 -08004714 del_timer_sync(&adapter->sfp_timer);
4715 cancel_work_sync(&adapter->watchdog_task);
4716 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004717 cancel_work_sync(&adapter->multispeed_fiber_task);
4718 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004719 flush_scheduled_work();
4720
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004721#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004722 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
4723 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
4724 dca_remove_requester(&pdev->dev);
4725 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
4726 }
4727
4728#endif
Donald Skidmorec4900be2008-11-20 21:11:42 -08004729 if (netdev->reg_state == NETREG_REGISTERED)
4730 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004731
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004732 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004733
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004734 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004735
4736 iounmap(adapter->hw.hw_addr);
4737 pci_release_regions(pdev);
4738
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004739 DPRINTK(PROBE, INFO, "complete\n");
4740 kfree(adapter->tx_ring);
4741 kfree(adapter->rx_ring);
4742
Auke Kok9a799d72007-09-15 14:07:45 -07004743 free_netdev(netdev);
4744
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004745 err = pci_disable_pcie_error_reporting(pdev);
4746 if (err)
4747 dev_err(&pdev->dev,
4748 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
4749
Auke Kok9a799d72007-09-15 14:07:45 -07004750 pci_disable_device(pdev);
4751}
4752
4753/**
4754 * ixgbe_io_error_detected - called when PCI error is detected
4755 * @pdev: Pointer to PCI device
4756 * @state: The current pci connection state
4757 *
4758 * This function is called after a PCI bus error affecting
4759 * this device has been detected.
4760 */
4761static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004762 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07004763{
4764 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004765 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004766
4767 netif_device_detach(netdev);
4768
4769 if (netif_running(netdev))
4770 ixgbe_down(adapter);
4771 pci_disable_device(pdev);
4772
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004773 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07004774 return PCI_ERS_RESULT_NEED_RESET;
4775}
4776
4777/**
4778 * ixgbe_io_slot_reset - called after the pci bus has been reset.
4779 * @pdev: Pointer to PCI device
4780 *
4781 * Restart the card from scratch, as if from a cold-boot.
4782 */
4783static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
4784{
4785 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004786 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004787 pci_ers_result_t result;
4788 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004789
4790 if (pci_enable_device(pdev)) {
4791 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004792 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004793 result = PCI_ERS_RESULT_DISCONNECT;
4794 } else {
4795 pci_set_master(pdev);
4796 pci_restore_state(pdev);
4797
4798 pci_enable_wake(pdev, PCI_D3hot, 0);
4799 pci_enable_wake(pdev, PCI_D3cold, 0);
4800
4801 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00004802 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004803 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07004804 }
Auke Kok9a799d72007-09-15 14:07:45 -07004805
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004806 err = pci_cleanup_aer_uncorrect_error_status(pdev);
4807 if (err) {
4808 dev_err(&pdev->dev,
4809 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
4810 /* non-fatal, continue */
4811 }
Auke Kok9a799d72007-09-15 14:07:45 -07004812
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004813 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07004814}
4815
4816/**
4817 * ixgbe_io_resume - called when traffic can start flowing again.
4818 * @pdev: Pointer to PCI device
4819 *
4820 * This callback is called when the error recovery driver tells us that
4821 * its OK to resume normal operation.
4822 */
4823static void ixgbe_io_resume(struct pci_dev *pdev)
4824{
4825 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004826 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004827
4828 if (netif_running(netdev)) {
4829 if (ixgbe_up(adapter)) {
4830 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
4831 return;
4832 }
4833 }
4834
4835 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004836}
4837
4838static struct pci_error_handlers ixgbe_err_handler = {
4839 .error_detected = ixgbe_io_error_detected,
4840 .slot_reset = ixgbe_io_slot_reset,
4841 .resume = ixgbe_io_resume,
4842};
4843
4844static struct pci_driver ixgbe_driver = {
4845 .name = ixgbe_driver_name,
4846 .id_table = ixgbe_pci_tbl,
4847 .probe = ixgbe_probe,
4848 .remove = __devexit_p(ixgbe_remove),
4849#ifdef CONFIG_PM
4850 .suspend = ixgbe_suspend,
4851 .resume = ixgbe_resume,
4852#endif
4853 .shutdown = ixgbe_shutdown,
4854 .err_handler = &ixgbe_err_handler
4855};
4856
4857/**
4858 * ixgbe_init_module - Driver Registration Routine
4859 *
4860 * ixgbe_init_module is the first routine called when the driver is
4861 * loaded. All it does is register with the PCI subsystem.
4862 **/
4863static int __init ixgbe_init_module(void)
4864{
4865 int ret;
4866 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
4867 ixgbe_driver_string, ixgbe_driver_version);
4868
4869 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
4870
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004871#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004872 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004873#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004874
Auke Kok9a799d72007-09-15 14:07:45 -07004875 ret = pci_register_driver(&ixgbe_driver);
4876 return ret;
4877}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004878
Auke Kok9a799d72007-09-15 14:07:45 -07004879module_init(ixgbe_init_module);
4880
4881/**
4882 * ixgbe_exit_module - Driver Exit Cleanup Routine
4883 *
4884 * ixgbe_exit_module is called just before the driver is removed
4885 * from memory.
4886 **/
4887static void __exit ixgbe_exit_module(void)
4888{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004889#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004890 dca_unregister_notify(&dca_notifier);
4891#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004892 pci_unregister_driver(&ixgbe_driver);
4893}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004894
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004895#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004896static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004897 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004898{
4899 int ret_val;
4900
4901 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004902 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004903
4904 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4905}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004906#endif /* CONFIG_IXGBE_DCA */
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004907
Auke Kok9a799d72007-09-15 14:07:45 -07004908module_exit(ixgbe_exit_module);
4909
4910/* ixgbe_main.c */