blob: 8e270b63e8064d88c27f26ee9717c302b2cad8fc [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
Peter P Waskiewicz Jr3efac5a2009-02-01 01:19:20 -080050#define DRV_VERSION "1.3.56-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,
Auke Kok9a799d72007-09-15 14:07:45 -070056};
57
58/* ixgbe_pci_tbl - PCI Device ID Table
59 *
60 * Wildcard entries (PCI_ANY_ID) should come last
61 * Last entry must be all 0s
62 *
63 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
64 * Class, Class Mask, private data (not used) }
65 */
66static struct pci_device_id ixgbe_pci_tbl[] = {
Don Skidmore1e336d02009-01-26 20:57:51 -080067 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
68 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070069 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070070 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070071 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070072 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070073 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
74 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070075 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070076 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070077 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
78 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080079 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
80 board_82598 },
81 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
82 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070083 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
84 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080085 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
86 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -080087 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
88 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070089
90 /* required last entry */
91 {0, }
92};
93MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
94
Jeff Garzik5dd2d332008-10-16 05:09:31 -040095#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080096static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070097 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080098static struct notifier_block dca_notifier = {
99 .notifier_call = ixgbe_notify_dca,
100 .next = NULL,
101 .priority = 0
102};
103#endif
104
Auke Kok9a799d72007-09-15 14:07:45 -0700105MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
106MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
107MODULE_LICENSE("GPL");
108MODULE_VERSION(DRV_VERSION);
109
110#define DEFAULT_DEBUG_LEVEL_SHIFT 3
111
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800112static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
113{
114 u32 ctrl_ext;
115
116 /* Let firmware take over control of h/w */
117 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
118 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700119 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800120}
121
122static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
123{
124 u32 ctrl_ext;
125
126 /* Let firmware know the driver has taken over */
127 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
128 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700129 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800130}
Auke Kok9a799d72007-09-15 14:07:45 -0700131
Auke Kok9a799d72007-09-15 14:07:45 -0700132static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, u16 int_alloc_entry,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700133 u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700134{
135 u32 ivar, index;
136
137 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
138 index = (int_alloc_entry >> 2) & 0x1F;
139 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR(index));
140 ivar &= ~(0xFF << (8 * (int_alloc_entry & 0x3)));
141 ivar |= (msix_vector << (8 * (int_alloc_entry & 0x3)));
142 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR(index), ivar);
143}
144
145static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700146 struct ixgbe_tx_buffer
147 *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700148{
149 if (tx_buffer_info->dma) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700150 pci_unmap_page(adapter->pdev, tx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700151 tx_buffer_info->length, PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700152 tx_buffer_info->dma = 0;
153 }
154 if (tx_buffer_info->skb) {
155 dev_kfree_skb_any(tx_buffer_info->skb);
156 tx_buffer_info->skb = NULL;
157 }
158 /* tx_buffer_info must be completely set up in the transmit path */
159}
160
161static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700162 struct ixgbe_ring *tx_ring,
163 unsigned int eop)
Auke Kok9a799d72007-09-15 14:07:45 -0700164{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700165 struct ixgbe_hw *hw = &adapter->hw;
166 u32 head, tail;
167
Auke Kok9a799d72007-09-15 14:07:45 -0700168 /* Detect a transmit hang in hardware, this serializes the
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700169 * check with the clearing of time_stamp and movement of eop */
170 head = IXGBE_READ_REG(hw, tx_ring->head);
171 tail = IXGBE_READ_REG(hw, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -0700172 adapter->detect_tx_hung = false;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700173 if ((head != tail) &&
174 tx_ring->tx_buffer_info[eop].time_stamp &&
Auke Kok9a799d72007-09-15 14:07:45 -0700175 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
176 !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) {
177 /* detected Tx unit hang */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700178 union ixgbe_adv_tx_desc *tx_desc;
179 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
Auke Kok9a799d72007-09-15 14:07:45 -0700180 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700181 " Tx Queue <%d>\n"
182 " TDH, TDT <%x>, <%x>\n"
Auke Kok9a799d72007-09-15 14:07:45 -0700183 " next_to_use <%x>\n"
184 " next_to_clean <%x>\n"
185 "tx_buffer_info[next_to_clean]\n"
186 " time_stamp <%lx>\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700187 " jiffies <%lx>\n",
188 tx_ring->queue_index,
189 head, tail,
190 tx_ring->next_to_use, eop,
191 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
Auke Kok9a799d72007-09-15 14:07:45 -0700192 return true;
193 }
194
195 return false;
196}
197
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700198#define IXGBE_MAX_TXD_PWR 14
199#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800200
201/* Tx Descriptors needed, worst case */
202#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
203 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
204#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700205 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800206
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700207static void ixgbe_tx_timeout(struct net_device *netdev);
208
Auke Kok9a799d72007-09-15 14:07:45 -0700209/**
210 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
211 * @adapter: board private structure
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700212 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700213 **/
214static bool ixgbe_clean_tx_irq(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700215 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700216{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700217 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800218 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
219 struct ixgbe_tx_buffer *tx_buffer_info;
220 unsigned int i, eop, count = 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700221 unsigned int total_bytes = 0, total_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700222
223 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800224 eop = tx_ring->tx_buffer_info[i].next_to_watch;
225 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
226
227 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
228 (count < tx_ring->count)) {
229 bool cleaned = false;
230 for ( ; !cleaned; count++) {
231 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700232 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
233 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800234 cleaned = (i == eop);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700235 skb = tx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700236
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800237 if (cleaned && skb) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800238 unsigned int segs, bytecount;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700239
240 /* gso_segs is currently only valid for tcp */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800241 segs = skb_shinfo(skb)->gso_segs ?: 1;
242 /* multiply data chunks by size of headers */
243 bytecount = ((segs - 1) * skb_headlen(skb)) +
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700244 skb->len;
245 total_packets += segs;
246 total_bytes += bytecount;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800247 }
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700248
Auke Kok9a799d72007-09-15 14:07:45 -0700249 ixgbe_unmap_and_free_tx_resource(adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700250 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700251
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800252 tx_desc->wb.status = 0;
253
Auke Kok9a799d72007-09-15 14:07:45 -0700254 i++;
255 if (i == tx_ring->count)
256 i = 0;
257 }
258
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800259 eop = tx_ring->tx_buffer_info[i].next_to_watch;
260 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
261 }
262
Auke Kok9a799d72007-09-15 14:07:45 -0700263 tx_ring->next_to_clean = i;
264
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800265#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700266 if (unlikely(count && netif_carrier_ok(netdev) &&
267 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800268 /* Make sure that anybody stopping the queue after this
269 * sees the new next_to_clean.
270 */
271 smp_mb();
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800272 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
273 !test_bit(__IXGBE_DOWN, &adapter->state)) {
274 netif_wake_subqueue(netdev, tx_ring->queue_index);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700275 ++adapter->restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800276 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800277 }
Auke Kok9a799d72007-09-15 14:07:45 -0700278
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700279 if (adapter->detect_tx_hung) {
280 if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
281 /* schedule immediate reset if we believe we hung */
282 DPRINTK(PROBE, INFO,
283 "tx hang %d detected, resetting adapter\n",
284 adapter->tx_timeout_count + 1);
285 ixgbe_tx_timeout(adapter->netdev);
286 }
287 }
Auke Kok9a799d72007-09-15 14:07:45 -0700288
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700289 /* re-arm the interrupt */
290 if ((total_packets >= tx_ring->work_limit) ||
291 (count == tx_ring->count))
292 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, tx_ring->v_idx);
Auke Kok9a799d72007-09-15 14:07:45 -0700293
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700294 tx_ring->total_bytes += total_bytes;
295 tx_ring->total_packets += total_packets;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700296 tx_ring->stats.packets += total_packets;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800297 tx_ring->stats.bytes += total_bytes;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700298 adapter->net_stats.tx_bytes += total_bytes;
299 adapter->net_stats.tx_packets += total_packets;
300 return (total_packets ? true : false);
Auke Kok9a799d72007-09-15 14:07:45 -0700301}
302
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400303#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800304static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700305 struct ixgbe_ring *rx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800306{
307 u32 rxctrl;
308 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700309 int q = rx_ring - adapter->rx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800310
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700311 if (rx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800312 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
313 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700314 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800315 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
316 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
Don Skidmore15005a32009-01-19 16:54:13 -0800317 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
318 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
319 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800320 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700321 rx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800322 }
323 put_cpu();
324}
325
326static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700327 struct ixgbe_ring *tx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800328{
329 u32 txctrl;
330 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700331 int q = tx_ring - adapter->tx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800332
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700333 if (tx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800334 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
335 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700336 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800337 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
338 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700339 tx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800340 }
341 put_cpu();
342}
343
344static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
345{
346 int i;
347
348 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
349 return;
350
351 for (i = 0; i < adapter->num_tx_queues; i++) {
352 adapter->tx_ring[i].cpu = -1;
353 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
354 }
355 for (i = 0; i < adapter->num_rx_queues; i++) {
356 adapter->rx_ring[i].cpu = -1;
357 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
358 }
359}
360
361static int __ixgbe_notify_dca(struct device *dev, void *data)
362{
363 struct net_device *netdev = dev_get_drvdata(dev);
364 struct ixgbe_adapter *adapter = netdev_priv(netdev);
365 unsigned long event = *(unsigned long *)data;
366
367 switch (event) {
368 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700369 /* if we're already enabled, don't do it again */
370 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
371 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800372 /* Always use CB2 mode, difference is masked
373 * in the CB driver. */
374 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
Denis V. Lunev652f0932008-03-27 14:39:17 +0300375 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700376 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800377 ixgbe_setup_dca(adapter);
378 break;
379 }
380 /* Fall Through since DCA is disabled. */
381 case DCA_PROVIDER_REMOVE:
382 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
383 dca_remove_requester(dev);
384 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
385 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
386 }
387 break;
388 }
389
Denis V. Lunev652f0932008-03-27 14:39:17 +0300390 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800391}
392
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400393#endif /* CONFIG_IXGBE_DCA */
Auke Kok9a799d72007-09-15 14:07:45 -0700394/**
395 * ixgbe_receive_skb - Send a completed packet up the stack
396 * @adapter: board private structure
397 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700398 * @status: hardware indication of status of receive
399 * @rx_ring: rx descriptor ring (for a specific queue) to setup
400 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -0700401 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800402static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700403 struct sk_buff *skb, u8 status,
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700404 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -0700405{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800406 struct ixgbe_adapter *adapter = q_vector->adapter;
407 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700408 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
409 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -0700410
David S. Miller0c8dfc82009-01-27 16:22:32 -0800411 skb_record_rx_queue(skb, q_vector - &adapter->q_vector[0]);
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800412 if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800413 if (adapter->vlgrp && is_vlan && (tag != 0))
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800414 vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700415 else
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800416 napi_gro_receive(napi, skb);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700417 } else {
418 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800419 if (adapter->vlgrp && is_vlan && (tag != 0))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700420 vlan_hwaccel_receive_skb(skb, adapter->vlgrp, tag);
421 else
422 netif_receive_skb(skb);
423 } else {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800424 if (adapter->vlgrp && is_vlan && (tag != 0))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700425 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
426 else
427 netif_rx(skb);
428 }
Auke Kok9a799d72007-09-15 14:07:45 -0700429 }
430}
431
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800432/**
433 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
434 * @adapter: address of board private structure
435 * @status_err: hardware indication of status of receive
436 * @skb: skb currently being received and modified
437 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700438static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700439 u32 status_err, struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700440{
441 skb->ip_summed = CHECKSUM_NONE;
442
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700443 /* Rx csum disabled */
444 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -0700445 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800446
447 /* if IP and error */
448 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
449 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700450 adapter->hw_csum_rx_error++;
451 return;
452 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800453
454 if (!(status_err & IXGBE_RXD_STAT_L4CS))
455 return;
456
457 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
458 adapter->hw_csum_rx_error++;
459 return;
460 }
461
Auke Kok9a799d72007-09-15 14:07:45 -0700462 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800463 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -0700464 adapter->hw_csum_rx_good++;
465}
466
467/**
468 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
469 * @adapter: address of board private structure
470 **/
471static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700472 struct ixgbe_ring *rx_ring,
473 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700474{
Auke Kok9a799d72007-09-15 14:07:45 -0700475 struct pci_dev *pdev = adapter->pdev;
476 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700477 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700478 unsigned int i;
Auke Kok9a799d72007-09-15 14:07:45 -0700479
480 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700481 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700482
483 while (cleaned_count--) {
484 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
485
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700486 if (!bi->page_dma &&
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700487 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700488 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700489 bi->page = alloc_page(GFP_ATOMIC);
490 if (!bi->page) {
491 adapter->alloc_rx_page_failed++;
492 goto no_buffers;
493 }
494 bi->page_offset = 0;
495 } else {
496 /* use a half page if we're re-using */
497 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700498 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700499
500 bi->page_dma = pci_map_page(pdev, bi->page,
501 bi->page_offset,
502 (PAGE_SIZE / 2),
503 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700504 }
505
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700506 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800507 struct sk_buff *skb;
508 skb = netdev_alloc_skb(adapter->netdev,
509 (rx_ring->rx_buf_len +
510 NET_IP_ALIGN));
Auke Kok9a799d72007-09-15 14:07:45 -0700511
512 if (!skb) {
513 adapter->alloc_rx_buff_failed++;
514 goto no_buffers;
515 }
516
517 /*
518 * Make buffer alignment 2 beyond a 16 byte boundary
519 * this will result in a 16 byte aligned IP header after
520 * the 14 byte MAC header is removed
521 */
522 skb_reserve(skb, NET_IP_ALIGN);
523
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700524 bi->skb = skb;
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800525 bi->dma = pci_map_single(pdev, skb->data,
526 rx_ring->rx_buf_len,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700527 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700528 }
529 /* Refresh the desc even if buffer_addrs didn't change because
530 * each write-back erases this info. */
531 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700532 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
533 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700534 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700535 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700536 }
537
538 i++;
539 if (i == rx_ring->count)
540 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700541 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700542 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700543
Auke Kok9a799d72007-09-15 14:07:45 -0700544no_buffers:
545 if (rx_ring->next_to_use != i) {
546 rx_ring->next_to_use = i;
547 if (i-- == 0)
548 i = (rx_ring->count - 1);
549
550 /*
551 * Force memory writes to complete before letting h/w
552 * know there are new descriptors to fetch. (Only
553 * applicable for weak-ordered memory model archs,
554 * such as IA-64).
555 */
556 wmb();
557 writel(i, adapter->hw.hw_addr + rx_ring->tail);
558 }
559}
560
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700561static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
562{
563 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
564}
565
566static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
567{
568 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
569}
570
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800571static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700572 struct ixgbe_ring *rx_ring,
573 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700574{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800575 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -0700576 struct pci_dev *pdev = adapter->pdev;
577 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
578 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
579 struct sk_buff *skb;
580 unsigned int i;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700581 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700582 u16 hdr_info;
583 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700584 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800585 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700586
587 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700588 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
589 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
590 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700591
592 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700593 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700594 if (*work_done >= work_to_do)
595 break;
596 (*work_done)++;
597
598 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700599 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
600 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700601 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700602 if (hdr_info & IXGBE_RXDADV_SPH)
603 adapter->rx_hdr_split++;
604 if (len > IXGBE_RX_HDR_SIZE)
605 len = IXGBE_RX_HDR_SIZE;
606 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700607 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700608 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700609 }
Auke Kok9a799d72007-09-15 14:07:45 -0700610
611 cleaned = true;
612 skb = rx_buffer_info->skb;
613 prefetch(skb->data - NET_IP_ALIGN);
614 rx_buffer_info->skb = NULL;
615
616 if (len && !skb_shinfo(skb)->nr_frags) {
617 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800618 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700619 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700620 skb_put(skb, len);
621 }
622
623 if (upper_len) {
624 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700625 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700626 rx_buffer_info->page_dma = 0;
627 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700628 rx_buffer_info->page,
629 rx_buffer_info->page_offset,
630 upper_len);
631
632 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
633 (page_count(rx_buffer_info->page) != 1))
634 rx_buffer_info->page = NULL;
635 else
636 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700637
638 skb->len += upper_len;
639 skb->data_len += upper_len;
640 skb->truesize += upper_len;
641 }
642
643 i++;
644 if (i == rx_ring->count)
645 i = 0;
646 next_buffer = &rx_ring->rx_buffer_info[i];
647
648 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
649 prefetch(next_rxd);
650
651 cleaned_count++;
652 if (staterr & IXGBE_RXD_STAT_EOP) {
653 rx_ring->stats.packets++;
654 rx_ring->stats.bytes += skb->len;
655 } else {
656 rx_buffer_info->skb = next_buffer->skb;
657 rx_buffer_info->dma = next_buffer->dma;
658 next_buffer->skb = skb;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700659 next_buffer->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700660 adapter->non_eop_descs++;
661 goto next_desc;
662 }
663
664 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
665 dev_kfree_skb_irq(skb);
666 goto next_desc;
667 }
668
669 ixgbe_rx_checksum(adapter, staterr, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800670
671 /* probably a little skewed due to removing CRC */
672 total_rx_bytes += skb->len;
673 total_rx_packets++;
674
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700675 skb->protocol = eth_type_trans(skb, adapter->netdev);
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800676 ixgbe_receive_skb(q_vector, skb, staterr, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700677
678next_desc:
679 rx_desc->wb.upper.status_error = 0;
680
681 /* return some buffers to hardware, one at a time is too slow */
682 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
683 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
684 cleaned_count = 0;
685 }
686
687 /* use prefetched values */
688 rx_desc = next_rxd;
689 rx_buffer_info = next_buffer;
690
691 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700692 }
693
Auke Kok9a799d72007-09-15 14:07:45 -0700694 rx_ring->next_to_clean = i;
695 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
696
697 if (cleaned_count)
698 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
699
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800700 rx_ring->total_packets += total_rx_packets;
701 rx_ring->total_bytes += total_rx_bytes;
702 adapter->net_stats.rx_bytes += total_rx_bytes;
703 adapter->net_stats.rx_packets += total_rx_packets;
704
Auke Kok9a799d72007-09-15 14:07:45 -0700705 return cleaned;
706}
707
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800708static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700709/**
710 * ixgbe_configure_msix - Configure MSI-X hardware
711 * @adapter: board private structure
712 *
713 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
714 * interrupts.
715 **/
716static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
717{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800718 struct ixgbe_q_vector *q_vector;
719 int i, j, q_vectors, v_idx, r_idx;
720 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700721
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800722 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
723
724 /* Populate the IVAR table and set the ITR values to the
725 * corresponding register.
726 */
727 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
728 q_vector = &adapter->q_vector[v_idx];
729 /* XXX for_each_bit(...) */
730 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700731 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800732
733 for (i = 0; i < q_vector->rxr_count; i++) {
734 j = adapter->rx_ring[r_idx].reg_idx;
735 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(j), v_idx);
736 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700737 adapter->num_rx_queues,
738 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800739 }
740 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700741 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800742
743 for (i = 0; i < q_vector->txr_count; i++) {
744 j = adapter->tx_ring[r_idx].reg_idx;
745 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(j), v_idx);
746 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700747 adapter->num_tx_queues,
748 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800749 }
750
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700751 /* if this is a tx only vector halve the interrupt rate */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800752 if (q_vector->txr_count && !q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700753 q_vector->eitr = (adapter->eitr_param >> 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800754 else
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700755 /* rx only */
756 q_vector->eitr = adapter->eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800757
758 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx),
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700759 EITR_INTS_PER_SEC_TO_REG(q_vector->eitr));
Auke Kok9a799d72007-09-15 14:07:45 -0700760 }
761
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800762 ixgbe_set_ivar(adapter, IXGBE_IVAR_OTHER_CAUSES_INDEX, v_idx);
763 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -0700764
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700765 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800766 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700767 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800768 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -0700769}
770
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800771enum latency_range {
772 lowest_latency = 0,
773 low_latency = 1,
774 bulk_latency = 2,
775 latency_invalid = 255
776};
777
778/**
779 * ixgbe_update_itr - update the dynamic ITR value based on statistics
780 * @adapter: pointer to adapter
781 * @eitr: eitr setting (ints per sec) to give last timeslice
782 * @itr_setting: current throttle rate in ints/second
783 * @packets: the number of packets during this measurement interval
784 * @bytes: the number of bytes during this measurement interval
785 *
786 * Stores a new ITR value based on packets and byte
787 * counts during the last interrupt. The advantage of per interrupt
788 * computation is faster updates and more accurate ITR for the current
789 * traffic pattern. Constants in this function were computed
790 * based on theoretical maximum wire speed and thresholds were set based
791 * on testing data as well as attempting to minimize response time
792 * while increasing bulk throughput.
793 * this functionality is controlled by the InterruptThrottleRate module
794 * parameter (see ixgbe_param.c)
795 **/
796static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700797 u32 eitr, u8 itr_setting,
798 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800799{
800 unsigned int retval = itr_setting;
801 u32 timepassed_us;
802 u64 bytes_perint;
803
804 if (packets == 0)
805 goto update_itr_done;
806
807
808 /* simple throttlerate management
809 * 0-20MB/s lowest (100000 ints/s)
810 * 20-100MB/s low (20000 ints/s)
811 * 100-1249MB/s bulk (8000 ints/s)
812 */
813 /* what was last interrupt timeslice? */
814 timepassed_us = 1000000/eitr;
815 bytes_perint = bytes / timepassed_us; /* bytes/usec */
816
817 switch (itr_setting) {
818 case lowest_latency:
819 if (bytes_perint > adapter->eitr_low)
820 retval = low_latency;
821 break;
822 case low_latency:
823 if (bytes_perint > adapter->eitr_high)
824 retval = bulk_latency;
825 else if (bytes_perint <= adapter->eitr_low)
826 retval = lowest_latency;
827 break;
828 case bulk_latency:
829 if (bytes_perint <= adapter->eitr_high)
830 retval = low_latency;
831 break;
832 }
833
834update_itr_done:
835 return retval;
836}
837
838static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
839{
840 struct ixgbe_adapter *adapter = q_vector->adapter;
841 struct ixgbe_hw *hw = &adapter->hw;
842 u32 new_itr;
843 u8 current_itr, ret_itr;
844 int i, r_idx, v_idx = ((void *)q_vector - (void *)(adapter->q_vector)) /
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700845 sizeof(struct ixgbe_q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800846 struct ixgbe_ring *rx_ring, *tx_ring;
847
848 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
849 for (i = 0; i < q_vector->txr_count; i++) {
850 tx_ring = &(adapter->tx_ring[r_idx]);
851 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700852 q_vector->tx_itr,
853 tx_ring->total_packets,
854 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800855 /* if the result for this queue would decrease interrupt
856 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700857 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700858 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800859 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700860 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800861 }
862
863 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
864 for (i = 0; i < q_vector->rxr_count; i++) {
865 rx_ring = &(adapter->rx_ring[r_idx]);
866 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700867 q_vector->rx_itr,
868 rx_ring->total_packets,
869 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800870 /* if the result for this queue would decrease interrupt
871 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700872 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700873 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800874 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700875 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800876 }
877
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700878 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800879
880 switch (current_itr) {
881 /* counts and packets in update_itr are dependent on these numbers */
882 case lowest_latency:
883 new_itr = 100000;
884 break;
885 case low_latency:
886 new_itr = 20000; /* aka hwitr = ~200 */
887 break;
888 case bulk_latency:
889 default:
890 new_itr = 8000;
891 break;
892 }
893
894 if (new_itr != q_vector->eitr) {
895 u32 itr_reg;
896 /* do an exponential smoothing */
897 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
898 q_vector->eitr = new_itr;
899 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
900 /* must write high and low 16 bits to reset counter */
901 DPRINTK(TX_ERR, DEBUG, "writing eitr(%d): %08X\n", v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700902 itr_reg);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800903 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg | (itr_reg)<<16);
904 }
905
906 return;
907}
908
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700909static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
910{
911 struct ixgbe_hw *hw = &adapter->hw;
912
913 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
914 (eicr & IXGBE_EICR_GPI_SDP1)) {
915 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
916 /* write to clear the interrupt */
917 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
918 }
919}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -0700920
921static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
922{
923 struct ixgbe_hw *hw = &adapter->hw;
924
925 adapter->lsc_int++;
926 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
927 adapter->link_check_timeout = jiffies;
928 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
929 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
930 schedule_work(&adapter->watchdog_task);
931 }
932}
933
Auke Kok9a799d72007-09-15 14:07:45 -0700934static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
935{
936 struct net_device *netdev = data;
937 struct ixgbe_adapter *adapter = netdev_priv(netdev);
938 struct ixgbe_hw *hw = &adapter->hw;
939 u32 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
940
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -0700941 if (eicr & IXGBE_EICR_LSC)
942 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -0800943
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700944 ixgbe_check_fan_failure(adapter, eicr);
945
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -0800946 if (!test_bit(__IXGBE_DOWN, &adapter->state))
947 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -0700948
949 return IRQ_HANDLED;
950}
951
952static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
953{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800954 struct ixgbe_q_vector *q_vector = data;
955 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700956 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800957 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -0700958
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800959 if (!q_vector->txr_count)
960 return IRQ_HANDLED;
961
962 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
963 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700964 tx_ring = &(adapter->tx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400965#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800966 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700967 ixgbe_update_tx_dca(adapter, tx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800968#endif
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700969 tx_ring->total_bytes = 0;
970 tx_ring->total_packets = 0;
971 ixgbe_clean_tx_irq(adapter, tx_ring);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800972 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700973 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800974 }
975
Auke Kok9a799d72007-09-15 14:07:45 -0700976 return IRQ_HANDLED;
977}
978
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800979/**
980 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
981 * @irq: unused
982 * @data: pointer to our q_vector struct for this interrupt vector
983 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700984static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
985{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800986 struct ixgbe_q_vector *q_vector = data;
987 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700988 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800989 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700990 int i;
Auke Kok9a799d72007-09-15 14:07:45 -0700991
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800992 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700993 for (i = 0; i < q_vector->rxr_count; i++) {
994 rx_ring = &(adapter->rx_ring[r_idx]);
995 rx_ring->total_bytes = 0;
996 rx_ring->total_packets = 0;
997 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
998 r_idx + 1);
999 }
1000
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001001 if (!q_vector->rxr_count)
1002 return IRQ_HANDLED;
1003
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001004 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001005 rx_ring = &(adapter->rx_ring[r_idx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001006 /* disable interrupts on this vector only */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001007 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rx_ring->v_idx);
Ben Hutchings288379f2009-01-19 16:43:59 -08001008 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001009
Auke Kok9a799d72007-09-15 14:07:45 -07001010 return IRQ_HANDLED;
1011}
1012
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001013static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1014{
1015 ixgbe_msix_clean_rx(irq, data);
1016 ixgbe_msix_clean_tx(irq, data);
1017
1018 return IRQ_HANDLED;
1019}
1020
1021/**
1022 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1023 * @napi: napi struct with our devices info in it
1024 * @budget: amount of work driver is allowed to do this pass, in packets
1025 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001026 * This function is optimized for cleaning one queue only on a single
1027 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001028 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001029static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1030{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001031 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001032 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001033 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001034 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001035 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001036 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001037
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001038 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001039 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001040#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001041 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001042 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001043#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001044
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001045 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001046
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001047 /* If all Rx work done, exit the polling mode */
1048 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001049 napi_complete(napi);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001050 if (adapter->itr_setting & 3)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001051 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001052 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001053 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rx_ring->v_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07001054 }
1055
1056 return work_done;
1057}
1058
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001059/**
1060 * ixgbe_clean_rxonly_many - msix (aka one shot) rx clean routine
1061 * @napi: napi struct with our devices info in it
1062 * @budget: amount of work driver is allowed to do this pass, in packets
1063 *
1064 * This function will clean more than one rx queue associated with a
1065 * q_vector.
1066 **/
1067static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget)
1068{
1069 struct ixgbe_q_vector *q_vector =
1070 container_of(napi, struct ixgbe_q_vector, napi);
1071 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001072 struct ixgbe_ring *rx_ring = NULL;
1073 int work_done = 0, i;
1074 long r_idx;
1075 u16 enable_mask = 0;
1076
1077 /* attempt to distribute budget to each queue fairly, but don't allow
1078 * the budget to go below 1 because we'll exit polling */
1079 budget /= (q_vector->rxr_count ?: 1);
1080 budget = max(budget, 1);
1081 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1082 for (i = 0; i < q_vector->rxr_count; i++) {
1083 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001084#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001085 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1086 ixgbe_update_rx_dca(adapter, rx_ring);
1087#endif
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001088 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001089 enable_mask |= rx_ring->v_idx;
1090 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1091 r_idx + 1);
1092 }
1093
1094 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1095 rx_ring = &(adapter->rx_ring[r_idx]);
1096 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001097 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001098 napi_complete(napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001099 if (adapter->itr_setting & 3)
1100 ixgbe_set_itr_msix(q_vector);
1101 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1102 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, enable_mask);
1103 return 0;
1104 }
1105
1106 return work_done;
1107}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001108static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001109 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001110{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001111 a->q_vector[v_idx].adapter = a;
1112 set_bit(r_idx, a->q_vector[v_idx].rxr_idx);
1113 a->q_vector[v_idx].rxr_count++;
1114 a->rx_ring[r_idx].v_idx = 1 << v_idx;
1115}
Auke Kok9a799d72007-09-15 14:07:45 -07001116
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001117static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001118 int r_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001119{
1120 a->q_vector[v_idx].adapter = a;
1121 set_bit(r_idx, a->q_vector[v_idx].txr_idx);
1122 a->q_vector[v_idx].txr_count++;
1123 a->tx_ring[r_idx].v_idx = 1 << v_idx;
1124}
Auke Kok9a799d72007-09-15 14:07:45 -07001125
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001126/**
1127 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1128 * @adapter: board private structure to initialize
1129 * @vectors: allotted vector count for descriptor rings
1130 *
1131 * This function maps descriptor rings to the queue-specific vectors
1132 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1133 * one vector per ring/queue, but on a constrained vector budget, we
1134 * group the rings as "efficiently" as possible. You would add new
1135 * mapping configurations in here.
1136 **/
1137static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001138 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001139{
1140 int v_start = 0;
1141 int rxr_idx = 0, txr_idx = 0;
1142 int rxr_remaining = adapter->num_rx_queues;
1143 int txr_remaining = adapter->num_tx_queues;
1144 int i, j;
1145 int rqpv, tqpv;
1146 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001147
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001148 /* No mapping required if MSI-X is disabled. */
1149 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001150 goto out;
1151
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001152 /*
1153 * The ideal configuration...
1154 * We have enough vectors to map one per queue.
1155 */
1156 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1157 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1158 map_vector_to_rxq(adapter, v_start, rxr_idx);
1159
1160 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1161 map_vector_to_txq(adapter, v_start, txr_idx);
1162
1163 goto out;
1164 }
1165
1166 /*
1167 * If we don't have enough vectors for a 1-to-1
1168 * mapping, we'll have to group them so there are
1169 * multiple queues per vector.
1170 */
1171 /* Re-adjusting *qpv takes care of the remainder. */
1172 for (i = v_start; i < vectors; i++) {
1173 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1174 for (j = 0; j < rqpv; j++) {
1175 map_vector_to_rxq(adapter, i, rxr_idx);
1176 rxr_idx++;
1177 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001178 }
Auke Kok9a799d72007-09-15 14:07:45 -07001179 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001180 for (i = v_start; i < vectors; i++) {
1181 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1182 for (j = 0; j < tqpv; j++) {
1183 map_vector_to_txq(adapter, i, txr_idx);
1184 txr_idx++;
1185 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001186 }
Auke Kok9a799d72007-09-15 14:07:45 -07001187 }
1188
Auke Kok9a799d72007-09-15 14:07:45 -07001189out:
Auke Kok9a799d72007-09-15 14:07:45 -07001190 return err;
1191}
1192
1193/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001194 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1195 * @adapter: board private structure
1196 *
1197 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1198 * interrupts from the kernel.
1199 **/
1200static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1201{
1202 struct net_device *netdev = adapter->netdev;
1203 irqreturn_t (*handler)(int, void *);
1204 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001205 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001206
1207 /* Decrement for Other and TCP Timer vectors */
1208 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1209
1210 /* Map the Tx/Rx rings to the vectors we were allotted. */
1211 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1212 if (err)
1213 goto out;
1214
1215#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001216 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1217 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001218 for (vector = 0; vector < q_vectors; vector++) {
1219 handler = SET_HANDLER(&adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001220
1221 if(handler == &ixgbe_msix_clean_rx) {
1222 sprintf(adapter->name[vector], "%s-%s-%d",
1223 netdev->name, "rx", ri++);
1224 }
1225 else if(handler == &ixgbe_msix_clean_tx) {
1226 sprintf(adapter->name[vector], "%s-%s-%d",
1227 netdev->name, "tx", ti++);
1228 }
1229 else
1230 sprintf(adapter->name[vector], "%s-%s-%d",
1231 netdev->name, "TxRx", vector);
1232
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001233 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001234 handler, 0, adapter->name[vector],
1235 &(adapter->q_vector[vector]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001236 if (err) {
1237 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001238 "request_irq failed for MSIX interrupt "
1239 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001240 goto free_queue_irqs;
1241 }
1242 }
1243
1244 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1245 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001246 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001247 if (err) {
1248 DPRINTK(PROBE, ERR,
1249 "request_irq for msix_lsc failed: %d\n", err);
1250 goto free_queue_irqs;
1251 }
1252
1253 return 0;
1254
1255free_queue_irqs:
1256 for (i = vector - 1; i >= 0; i--)
1257 free_irq(adapter->msix_entries[--vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001258 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001259 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1260 pci_disable_msix(adapter->pdev);
1261 kfree(adapter->msix_entries);
1262 adapter->msix_entries = NULL;
1263out:
1264 return err;
1265}
1266
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001267static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1268{
1269 struct ixgbe_hw *hw = &adapter->hw;
1270 struct ixgbe_q_vector *q_vector = adapter->q_vector;
1271 u8 current_itr;
1272 u32 new_itr = q_vector->eitr;
1273 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1274 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1275
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001276 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001277 q_vector->tx_itr,
1278 tx_ring->total_packets,
1279 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001280 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001281 q_vector->rx_itr,
1282 rx_ring->total_packets,
1283 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001284
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001285 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001286
1287 switch (current_itr) {
1288 /* counts and packets in update_itr are dependent on these numbers */
1289 case lowest_latency:
1290 new_itr = 100000;
1291 break;
1292 case low_latency:
1293 new_itr = 20000; /* aka hwitr = ~200 */
1294 break;
1295 case bulk_latency:
1296 new_itr = 8000;
1297 break;
1298 default:
1299 break;
1300 }
1301
1302 if (new_itr != q_vector->eitr) {
1303 u32 itr_reg;
1304 /* do an exponential smoothing */
1305 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
1306 q_vector->eitr = new_itr;
1307 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
1308 /* must write high and low 16 bits to reset counter */
1309 IXGBE_WRITE_REG(hw, IXGBE_EITR(0), itr_reg | (itr_reg)<<16);
1310 }
1311
1312 return;
1313}
1314
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001315/**
1316 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1317 * @adapter: board private structure
1318 **/
1319static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1320{
1321 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1322 IXGBE_WRITE_FLUSH(&adapter->hw);
1323 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1324 int i;
1325 for (i = 0; i < adapter->num_msix_vectors; i++)
1326 synchronize_irq(adapter->msix_entries[i].vector);
1327 } else {
1328 synchronize_irq(adapter->pdev->irq);
1329 }
1330}
1331
1332/**
1333 * ixgbe_irq_enable - Enable default interrupt generation settings
1334 * @adapter: board private structure
1335 **/
1336static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1337{
1338 u32 mask;
1339 mask = IXGBE_EIMS_ENABLE_MASK;
David S. Miller6ab33d52008-11-20 16:44:00 -08001340 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1341 mask |= IXGBE_EIMS_GPI_SDP1;
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001342 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1343 IXGBE_WRITE_FLUSH(&adapter->hw);
1344}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001345
1346/**
1347 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001348 * @irq: interrupt number
1349 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001350 **/
1351static irqreturn_t ixgbe_intr(int irq, void *data)
1352{
1353 struct net_device *netdev = data;
1354 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1355 struct ixgbe_hw *hw = &adapter->hw;
1356 u32 eicr;
1357
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001358 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1359 * therefore no explict interrupt disable is necessary */
1360 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001361 if (!eicr) {
1362 /* shared interrupt alert!
1363 * make sure interrupts are enabled because the read will
1364 * have disabled interrupts due to EIAM */
1365 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001366 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001367 }
Auke Kok9a799d72007-09-15 14:07:45 -07001368
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001369 if (eicr & IXGBE_EICR_LSC)
1370 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001371
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001372 ixgbe_check_fan_failure(adapter, eicr);
1373
Ben Hutchings288379f2009-01-19 16:43:59 -08001374 if (napi_schedule_prep(&adapter->q_vector[0].napi)) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001375 adapter->tx_ring[0].total_packets = 0;
1376 adapter->tx_ring[0].total_bytes = 0;
1377 adapter->rx_ring[0].total_packets = 0;
1378 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001379 /* would disable interrupts here but EIAM disabled it */
Ben Hutchings288379f2009-01-19 16:43:59 -08001380 __napi_schedule(&adapter->q_vector[0].napi);
Auke Kok9a799d72007-09-15 14:07:45 -07001381 }
1382
1383 return IRQ_HANDLED;
1384}
1385
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001386static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1387{
1388 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1389
1390 for (i = 0; i < q_vectors; i++) {
1391 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
1392 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1393 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1394 q_vector->rxr_count = 0;
1395 q_vector->txr_count = 0;
1396 }
1397}
1398
Auke Kok9a799d72007-09-15 14:07:45 -07001399/**
1400 * ixgbe_request_irq - initialize interrupts
1401 * @adapter: board private structure
1402 *
1403 * Attempts to configure interrupts using the best available
1404 * capabilities of the hardware and kernel.
1405 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001406static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001407{
1408 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001409 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001410
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001411 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1412 err = ixgbe_request_msix_irqs(adapter);
1413 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1414 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001415 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001416 } else {
1417 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001418 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001419 }
1420
Auke Kok9a799d72007-09-15 14:07:45 -07001421 if (err)
1422 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1423
Auke Kok9a799d72007-09-15 14:07:45 -07001424 return err;
1425}
1426
1427static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1428{
1429 struct net_device *netdev = adapter->netdev;
1430
1431 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001432 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001433
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001434 q_vectors = adapter->num_msix_vectors;
1435
1436 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001437 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001438
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001439 i--;
1440 for (; i >= 0; i--) {
1441 free_irq(adapter->msix_entries[i].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001442 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001443 }
1444
1445 ixgbe_reset_q_vectors(adapter);
1446 } else {
1447 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001448 }
1449}
1450
1451/**
Auke Kok9a799d72007-09-15 14:07:45 -07001452 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1453 *
1454 **/
1455static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1456{
Auke Kok9a799d72007-09-15 14:07:45 -07001457 struct ixgbe_hw *hw = &adapter->hw;
1458
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001459 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001460 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001461
1462 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(0), 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001463 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(0), 0);
1464
1465 map_vector_to_rxq(adapter, 0, 0);
1466 map_vector_to_txq(adapter, 0, 0);
1467
1468 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001469}
1470
1471/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001472 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001473 * @adapter: board private structure
1474 *
1475 * Configure the Tx unit of the MAC after a reset.
1476 **/
1477static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1478{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001479 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001480 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001481 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001482
1483 /* Setup the HW Tx Head and Tail descriptor pointers */
1484 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001485 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1486 j = ring->reg_idx;
1487 tdba = ring->dma;
1488 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001489 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001490 (tdba & DMA_32BIT_MASK));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001491 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1492 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1493 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1494 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1495 adapter->tx_ring[i].head = IXGBE_TDH(j);
1496 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1497 /* Disable Tx Head Writeback RO bit, since this hoses
1498 * bookkeeping if things aren't delivered in order.
1499 */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001500 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001501 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001502 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001503 }
Auke Kok9a799d72007-09-15 14:07:45 -07001504}
1505
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001506#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07001507
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001508static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1509{
1510 struct ixgbe_ring *rx_ring;
1511 u32 srrctl;
1512 int queue0;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001513 unsigned long mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001514
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001515 /* program one srrctl register per VMDq index */
1516 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
1517 long shift, len;
1518 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1519 len = sizeof(adapter->ring_feature[RING_F_VMDQ].mask) * 8;
1520 shift = find_first_bit(&mask, len);
1521 queue0 = index & mask;
1522 index = (index & mask) >> shift;
1523 /* program one srrctl per RSS queue since RDRXCTL.MVMEN is enabled */
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001524 } else {
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001525 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1526 queue0 = index & mask;
1527 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001528 }
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001529
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001530 rx_ring = &adapter->rx_ring[queue0];
1531
1532 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1533
1534 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1535 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1536
1537 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1538 srrctl |= IXGBE_RXBUFFER_2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1539 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1540 srrctl |= ((IXGBE_RX_HDR_SIZE <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001541 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1542 IXGBE_SRRCTL_BSIZEHDR_MASK);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001543 } else {
1544 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1545
1546 if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1547 srrctl |= IXGBE_RXBUFFER_2048 >>
1548 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1549 else
1550 srrctl |= rx_ring->rx_buf_len >>
1551 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1552 }
1553 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1554}
1555
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001556#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001557 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001558
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001559/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001560 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001561 * @adapter: board private structure
1562 *
1563 * Configure the Rx unit of the MAC after a reset.
1564 **/
1565static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1566{
1567 u64 rdba;
1568 struct ixgbe_hw *hw = &adapter->hw;
1569 struct net_device *netdev = adapter->netdev;
1570 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001571 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001572 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001573 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1574 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1575 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001576 u32 fctrl, hlreg0;
Auke Kok9a799d72007-09-15 14:07:45 -07001577 u32 pages;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001578 u32 reta = 0, mrqc;
1579 u32 rdrxctl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001580 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07001581
1582 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001583 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07001584
1585 /* Set the RX buffer length according to the mode */
1586 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001587 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001588 } else {
1589 if (netdev->mtu <= ETH_DATA_LEN)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001590 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001591 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001592 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07001593 }
1594
1595 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1596 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001597 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
Auke Kok9a799d72007-09-15 14:07:45 -07001598 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1599
1600 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1601 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1602 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1603 else
1604 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1605 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1606
1607 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1608
Auke Kok9a799d72007-09-15 14:07:45 -07001609 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1610 /* disable receives while setting up the descriptors */
1611 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1612 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1613
1614 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1615 * the Base and Length of the Rx Descriptor Ring */
1616 for (i = 0; i < adapter->num_rx_queues; i++) {
1617 rdba = adapter->rx_ring[i].dma;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001618 j = adapter->rx_ring[i].reg_idx;
1619 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_32BIT_MASK));
1620 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
1621 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
1622 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
1623 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
1624 adapter->rx_ring[i].head = IXGBE_RDH(j);
1625 adapter->rx_ring[i].tail = IXGBE_RDT(j);
1626 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001627
1628 ixgbe_configure_srrctl(adapter, j);
Auke Kok9a799d72007-09-15 14:07:45 -07001629 }
1630
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001631 /*
1632 * For VMDq support of different descriptor types or
1633 * buffer sizes through the use of multiple SRRCTL
1634 * registers, RDRXCTL.MVMEN must be set to 1
1635 *
1636 * also, the manual doesn't mention it clearly but DCA hints
1637 * will only use queue 0's tags unless this bit is set. Side
1638 * effects of setting this bit are only that SRRCTL must be
1639 * fully programmed [0..15]
1640 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08001641 if (adapter->flags &
1642 (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_VMDQ_ENABLED)) {
1643 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1644 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
1645 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
1646 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001647
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001648 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07001649 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001650 for (i = 0, j = 0; i < 128; i++, j++) {
1651 if (j == adapter->ring_feature[RING_F_RSS].indices)
1652 j = 0;
1653 /* reta = 4-byte sliding window of
1654 * 0x00..(indices-1)(indices-1)00..etc. */
1655 reta = (reta << 8) | (j * 0x11);
1656 if ((i & 3) == 3)
1657 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07001658 }
1659
1660 /* Fill out hash function seeds */
1661 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001662 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07001663
1664 mrqc = IXGBE_MRQC_RSSEN
1665 /* Perform hash on these packet types */
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001666 | IXGBE_MRQC_RSS_FIELD_IPV4
1667 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1668 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1669 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
1670 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
1671 | IXGBE_MRQC_RSS_FIELD_IPV6
1672 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1673 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
1674 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07001675 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Auke Kok9a799d72007-09-15 14:07:45 -07001676 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001677
1678 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1679
1680 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
1681 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
1682 /* Disable indicating checksum in descriptor, enables
1683 * RSS hash */
1684 rxcsum |= IXGBE_RXCSUM_PCSD;
1685 }
1686 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
1687 /* Enable IPv4 payload checksum for UDP fragments
1688 * if PCSD is not set */
1689 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1690 }
1691
1692 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
Auke Kok9a799d72007-09-15 14:07:45 -07001693}
1694
Auke Kok9a799d72007-09-15 14:07:45 -07001695static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1696{
1697 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001698 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001699
1700 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001701 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07001702}
1703
1704static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1705{
1706 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001707 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001708
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001709 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1710 ixgbe_irq_disable(adapter);
1711
Auke Kok9a799d72007-09-15 14:07:45 -07001712 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001713
1714 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1715 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001716
1717 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001718 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07001719}
1720
Don Skidmore068c89b2009-01-19 16:54:36 -08001721static void ixgbe_vlan_rx_register(struct net_device *netdev,
1722 struct vlan_group *grp)
1723{
1724 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1725 u32 ctrl;
1726
1727 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1728 ixgbe_irq_disable(adapter);
1729 adapter->vlgrp = grp;
1730
1731 /*
1732 * For a DCB driver, always enable VLAN tag stripping so we can
1733 * still receive traffic from a DCB-enabled host even if we're
1734 * not in DCB mode.
1735 */
1736 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1737 ctrl |= IXGBE_VLNCTRL_VME;
1738 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1739 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1740 ixgbe_vlan_rx_add_vid(netdev, 0);
1741
1742 if (grp) {
1743 /* enable VLAN tag insert/strip */
1744 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1745 ctrl |= IXGBE_VLNCTRL_VME;
1746 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1747 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1748 }
1749
1750 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1751 ixgbe_irq_enable(adapter);
1752}
1753
Auke Kok9a799d72007-09-15 14:07:45 -07001754static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
1755{
1756 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1757
1758 if (adapter->vlgrp) {
1759 u16 vid;
1760 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1761 if (!vlan_group_get_device(adapter->vlgrp, vid))
1762 continue;
1763 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
1764 }
1765 }
1766}
1767
Christopher Leech2c5645c2008-08-26 04:27:02 -07001768static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
1769{
1770 struct dev_mc_list *mc_ptr;
1771 u8 *addr = *mc_addr_ptr;
1772 *vmdq = 0;
1773
1774 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
1775 if (mc_ptr->next)
1776 *mc_addr_ptr = mc_ptr->next->dmi_addr;
1777 else
1778 *mc_addr_ptr = NULL;
1779
1780 return addr;
1781}
1782
Auke Kok9a799d72007-09-15 14:07:45 -07001783/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07001784 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07001785 * @netdev: network interface device structure
1786 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07001787 * The set_rx_method entry point is called whenever the unicast/multicast
1788 * address list or the network interface flags are updated. This routine is
1789 * responsible for configuring the hardware for proper unicast, multicast and
1790 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07001791 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07001792static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001793{
1794 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1795 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07001796 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001797 u8 *addr_list = NULL;
1798 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001799
1800 /* Check for Promiscuous and All Multicast modes */
1801
1802 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07001803 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07001804
1805 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07001806 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001807 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07001808 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07001809 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07001810 if (netdev->flags & IFF_ALLMULTI) {
1811 fctrl |= IXGBE_FCTRL_MPE;
1812 fctrl &= ~IXGBE_FCTRL_UPE;
1813 } else {
1814 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1815 }
Alexander Duyck3d016252008-08-26 18:30:04 -07001816 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001817 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001818 }
1819
1820 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07001821 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001822
Christopher Leech2c5645c2008-08-26 04:27:02 -07001823 /* reprogram secondary unicast list */
1824 addr_count = netdev->uc_count;
1825 if (addr_count)
1826 addr_list = netdev->uc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001827 hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count,
1828 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07001829
Christopher Leech2c5645c2008-08-26 04:27:02 -07001830 /* reprogram multicast list */
1831 addr_count = netdev->mc_count;
1832 if (addr_count)
1833 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001834 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
1835 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07001836}
1837
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001838static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
1839{
1840 int q_idx;
1841 struct ixgbe_q_vector *q_vector;
1842 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1843
1844 /* legacy and MSI only use one vector */
1845 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1846 q_vectors = 1;
1847
1848 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001849 struct napi_struct *napi;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001850 q_vector = &adapter->q_vector[q_idx];
1851 if (!q_vector->rxr_count)
1852 continue;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001853 napi = &q_vector->napi;
1854 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) &&
1855 (q_vector->rxr_count > 1))
1856 napi->poll = &ixgbe_clean_rxonly_many;
1857
1858 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001859 }
1860}
1861
1862static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
1863{
1864 int q_idx;
1865 struct ixgbe_q_vector *q_vector;
1866 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1867
1868 /* legacy and MSI only use one vector */
1869 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1870 q_vectors = 1;
1871
1872 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1873 q_vector = &adapter->q_vector[q_idx];
1874 if (!q_vector->rxr_count)
1875 continue;
1876 napi_disable(&q_vector->napi);
1877 }
1878}
1879
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08001880#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08001881/*
1882 * ixgbe_configure_dcb - Configure DCB hardware
1883 * @adapter: ixgbe adapter struct
1884 *
1885 * This is called by the driver on open to configure the DCB hardware.
1886 * This is also called by the gennetlink interface when reconfiguring
1887 * the DCB state.
1888 */
1889static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
1890{
1891 struct ixgbe_hw *hw = &adapter->hw;
1892 u32 txdctl, vlnctrl;
1893 int i, j;
1894
1895 ixgbe_dcb_check_config(&adapter->dcb_cfg);
1896 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
1897 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
1898
1899 /* reconfigure the hardware */
1900 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
1901
1902 for (i = 0; i < adapter->num_tx_queues; i++) {
1903 j = adapter->tx_ring[i].reg_idx;
1904 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
1905 /* PThresh workaround for Tx hang with DFP enabled. */
1906 txdctl |= 32;
1907 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
1908 }
1909 /* Enable VLAN tag insert/strip */
1910 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1911 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
1912 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
1913 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1914 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
1915}
1916
1917#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001918static void ixgbe_configure(struct ixgbe_adapter *adapter)
1919{
1920 struct net_device *netdev = adapter->netdev;
1921 int i;
1922
Christopher Leech2c5645c2008-08-26 04:27:02 -07001923 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001924
1925 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08001926#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08001927 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
1928 netif_set_gso_max_size(netdev, 32768);
1929 ixgbe_configure_dcb(adapter);
1930 } else {
1931 netif_set_gso_max_size(netdev, 65536);
1932 }
1933#else
1934 netif_set_gso_max_size(netdev, 65536);
1935#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001936
1937 ixgbe_configure_tx(adapter);
1938 ixgbe_configure_rx(adapter);
1939 for (i = 0; i < adapter->num_rx_queues; i++)
1940 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001941 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07001942}
1943
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001944/**
1945 * ixgbe_link_config - set up initial link with default speed and duplex
1946 * @hw: pointer to private hardware struct
1947 *
1948 * Returns 0 on success, negative on failure
1949 **/
1950static int ixgbe_link_config(struct ixgbe_hw *hw)
1951{
1952 u32 autoneg;
1953 bool link_up = false;
1954 u32 ret = IXGBE_ERR_LINK_SETUP;
1955
1956 if (hw->mac.ops.check_link)
1957 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1958
1959 if (ret)
1960 goto link_cfg_out;
1961
1962 if (hw->mac.ops.get_link_capabilities)
1963 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
1964 &hw->mac.autoneg);
1965 if (ret)
1966 goto link_cfg_out;
1967
1968 if (hw->mac.ops.setup_link_speed)
1969 ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up);
1970
1971link_cfg_out:
1972 return ret;
1973}
1974
Auke Kok9a799d72007-09-15 14:07:45 -07001975static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
1976{
1977 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07001978 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001979 int i, j = 0;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001980 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001981 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001982 u32 txdctl, rxdctl, mhadd;
1983 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07001984
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08001985 ixgbe_get_hw_control(adapter);
1986
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001987 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
1988 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001989 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1990 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001991 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07001992 } else {
1993 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001994 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001995 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001996 /* XXX: to interrupt immediately for EICS writes, enable this */
1997 /* gpie |= IXGBE_GPIE_EIMEN; */
1998 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
1999 }
2000
2001 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2002 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2003 * specifically only auto mask tx and rx interrupts */
2004 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002005 }
2006
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002007 /* Enable fan failure interrupt if media type is copper */
2008 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2009 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2010 gpie |= IXGBE_SDP1_GPIEN;
2011 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2012 }
2013
Auke Kok9a799d72007-09-15 14:07:45 -07002014 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002015 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2016 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2017 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2018
2019 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2020 }
2021
2022 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002023 j = adapter->tx_ring[i].reg_idx;
2024 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002025 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2026 txdctl |= (8 << 16);
Auke Kok9a799d72007-09-15 14:07:45 -07002027 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002028 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002029 }
2030
2031 for (i = 0; i < adapter->num_rx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002032 j = adapter->rx_ring[i].reg_idx;
2033 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2034 /* enable PTHRESH=32 descriptors (half the internal cache)
2035 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2036 * this also removes a pesky rx_no_buffer_count increment */
2037 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002038 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002039 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002040 }
2041 /* enable all receives */
2042 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2043 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2044 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxdctl);
2045
2046 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2047 ixgbe_configure_msix(adapter);
2048 else
2049 ixgbe_configure_msi_and_legacy(adapter);
2050
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08002051 ixgbe_napi_add_all(adapter);
2052
Auke Kok9a799d72007-09-15 14:07:45 -07002053 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002054 ixgbe_napi_enable_all(adapter);
2055
2056 /* clear any pending interrupts, may auto mask */
2057 IXGBE_READ_REG(hw, IXGBE_EICR);
2058
Auke Kok9a799d72007-09-15 14:07:45 -07002059 ixgbe_irq_enable(adapter);
2060
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002061 err = ixgbe_link_config(hw);
2062 if (err)
2063 dev_err(&adapter->pdev->dev, "link_config FAILED %d\n", err);
2064
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002065 /* enable transmits */
2066 netif_tx_start_all_queues(netdev);
2067
Auke Kok9a799d72007-09-15 14:07:45 -07002068 /* bring the link up in the watchdog, this could race with our first
2069 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002070 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2071 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002072 mod_timer(&adapter->watchdog_timer, jiffies);
2073 return 0;
2074}
2075
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002076void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2077{
2078 WARN_ON(in_interrupt());
2079 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2080 msleep(1);
2081 ixgbe_down(adapter);
2082 ixgbe_up(adapter);
2083 clear_bit(__IXGBE_RESETTING, &adapter->state);
2084}
2085
Auke Kok9a799d72007-09-15 14:07:45 -07002086int ixgbe_up(struct ixgbe_adapter *adapter)
2087{
2088 /* hardware has been reset, we need to reload some things */
2089 ixgbe_configure(adapter);
2090
2091 return ixgbe_up_complete(adapter);
2092}
2093
2094void ixgbe_reset(struct ixgbe_adapter *adapter)
2095{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002096 struct ixgbe_hw *hw = &adapter->hw;
2097 if (hw->mac.ops.init_hw(hw))
2098 dev_err(&adapter->pdev->dev, "Hardware Error\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002099
2100 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002101 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002102
2103}
2104
Auke Kok9a799d72007-09-15 14:07:45 -07002105/**
2106 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2107 * @adapter: board private structure
2108 * @rx_ring: ring to free buffers from
2109 **/
2110static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002111 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002112{
2113 struct pci_dev *pdev = adapter->pdev;
2114 unsigned long size;
2115 unsigned int i;
2116
2117 /* Free all the Rx ring sk_buffs */
2118
2119 for (i = 0; i < rx_ring->count; i++) {
2120 struct ixgbe_rx_buffer *rx_buffer_info;
2121
2122 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2123 if (rx_buffer_info->dma) {
2124 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002125 rx_ring->rx_buf_len,
2126 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002127 rx_buffer_info->dma = 0;
2128 }
2129 if (rx_buffer_info->skb) {
2130 dev_kfree_skb(rx_buffer_info->skb);
2131 rx_buffer_info->skb = NULL;
2132 }
2133 if (!rx_buffer_info->page)
2134 continue;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002135 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2136 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002137 rx_buffer_info->page_dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002138 put_page(rx_buffer_info->page);
2139 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002140 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002141 }
2142
2143 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2144 memset(rx_ring->rx_buffer_info, 0, size);
2145
2146 /* Zero out the descriptor ring */
2147 memset(rx_ring->desc, 0, rx_ring->size);
2148
2149 rx_ring->next_to_clean = 0;
2150 rx_ring->next_to_use = 0;
2151
2152 writel(0, adapter->hw.hw_addr + rx_ring->head);
2153 writel(0, adapter->hw.hw_addr + rx_ring->tail);
2154}
2155
2156/**
2157 * ixgbe_clean_tx_ring - Free Tx Buffers
2158 * @adapter: board private structure
2159 * @tx_ring: ring to be cleaned
2160 **/
2161static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002162 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002163{
2164 struct ixgbe_tx_buffer *tx_buffer_info;
2165 unsigned long size;
2166 unsigned int i;
2167
2168 /* Free all the Tx ring sk_buffs */
2169
2170 for (i = 0; i < tx_ring->count; i++) {
2171 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2172 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2173 }
2174
2175 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2176 memset(tx_ring->tx_buffer_info, 0, size);
2177
2178 /* Zero out the descriptor ring */
2179 memset(tx_ring->desc, 0, tx_ring->size);
2180
2181 tx_ring->next_to_use = 0;
2182 tx_ring->next_to_clean = 0;
2183
2184 writel(0, adapter->hw.hw_addr + tx_ring->head);
2185 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2186}
2187
2188/**
Auke Kok9a799d72007-09-15 14:07:45 -07002189 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2190 * @adapter: board private structure
2191 **/
2192static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2193{
2194 int i;
2195
2196 for (i = 0; i < adapter->num_rx_queues; i++)
2197 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2198}
2199
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002200/**
2201 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2202 * @adapter: board private structure
2203 **/
2204static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2205{
2206 int i;
2207
2208 for (i = 0; i < adapter->num_tx_queues; i++)
2209 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2210}
2211
Auke Kok9a799d72007-09-15 14:07:45 -07002212void ixgbe_down(struct ixgbe_adapter *adapter)
2213{
2214 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002215 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002216 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002217 u32 txdctl;
2218 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002219
2220 /* signal that we are down to the interrupt handler */
2221 set_bit(__IXGBE_DOWN, &adapter->state);
2222
2223 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002224 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2225 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002226
2227 netif_tx_disable(netdev);
2228
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002229 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002230 msleep(10);
2231
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002232 netif_tx_stop_all_queues(netdev);
2233
Auke Kok9a799d72007-09-15 14:07:45 -07002234 ixgbe_irq_disable(adapter);
2235
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002236 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002237
Auke Kok9a799d72007-09-15 14:07:45 -07002238 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002239 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002240
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002241 /* disable transmits in the hardware now that interrupts are off */
2242 for (i = 0; i < adapter->num_tx_queues; i++) {
2243 j = adapter->tx_ring[i].reg_idx;
2244 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2245 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2246 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2247 }
2248
Auke Kok9a799d72007-09-15 14:07:45 -07002249 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002250
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002251#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002252 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2253 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
2254 dca_remove_requester(&adapter->pdev->dev);
2255 }
2256
2257#endif
Paul Larson6f4a0e42008-06-24 17:00:56 -07002258 if (!pci_channel_offline(adapter->pdev))
2259 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002260 ixgbe_clean_all_tx_rings(adapter);
2261 ixgbe_clean_all_rx_rings(adapter);
2262
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002263#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002264 /* since we reset the hardware DCA settings were cleared */
2265 if (dca_add_requester(&adapter->pdev->dev) == 0) {
2266 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
2267 /* always use CB2 mode, difference is masked
2268 * in the CB driver */
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002269 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002270 ixgbe_setup_dca(adapter);
2271 }
2272#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002273}
2274
Auke Kok9a799d72007-09-15 14:07:45 -07002275/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002276 * ixgbe_poll - NAPI Rx polling callback
2277 * @napi: structure for representing this polling device
2278 * @budget: how many packets driver is allowed to clean
2279 *
2280 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002281 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002282static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002283{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002284 struct ixgbe_q_vector *q_vector = container_of(napi,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002285 struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002286 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -07002287 int tx_cleaned, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002288
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002289#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002290 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2291 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2292 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2293 }
2294#endif
2295
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002296 tx_cleaned = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002297 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002298
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002299 if (tx_cleaned)
2300 work_done = budget;
2301
David S. Miller53e52c72008-01-07 21:06:12 -08002302 /* If budget not fully consumed, exit the polling mode */
2303 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002304 napi_complete(napi);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002305 if (adapter->itr_setting & 3)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002306 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002307 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2308 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002309 }
Auke Kok9a799d72007-09-15 14:07:45 -07002310 return work_done;
2311}
2312
2313/**
2314 * ixgbe_tx_timeout - Respond to a Tx Hang
2315 * @netdev: network interface device structure
2316 **/
2317static void ixgbe_tx_timeout(struct net_device *netdev)
2318{
2319 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2320
2321 /* Do the reset outside of interrupt context */
2322 schedule_work(&adapter->reset_task);
2323}
2324
2325static void ixgbe_reset_task(struct work_struct *work)
2326{
2327 struct ixgbe_adapter *adapter;
2328 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2329
Alexander Duyck2f90b862008-11-20 20:52:10 -08002330 /* If we're already down or resetting, just bail */
2331 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2332 test_bit(__IXGBE_RESETTING, &adapter->state))
2333 return;
2334
Auke Kok9a799d72007-09-15 14:07:45 -07002335 adapter->tx_timeout_count++;
2336
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002337 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002338}
2339
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002340#ifdef CONFIG_IXGBE_DCB
2341static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002342{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002343 bool ret = false;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002344
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002345 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2346 adapter->ring_feature[RING_F_DCB].mask = 0x7 << 3;
2347 adapter->num_rx_queues =
2348 adapter->ring_feature[RING_F_DCB].indices;
2349 adapter->num_tx_queues =
2350 adapter->ring_feature[RING_F_DCB].indices;
2351 ret = true;
2352 } else {
2353 adapter->ring_feature[RING_F_DCB].mask = 0;
2354 adapter->ring_feature[RING_F_DCB].indices = 0;
2355 ret = false;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002356 }
2357
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002358 return ret;
2359}
2360#endif
2361
2362static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
2363{
2364 bool ret = false;
2365
2366 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2367 adapter->ring_feature[RING_F_RSS].mask = 0xF;
2368 adapter->num_rx_queues =
2369 adapter->ring_feature[RING_F_RSS].indices;
2370 adapter->num_tx_queues =
2371 adapter->ring_feature[RING_F_RSS].indices;
2372 ret = true;
2373 } else {
2374 adapter->ring_feature[RING_F_RSS].mask = 0;
2375 adapter->ring_feature[RING_F_RSS].indices = 0;
2376 ret = false;
2377 }
2378
2379 return ret;
2380}
2381
2382static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2383{
2384 /* Start with base case */
2385 adapter->num_rx_queues = 1;
2386 adapter->num_tx_queues = 1;
2387
2388#ifdef CONFIG_IXGBE_DCB
2389 if (ixgbe_set_dcb_queues(adapter))
2390 return;
2391
2392#endif
2393 if (ixgbe_set_rss_queues(adapter))
2394 return;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002395}
2396
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002397static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002398 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002399{
2400 int err, vector_threshold;
2401
2402 /* We'll want at least 3 (vector_threshold):
2403 * 1) TxQ[0] Cleanup
2404 * 2) RxQ[0] Cleanup
2405 * 3) Other (Link Status Change, etc.)
2406 * 4) TCP Timer (optional)
2407 */
2408 vector_threshold = MIN_MSIX_COUNT;
2409
2410 /* The more we get, the more we will assign to Tx/Rx Cleanup
2411 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2412 * Right now, we simply care about how many we'll get; we'll
2413 * set them up later while requesting irq's.
2414 */
2415 while (vectors >= vector_threshold) {
2416 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002417 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002418 if (!err) /* Success in acquiring all requested vectors. */
2419 break;
2420 else if (err < 0)
2421 vectors = 0; /* Nasty failure, quit now */
2422 else /* err == number of vectors we should try again with */
2423 vectors = err;
2424 }
2425
2426 if (vectors < vector_threshold) {
2427 /* Can't allocate enough MSI-X interrupts? Oh well.
2428 * This just means we'll go with either a single MSI
2429 * vector or fall back to legacy interrupts.
2430 */
2431 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2432 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2433 kfree(adapter->msix_entries);
2434 adapter->msix_entries = NULL;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002435 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002436 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002437 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002438 } else {
2439 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08002440 /*
2441 * Adjust for only the vectors we'll use, which is minimum
2442 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
2443 * vectors we were allocated.
2444 */
2445 adapter->num_msix_vectors = min(vectors,
2446 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002447 }
2448}
2449
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002450/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002451 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002452 * @adapter: board private structure to initialize
2453 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002454 * Cache the descriptor ring offsets for RSS to the assigned rings.
2455 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002456 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002457static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002458{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002459 int i;
2460 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002461
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002462 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2463 for (i = 0; i < adapter->num_rx_queues; i++)
2464 adapter->rx_ring[i].reg_idx = i;
2465 for (i = 0; i < adapter->num_tx_queues; i++)
2466 adapter->tx_ring[i].reg_idx = i;
2467 ret = true;
2468 } else {
2469 ret = false;
2470 }
2471
2472 return ret;
2473}
2474
2475#ifdef CONFIG_IXGBE_DCB
2476/**
2477 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
2478 * @adapter: board private structure to initialize
2479 *
2480 * Cache the descriptor ring offsets for DCB to the assigned rings.
2481 *
2482 **/
2483static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
2484{
2485 int i;
2486 bool ret = false;
2487 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2488
2489 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2490 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002491 /* the number of queues is assumed to be symmetric */
2492 for (i = 0; i < dcb_i; i++) {
2493 adapter->rx_ring[i].reg_idx = i << 3;
2494 adapter->tx_ring[i].reg_idx = i << 2;
2495 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002496 ret = true;
2497 } else {
2498 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002499 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002500 } else {
2501 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002502 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002503
2504 return ret;
2505}
2506#endif
2507
2508/**
2509 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2510 * @adapter: board private structure to initialize
2511 *
2512 * Once we know the feature-set enabled for the device, we'll cache
2513 * the register offset the descriptor ring is assigned to.
2514 *
2515 * Note, the order the various feature calls is important. It must start with
2516 * the "most" features enabled at the same time, then trickle down to the
2517 * least amount of features turned on at once.
2518 **/
2519static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
2520{
2521 /* start with default case */
2522 adapter->rx_ring[0].reg_idx = 0;
2523 adapter->tx_ring[0].reg_idx = 0;
2524
2525#ifdef CONFIG_IXGBE_DCB
2526 if (ixgbe_cache_ring_dcb(adapter))
2527 return;
2528
2529#endif
2530 if (ixgbe_cache_ring_rss(adapter))
2531 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002532}
2533
Auke Kok9a799d72007-09-15 14:07:45 -07002534/**
2535 * ixgbe_alloc_queues - Allocate memory for all rings
2536 * @adapter: board private structure to initialize
2537 *
2538 * We allocate one ring per queue at run-time since we don't know the
Wang Chena4d2f342008-12-03 22:05:58 -08002539 * number of queues at compile-time.
Auke Kok9a799d72007-09-15 14:07:45 -07002540 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002541static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002542{
2543 int i;
2544
2545 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002546 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07002547 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002548 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07002549
2550 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002551 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002552 if (!adapter->rx_ring)
2553 goto err_rx_ring_allocation;
2554
2555 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002556 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002557 adapter->tx_ring[i].queue_index = i;
2558 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002559
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002560 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002561 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002562 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07002563 }
2564
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002565 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002566
2567 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002568
2569err_rx_ring_allocation:
2570 kfree(adapter->tx_ring);
2571err_tx_ring_allocation:
2572 return -ENOMEM;
2573}
2574
2575/**
2576 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
2577 * @adapter: board private structure to initialize
2578 *
2579 * Attempt to configure the interrupts using the best available
2580 * capabilities of the hardware and the kernel.
2581 **/
Al Virofeea6a52008-11-27 15:34:07 -08002582static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002583{
2584 int err = 0;
2585 int vector, v_budget;
2586
2587 /*
2588 * It's easy to be greedy for MSI-X vectors, but it really
2589 * doesn't do us much good if we have a lot more vectors
2590 * than CPU's. So let's be conservative and only ask for
2591 * (roughly) twice the number of vectors as there are CPU's.
2592 */
2593 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002594 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002595
2596 /*
2597 * At the same time, hardware can only support a maximum of
2598 * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq,
2599 * we can easily reach upwards of 64 Rx descriptor queues and
2600 * 32 Tx queues. Thus, we cap it off in those rare cases where
2601 * the cpu count also exceeds our vector limit.
2602 */
2603 v_budget = min(v_budget, MAX_MSIX_COUNT);
2604
2605 /* A failure in MSI-X entry allocation isn't fatal, but it does
2606 * mean we disable MSI-X capabilities of the adapter. */
2607 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002608 sizeof(struct msix_entry), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002609 if (!adapter->msix_entries) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002610 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002611 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2612 ixgbe_set_num_queues(adapter);
2613 kfree(adapter->tx_ring);
2614 kfree(adapter->rx_ring);
2615 err = ixgbe_alloc_queues(adapter);
2616 if (err) {
2617 DPRINTK(PROBE, ERR, "Unable to allocate memory "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002618 "for queues\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002619 goto out;
2620 }
2621
2622 goto try_msi;
2623 }
2624
2625 for (vector = 0; vector < v_budget; vector++)
2626 adapter->msix_entries[vector].entry = vector;
2627
2628 ixgbe_acquire_msix_vectors(adapter, v_budget);
2629
2630 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2631 goto out;
2632
2633try_msi:
2634 err = pci_enable_msi(adapter->pdev);
2635 if (!err) {
2636 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
2637 } else {
2638 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002639 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002640 /* reset err */
2641 err = 0;
2642 }
2643
2644out:
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08002645 /* Notify the stack of the (possibly) reduced Tx Queue count. */
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002646 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002647
2648 return err;
2649}
2650
Alexander Duyck2f90b862008-11-20 20:52:10 -08002651void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002652{
2653 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2654 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2655 pci_disable_msix(adapter->pdev);
2656 kfree(adapter->msix_entries);
2657 adapter->msix_entries = NULL;
2658 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2659 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
2660 pci_disable_msi(adapter->pdev);
2661 }
2662 return;
2663}
2664
2665/**
2666 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
2667 * @adapter: board private structure to initialize
2668 *
2669 * We determine which interrupt scheme to use based on...
2670 * - Kernel support (MSI, MSI-X)
2671 * - which can be user-defined (via MODULE_PARAM)
2672 * - Hardware queue count (num_*_queues)
2673 * - defined by miscellaneous hardware support/features (RSS, etc.)
2674 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002675int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002676{
2677 int err;
2678
2679 /* Number of supported queues */
2680 ixgbe_set_num_queues(adapter);
2681
2682 err = ixgbe_alloc_queues(adapter);
2683 if (err) {
2684 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
2685 goto err_alloc_queues;
2686 }
2687
2688 err = ixgbe_set_interrupt_capability(adapter);
2689 if (err) {
2690 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
2691 goto err_set_interrupt;
2692 }
2693
2694 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002695 "Tx Queue count = %u\n",
2696 (adapter->num_rx_queues > 1) ? "Enabled" :
2697 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002698
2699 set_bit(__IXGBE_DOWN, &adapter->state);
2700
2701 return 0;
2702
2703err_set_interrupt:
2704 kfree(adapter->tx_ring);
2705 kfree(adapter->rx_ring);
2706err_alloc_queues:
2707 return err;
Auke Kok9a799d72007-09-15 14:07:45 -07002708}
2709
2710/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08002711 * ixgbe_sfp_timer - worker thread to find a missing module
2712 * @data: pointer to our adapter struct
2713 **/
2714static void ixgbe_sfp_timer(unsigned long data)
2715{
2716 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
2717
2718 /* Do the sfp_timer outside of interrupt context due to the
2719 * delays that sfp+ detection requires
2720 */
2721 schedule_work(&adapter->sfp_task);
2722}
2723
2724/**
2725 * ixgbe_sfp_task - worker thread to find a missing module
2726 * @work: pointer to work_struct containing our data
2727 **/
2728static void ixgbe_sfp_task(struct work_struct *work)
2729{
2730 struct ixgbe_adapter *adapter = container_of(work,
2731 struct ixgbe_adapter,
2732 sfp_task);
2733 struct ixgbe_hw *hw = &adapter->hw;
2734
2735 if ((hw->phy.type == ixgbe_phy_nl) &&
2736 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
2737 s32 ret = hw->phy.ops.identify_sfp(hw);
2738 if (ret)
2739 goto reschedule;
2740 ret = hw->phy.ops.reset(hw);
2741 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2742 DPRINTK(PROBE, ERR, "failed to initialize because an "
2743 "unsupported SFP+ module type was detected.\n"
2744 "Reload the driver after installing a "
2745 "supported module.\n");
2746 unregister_netdev(adapter->netdev);
2747 } else {
2748 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
2749 hw->phy.sfp_type);
2750 }
2751 /* don't need this routine any more */
2752 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
2753 }
2754 return;
2755reschedule:
2756 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
2757 mod_timer(&adapter->sfp_timer,
2758 round_jiffies(jiffies + (2 * HZ)));
2759}
2760
2761/**
Auke Kok9a799d72007-09-15 14:07:45 -07002762 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
2763 * @adapter: board private structure to initialize
2764 *
2765 * ixgbe_sw_init initializes the Adapter private data structure.
2766 * Fields are initialized based on PCI device information and
2767 * OS network device settings (MTU size).
2768 **/
2769static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
2770{
2771 struct ixgbe_hw *hw = &adapter->hw;
2772 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002773 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002774#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002775 int j;
2776 struct tc_configuration *tc;
2777#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002778
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002779 /* PCI config space info */
2780
2781 hw->vendor_id = pdev->vendor;
2782 hw->device_id = pdev->device;
2783 hw->revision_id = pdev->revision;
2784 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2785 hw->subsystem_device_id = pdev->subsystem_device;
2786
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002787 /* Set capability flags */
2788 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
2789 adapter->ring_feature[RING_F_RSS].indices = rss;
2790 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002791 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08002792 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002793
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002794#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002795 /* Configure DCB traffic classes */
2796 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
2797 tc = &adapter->dcb_cfg.tc_config[j];
2798 tc->path[DCB_TX_CONFIG].bwg_id = 0;
2799 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
2800 tc->path[DCB_RX_CONFIG].bwg_id = 0;
2801 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
2802 tc->dcb_pfc = pfc_disabled;
2803 }
2804 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
2805 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
2806 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
2807 adapter->dcb_cfg.round_robin_enable = false;
2808 adapter->dcb_set_bitmap = 0x00;
2809 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
2810 adapter->ring_feature[RING_F_DCB].indices);
2811
2812#endif
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002813 if (hw->mac.ops.get_media_type &&
2814 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper))
2815 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Auke Kok9a799d72007-09-15 14:07:45 -07002816
2817 /* default flow control settings */
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002818 hw->fc.requested_mode = ixgbe_fc_none;
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07002819 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
2820 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
2821 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
2822 hw->fc.send_xon = true;
Auke Kok9a799d72007-09-15 14:07:45 -07002823
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002824 /* enable itr by default in dynamic mode */
2825 adapter->itr_setting = 1;
2826 adapter->eitr_param = 20000;
2827
2828 /* set defaults for eitr in MegaBytes */
2829 adapter->eitr_low = 10;
2830 adapter->eitr_high = 20;
2831
2832 /* set default ring sizes */
2833 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
2834 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
2835
Auke Kok9a799d72007-09-15 14:07:45 -07002836 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002837 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002838 dev_err(&pdev->dev, "EEPROM initialization failed\n");
2839 return -EIO;
2840 }
2841
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002842 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07002843 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
2844
Auke Kok9a799d72007-09-15 14:07:45 -07002845 set_bit(__IXGBE_DOWN, &adapter->state);
2846
2847 return 0;
2848}
2849
2850/**
2851 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
2852 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002853 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07002854 *
2855 * Return 0 on success, negative on failure
2856 **/
2857int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002858 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002859{
2860 struct pci_dev *pdev = adapter->pdev;
2861 int size;
2862
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002863 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2864 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002865 if (!tx_ring->tx_buffer_info)
2866 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002867 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07002868
2869 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08002870 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002871 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07002872
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002873 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
2874 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002875 if (!tx_ring->desc)
2876 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07002877
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002878 tx_ring->next_to_use = 0;
2879 tx_ring->next_to_clean = 0;
2880 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07002881 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002882
2883err:
2884 vfree(tx_ring->tx_buffer_info);
2885 tx_ring->tx_buffer_info = NULL;
2886 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
2887 "descriptor ring\n");
2888 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07002889}
2890
2891/**
Alexander Duyck69888672008-09-11 20:05:39 -07002892 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
2893 * @adapter: board private structure
2894 *
2895 * If this function returns with an error, then it's possible one or
2896 * more of the rings is populated (while the rest are not). It is the
2897 * callers duty to clean those orphaned rings.
2898 *
2899 * Return 0 on success, negative on failure
2900 **/
2901static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
2902{
2903 int i, err = 0;
2904
2905 for (i = 0; i < adapter->num_tx_queues; i++) {
2906 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
2907 if (!err)
2908 continue;
2909 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
2910 break;
2911 }
2912
2913 return err;
2914}
2915
2916/**
Auke Kok9a799d72007-09-15 14:07:45 -07002917 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
2918 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002919 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07002920 *
2921 * Returns 0 on success, negative on failure
2922 **/
2923int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002924 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002925{
2926 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002927 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002928
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002929 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2930 rx_ring->rx_buffer_info = vmalloc(size);
2931 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07002932 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002933 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002934 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07002935 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002936 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07002937
Auke Kok9a799d72007-09-15 14:07:45 -07002938 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002939 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
2940 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07002941
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002942 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07002943
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002944 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07002945 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002946 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002947 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002948 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07002949 }
2950
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002951 rx_ring->next_to_clean = 0;
2952 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002953
2954 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002955
2956alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002957 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07002958}
2959
2960/**
Alexander Duyck69888672008-09-11 20:05:39 -07002961 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
2962 * @adapter: board private structure
2963 *
2964 * If this function returns with an error, then it's possible one or
2965 * more of the rings is populated (while the rest are not). It is the
2966 * callers duty to clean those orphaned rings.
2967 *
2968 * Return 0 on success, negative on failure
2969 **/
2970
2971static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
2972{
2973 int i, err = 0;
2974
2975 for (i = 0; i < adapter->num_rx_queues; i++) {
2976 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
2977 if (!err)
2978 continue;
2979 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
2980 break;
2981 }
2982
2983 return err;
2984}
2985
2986/**
Auke Kok9a799d72007-09-15 14:07:45 -07002987 * ixgbe_free_tx_resources - Free Tx Resources per Queue
2988 * @adapter: board private structure
2989 * @tx_ring: Tx descriptor ring for a specific queue
2990 *
2991 * Free all transmit software resources
2992 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07002993void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
2994 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002995{
2996 struct pci_dev *pdev = adapter->pdev;
2997
2998 ixgbe_clean_tx_ring(adapter, tx_ring);
2999
3000 vfree(tx_ring->tx_buffer_info);
3001 tx_ring->tx_buffer_info = NULL;
3002
3003 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
3004
3005 tx_ring->desc = NULL;
3006}
3007
3008/**
3009 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
3010 * @adapter: board private structure
3011 *
3012 * Free all transmit software resources
3013 **/
3014static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
3015{
3016 int i;
3017
3018 for (i = 0; i < adapter->num_tx_queues; i++)
3019 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
3020}
3021
3022/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003023 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07003024 * @adapter: board private structure
3025 * @rx_ring: ring to clean the resources from
3026 *
3027 * Free all receive software resources
3028 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003029void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
3030 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003031{
3032 struct pci_dev *pdev = adapter->pdev;
3033
3034 ixgbe_clean_rx_ring(adapter, rx_ring);
3035
3036 vfree(rx_ring->rx_buffer_info);
3037 rx_ring->rx_buffer_info = NULL;
3038
3039 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
3040
3041 rx_ring->desc = NULL;
3042}
3043
3044/**
3045 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
3046 * @adapter: board private structure
3047 *
3048 * Free all receive software resources
3049 **/
3050static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
3051{
3052 int i;
3053
3054 for (i = 0; i < adapter->num_rx_queues; i++)
3055 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
3056}
3057
3058/**
Auke Kok9a799d72007-09-15 14:07:45 -07003059 * ixgbe_change_mtu - Change the Maximum Transfer Unit
3060 * @netdev: network interface device structure
3061 * @new_mtu: new value for maximum frame size
3062 *
3063 * Returns 0 on success, negative on failure
3064 **/
3065static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
3066{
3067 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3068 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3069
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07003070 /* MTU < 68 is an error and causes problems on some kernels */
3071 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07003072 return -EINVAL;
3073
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003074 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003075 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003076 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07003077 netdev->mtu = new_mtu;
3078
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003079 if (netif_running(netdev))
3080 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003081
3082 return 0;
3083}
3084
3085/**
3086 * ixgbe_open - Called when a network interface is made active
3087 * @netdev: network interface device structure
3088 *
3089 * Returns 0 on success, negative value on failure
3090 *
3091 * The open entry point is called when a network interface is made
3092 * active by the system (IFF_UP). At this point all resources needed
3093 * for transmit and receive operations are allocated, the interrupt
3094 * handler is registered with the OS, the watchdog timer is started,
3095 * and the stack is notified that the interface is ready.
3096 **/
3097static int ixgbe_open(struct net_device *netdev)
3098{
3099 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3100 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003101
Auke Kok4bebfaa2008-02-11 09:26:01 -08003102 /* disallow open during test */
3103 if (test_bit(__IXGBE_TESTING, &adapter->state))
3104 return -EBUSY;
3105
Auke Kok9a799d72007-09-15 14:07:45 -07003106 /* allocate transmit descriptors */
3107 err = ixgbe_setup_all_tx_resources(adapter);
3108 if (err)
3109 goto err_setup_tx;
3110
Auke Kok9a799d72007-09-15 14:07:45 -07003111 /* allocate receive descriptors */
3112 err = ixgbe_setup_all_rx_resources(adapter);
3113 if (err)
3114 goto err_setup_rx;
3115
3116 ixgbe_configure(adapter);
3117
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003118 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003119 if (err)
3120 goto err_req_irq;
3121
Auke Kok9a799d72007-09-15 14:07:45 -07003122 err = ixgbe_up_complete(adapter);
3123 if (err)
3124 goto err_up;
3125
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003126 netif_tx_start_all_queues(netdev);
3127
Auke Kok9a799d72007-09-15 14:07:45 -07003128 return 0;
3129
3130err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003131 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003132 ixgbe_free_irq(adapter);
3133err_req_irq:
3134 ixgbe_free_all_rx_resources(adapter);
3135err_setup_rx:
3136 ixgbe_free_all_tx_resources(adapter);
3137err_setup_tx:
3138 ixgbe_reset(adapter);
3139
3140 return err;
3141}
3142
3143/**
3144 * ixgbe_close - Disables a network interface
3145 * @netdev: network interface device structure
3146 *
3147 * Returns 0, this is not allowed to fail
3148 *
3149 * The close entry point is called when an interface is de-activated
3150 * by the OS. The hardware is still under the drivers control, but
3151 * needs to be disabled. A global MAC reset is issued to stop the
3152 * hardware, and all transmit and receive resources are freed.
3153 **/
3154static int ixgbe_close(struct net_device *netdev)
3155{
3156 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003157
3158 ixgbe_down(adapter);
3159 ixgbe_free_irq(adapter);
3160
3161 ixgbe_free_all_tx_resources(adapter);
3162 ixgbe_free_all_rx_resources(adapter);
3163
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003164 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003165
3166 return 0;
3167}
3168
3169/**
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003170 * ixgbe_napi_add_all - prep napi structs for use
3171 * @adapter: private struct
3172 * helper function to napi_add each possible q_vector->napi
3173 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08003174void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003175{
3176 int q_idx, q_vectors;
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003177 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003178 int (*poll)(struct napi_struct *, int);
3179
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003180 /* check if we already have our netdev->napi_list populated */
3181 if (&netdev->napi_list != netdev->napi_list.next)
3182 return;
3183
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003184 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3185 poll = &ixgbe_clean_rxonly;
3186 /* Only enable as many vectors as we have rx queues. */
3187 q_vectors = adapter->num_rx_queues;
3188 } else {
3189 poll = &ixgbe_poll;
3190 /* only one q_vector for legacy modes */
3191 q_vectors = 1;
3192 }
3193
3194 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3195 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3196 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
3197 }
3198}
3199
Alexander Duyck2f90b862008-11-20 20:52:10 -08003200void ixgbe_napi_del_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003201{
3202 int q_idx;
3203 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3204
3205 /* legacy and MSI only use one vector */
3206 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3207 q_vectors = 1;
3208
3209 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3210 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3211 if (!q_vector->rxr_count)
3212 continue;
3213 netif_napi_del(&q_vector->napi);
3214 }
3215}
3216
3217#ifdef CONFIG_PM
3218static int ixgbe_resume(struct pci_dev *pdev)
3219{
3220 struct net_device *netdev = pci_get_drvdata(pdev);
3221 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3222 u32 err;
3223
3224 pci_set_power_state(pdev, PCI_D0);
3225 pci_restore_state(pdev);
3226 err = pci_enable_device(pdev);
3227 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07003228 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003229 "suspend\n");
3230 return err;
3231 }
3232 pci_set_master(pdev);
3233
3234 pci_enable_wake(pdev, PCI_D3hot, 0);
3235 pci_enable_wake(pdev, PCI_D3cold, 0);
3236
3237 err = ixgbe_init_interrupt_scheme(adapter);
3238 if (err) {
3239 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
3240 "device\n");
3241 return err;
3242 }
3243
3244 ixgbe_napi_add_all(adapter);
3245 ixgbe_reset(adapter);
3246
3247 if (netif_running(netdev)) {
3248 err = ixgbe_open(adapter->netdev);
3249 if (err)
3250 return err;
3251 }
3252
3253 netif_device_attach(netdev);
3254
3255 return 0;
3256}
3257
3258#endif /* CONFIG_PM */
3259static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
3260{
3261 struct net_device *netdev = pci_get_drvdata(pdev);
3262 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3263#ifdef CONFIG_PM
3264 int retval = 0;
3265#endif
3266
3267 netif_device_detach(netdev);
3268
3269 if (netif_running(netdev)) {
3270 ixgbe_down(adapter);
3271 ixgbe_free_irq(adapter);
3272 ixgbe_free_all_tx_resources(adapter);
3273 ixgbe_free_all_rx_resources(adapter);
3274 }
3275 ixgbe_reset_interrupt_capability(adapter);
3276 ixgbe_napi_del_all(adapter);
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003277 INIT_LIST_HEAD(&netdev->napi_list);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003278 kfree(adapter->tx_ring);
3279 kfree(adapter->rx_ring);
3280
3281#ifdef CONFIG_PM
3282 retval = pci_save_state(pdev);
3283 if (retval)
3284 return retval;
3285#endif
3286
3287 pci_enable_wake(pdev, PCI_D3hot, 0);
3288 pci_enable_wake(pdev, PCI_D3cold, 0);
3289
3290 ixgbe_release_hw_control(adapter);
3291
3292 pci_disable_device(pdev);
3293
3294 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3295
3296 return 0;
3297}
3298
3299static void ixgbe_shutdown(struct pci_dev *pdev)
3300{
3301 ixgbe_suspend(pdev, PMSG_SUSPEND);
3302}
3303
3304/**
Auke Kok9a799d72007-09-15 14:07:45 -07003305 * ixgbe_update_stats - Update the board statistics counters.
3306 * @adapter: board private structure
3307 **/
3308void ixgbe_update_stats(struct ixgbe_adapter *adapter)
3309{
3310 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003311 u64 total_mpc = 0;
3312 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003313
3314 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003315 for (i = 0; i < 8; i++) {
3316 /* for packet buffers not used, the register should read 0 */
3317 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
3318 missed_rx += mpc;
3319 adapter->stats.mpc[i] += mpc;
3320 total_mpc += adapter->stats.mpc[i];
3321 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08003322 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
3323 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
3324 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
3325 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
3326 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3327 IXGBE_PXONRXC(i));
3328 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
3329 IXGBE_PXONTXC(i));
3330 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3331 IXGBE_PXOFFRXC(i));
3332 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
3333 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003334 }
3335 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
3336 /* work around hardware counting issue */
3337 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07003338
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003339 /* 82598 hardware only has a 32 bit counter in the high register */
Auke Kok9a799d72007-09-15 14:07:45 -07003340 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003341 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
3342 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
Auke Kok9a799d72007-09-15 14:07:45 -07003343 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
3344 adapter->stats.bprc += bprc;
3345 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
3346 adapter->stats.mprc -= bprc;
3347 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
3348 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
3349 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
3350 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
3351 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
3352 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
3353 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003354 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
3355 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Auke Kok9a799d72007-09-15 14:07:45 -07003356 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003357 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
3358 adapter->stats.lxontxc += lxon;
3359 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
3360 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07003361 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3362 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003363 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
3364 /*
3365 * 82598 errata - tx of flow control packets is included in tx counters
3366 */
3367 xon_off_tot = lxon + lxoff;
3368 adapter->stats.gptc -= xon_off_tot;
3369 adapter->stats.mptc -= xon_off_tot;
3370 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07003371 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3372 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
3373 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07003374 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
3375 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003376 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003377 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3378 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3379 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3380 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3381 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003382 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3383
3384 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07003385 adapter->net_stats.multicast = adapter->stats.mprc;
3386
3387 /* Rx Errors */
3388 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003389 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07003390 adapter->net_stats.rx_dropped = 0;
3391 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3392 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003393 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07003394}
3395
3396/**
3397 * ixgbe_watchdog - Timer Call-back
3398 * @data: pointer to adapter cast into an unsigned long
3399 **/
3400static void ixgbe_watchdog(unsigned long data)
3401{
3402 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003403 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003404
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003405 /* Do the watchdog outside of interrupt context due to the lovely
3406 * delays that some of the newer hardware requires */
3407 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
3408 /* Cause software interrupt to ensure rx rings are cleaned */
3409 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3410 u32 eics =
3411 (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1;
3412 IXGBE_WRITE_REG(hw, IXGBE_EICS, eics);
3413 } else {
3414 /* For legacy and MSI interrupts don't set any bits that
3415 * are enabled for EIAM, because this operation would
3416 * set *both* EIMS and EICS for any bit in EIAM */
3417 IXGBE_WRITE_REG(hw, IXGBE_EICS,
3418 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
3419 }
3420 /* Reset the timer */
3421 mod_timer(&adapter->watchdog_timer,
3422 round_jiffies(jiffies + 2 * HZ));
3423 }
3424
3425 schedule_work(&adapter->watchdog_task);
3426}
3427
3428/**
Alexander Duyck69888672008-09-11 20:05:39 -07003429 * ixgbe_watchdog_task - worker thread to bring link up
3430 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003431 **/
3432static void ixgbe_watchdog_task(struct work_struct *work)
3433{
3434 struct ixgbe_adapter *adapter = container_of(work,
3435 struct ixgbe_adapter,
3436 watchdog_task);
3437 struct net_device *netdev = adapter->netdev;
3438 struct ixgbe_hw *hw = &adapter->hw;
3439 u32 link_speed = adapter->link_speed;
3440 bool link_up = adapter->link_up;
3441
3442 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
3443
3444 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3445 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
3446 if (link_up ||
3447 time_after(jiffies, (adapter->link_check_timeout +
3448 IXGBE_TRY_LINK_TIMEOUT))) {
3449 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
3450 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
3451 }
3452 adapter->link_up = link_up;
3453 adapter->link_speed = link_speed;
3454 }
Auke Kok9a799d72007-09-15 14:07:45 -07003455
3456 if (link_up) {
3457 if (!netif_carrier_ok(netdev)) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003458 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3459 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
Auke Kok9a799d72007-09-15 14:07:45 -07003460#define FLOW_RX (frctl & IXGBE_FCTRL_RFCE)
3461#define FLOW_TX (rmcs & IXGBE_RMCS_TFCE_802_3X)
Jeff Kirshera46e5342008-11-27 00:22:21 -08003462 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
3463 "Flow Control: %s\n",
3464 netdev->name,
3465 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
3466 "10 Gbps" :
3467 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
3468 "1 Gbps" : "unknown speed")),
3469 ((FLOW_RX && FLOW_TX) ? "RX/TX" :
3470 (FLOW_RX ? "RX" :
3471 (FLOW_TX ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07003472
3473 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003474 } else {
3475 /* Force detection of hung controller */
3476 adapter->detect_tx_hung = true;
3477 }
3478 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003479 adapter->link_up = false;
3480 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003481 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08003482 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
3483 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07003484 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003485 }
3486 }
3487
3488 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003489 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07003490}
3491
Auke Kok9a799d72007-09-15 14:07:45 -07003492static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003493 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
3494 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07003495{
3496 struct ixgbe_adv_tx_context_desc *context_desc;
3497 unsigned int i;
3498 int err;
3499 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003500 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
3501 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07003502
3503 if (skb_is_gso(skb)) {
3504 if (skb_header_cloned(skb)) {
3505 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3506 if (err)
3507 return err;
3508 }
3509 l4len = tcp_hdrlen(skb);
3510 *hdr_len += l4len;
3511
Al Viro8327d002007-12-10 18:54:12 +00003512 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003513 struct iphdr *iph = ip_hdr(skb);
3514 iph->tot_len = 0;
3515 iph->check = 0;
3516 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003517 iph->daddr, 0,
3518 IPPROTO_TCP,
3519 0);
Auke Kok9a799d72007-09-15 14:07:45 -07003520 adapter->hw_tso_ctxt++;
3521 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3522 ipv6_hdr(skb)->payload_len = 0;
3523 tcp_hdr(skb)->check =
3524 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003525 &ipv6_hdr(skb)->daddr,
3526 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07003527 adapter->hw_tso6_ctxt++;
3528 }
3529
3530 i = tx_ring->next_to_use;
3531
3532 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3533 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3534
3535 /* VLAN MACLEN IPLEN */
3536 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3537 vlan_macip_lens |=
3538 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3539 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003540 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003541 *hdr_len += skb_network_offset(skb);
3542 vlan_macip_lens |=
3543 (skb_transport_header(skb) - skb_network_header(skb));
3544 *hdr_len +=
3545 (skb_transport_header(skb) - skb_network_header(skb));
3546 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3547 context_desc->seqnum_seed = 0;
3548
3549 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003550 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003551 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07003552
Al Viro8327d002007-12-10 18:54:12 +00003553 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07003554 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3555 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3556 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3557
3558 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003559 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07003560 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
3561 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003562 /* use index 1 for TSO */
3563 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003564 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
3565
3566 tx_buffer_info->time_stamp = jiffies;
3567 tx_buffer_info->next_to_watch = i;
3568
3569 i++;
3570 if (i == tx_ring->count)
3571 i = 0;
3572 tx_ring->next_to_use = i;
3573
3574 return true;
3575 }
3576 return false;
3577}
3578
3579static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003580 struct ixgbe_ring *tx_ring,
3581 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07003582{
3583 struct ixgbe_adv_tx_context_desc *context_desc;
3584 unsigned int i;
3585 struct ixgbe_tx_buffer *tx_buffer_info;
3586 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3587
3588 if (skb->ip_summed == CHECKSUM_PARTIAL ||
3589 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
3590 i = tx_ring->next_to_use;
3591 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3592 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3593
3594 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3595 vlan_macip_lens |=
3596 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3597 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003598 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003599 if (skb->ip_summed == CHECKSUM_PARTIAL)
3600 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003601 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07003602
3603 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3604 context_desc->seqnum_seed = 0;
3605
3606 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003607 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07003608
3609 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08003610 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08003611 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07003612 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08003613 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3614 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003615 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08003616 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08003617 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08003618 /* XXX what about other V6 headers?? */
3619 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3620 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003621 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08003622 break;
Auke Kok41825d72008-02-12 15:20:33 -08003623 default:
3624 if (unlikely(net_ratelimit())) {
3625 DPRINTK(PROBE, WARNING,
3626 "partial checksum but proto=%x!\n",
3627 skb->protocol);
3628 }
3629 break;
3630 }
Auke Kok9a799d72007-09-15 14:07:45 -07003631 }
3632
3633 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003634 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07003635 context_desc->mss_l4len_idx = 0;
3636
3637 tx_buffer_info->time_stamp = jiffies;
3638 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003639
Auke Kok9a799d72007-09-15 14:07:45 -07003640 adapter->hw_csum_tx_good++;
3641 i++;
3642 if (i == tx_ring->count)
3643 i = 0;
3644 tx_ring->next_to_use = i;
3645
3646 return true;
3647 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003648
Auke Kok9a799d72007-09-15 14:07:45 -07003649 return false;
3650}
3651
3652static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003653 struct ixgbe_ring *tx_ring,
3654 struct sk_buff *skb, unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07003655{
3656 struct ixgbe_tx_buffer *tx_buffer_info;
3657 unsigned int len = skb->len;
3658 unsigned int offset = 0, size, count = 0, i;
3659 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3660 unsigned int f;
3661
3662 len -= skb->data_len;
3663
3664 i = tx_ring->next_to_use;
3665
3666 while (len) {
3667 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3668 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3669
3670 tx_buffer_info->length = size;
3671 tx_buffer_info->dma = pci_map_single(adapter->pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003672 skb->data + offset,
3673 size, PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003674 tx_buffer_info->time_stamp = jiffies;
3675 tx_buffer_info->next_to_watch = i;
3676
3677 len -= size;
3678 offset += size;
3679 count++;
3680 i++;
3681 if (i == tx_ring->count)
3682 i = 0;
3683 }
3684
3685 for (f = 0; f < nr_frags; f++) {
3686 struct skb_frag_struct *frag;
3687
3688 frag = &skb_shinfo(skb)->frags[f];
3689 len = frag->size;
3690 offset = frag->page_offset;
3691
3692 while (len) {
3693 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3694 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3695
3696 tx_buffer_info->length = size;
3697 tx_buffer_info->dma = pci_map_page(adapter->pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003698 frag->page,
3699 offset,
3700 size,
3701 PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003702 tx_buffer_info->time_stamp = jiffies;
3703 tx_buffer_info->next_to_watch = i;
3704
3705 len -= size;
3706 offset += size;
3707 count++;
3708 i++;
3709 if (i == tx_ring->count)
3710 i = 0;
3711 }
3712 }
3713 if (i == 0)
3714 i = tx_ring->count - 1;
3715 else
3716 i = i - 1;
3717 tx_ring->tx_buffer_info[i].skb = skb;
3718 tx_ring->tx_buffer_info[first].next_to_watch = i;
3719
3720 return count;
3721}
3722
3723static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003724 struct ixgbe_ring *tx_ring,
3725 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07003726{
3727 union ixgbe_adv_tx_desc *tx_desc = NULL;
3728 struct ixgbe_tx_buffer *tx_buffer_info;
3729 u32 olinfo_status = 0, cmd_type_len = 0;
3730 unsigned int i;
3731 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
3732
3733 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
3734
3735 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
3736
3737 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3738 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
3739
3740 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
3741 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
3742
3743 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003744 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003745
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003746 /* use index 1 context for tso */
3747 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003748 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
3749 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003750 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003751
3752 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
3753 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003754 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003755
3756 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
3757
3758 i = tx_ring->next_to_use;
3759 while (count--) {
3760 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3761 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
3762 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
3763 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003764 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07003765 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07003766 i++;
3767 if (i == tx_ring->count)
3768 i = 0;
3769 }
3770
3771 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
3772
3773 /*
3774 * Force memory writes to complete before letting h/w
3775 * know there are new descriptors to fetch. (Only
3776 * applicable for weak-ordered memory model archs,
3777 * such as IA-64).
3778 */
3779 wmb();
3780
3781 tx_ring->next_to_use = i;
3782 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3783}
3784
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003785static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003786 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003787{
3788 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3789
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003790 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003791 /* Herbert's original patch had:
3792 * smp_mb__after_netif_stop_queue();
3793 * but since that doesn't exist yet, just open code it. */
3794 smp_mb();
3795
3796 /* We need to check again in a case another CPU has just
3797 * made room available. */
3798 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
3799 return -EBUSY;
3800
3801 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07003802 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003803 ++adapter->restart_queue;
3804 return 0;
3805}
3806
3807static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003808 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003809{
3810 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
3811 return 0;
3812 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
3813}
3814
Auke Kok9a799d72007-09-15 14:07:45 -07003815static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3816{
3817 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3818 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07003819 unsigned int first;
3820 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003821 u8 hdr_len = 0;
3822 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07003823 int count = 0;
3824 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003825
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003826 r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003827 tx_ring = &adapter->tx_ring[r_idx];
Auke Kok9a799d72007-09-15 14:07:45 -07003828
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003829 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3830 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003831 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3832 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
3833 tx_flags |= (skb->queue_mapping << 13);
3834 }
3835 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3836 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3837 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3838 tx_flags |= (skb->queue_mapping << 13);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003839 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3840 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07003841 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003842 /* three things can cause us to need a context descriptor */
3843 if (skb_is_gso(skb) ||
3844 (skb->ip_summed == CHECKSUM_PARTIAL) ||
3845 (tx_flags & IXGBE_TX_FLAGS_VLAN))
Auke Kok9a799d72007-09-15 14:07:45 -07003846 count++;
3847
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003848 count += TXD_USE_COUNT(skb_headlen(skb));
3849 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07003850 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
3851
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003852 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003853 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07003854 return NETDEV_TX_BUSY;
3855 }
Auke Kok9a799d72007-09-15 14:07:45 -07003856
Al Viro8327d002007-12-10 18:54:12 +00003857 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07003858 tx_flags |= IXGBE_TX_FLAGS_IPV4;
3859 first = tx_ring->next_to_use;
3860 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
3861 if (tso < 0) {
3862 dev_kfree_skb_any(skb);
3863 return NETDEV_TX_OK;
3864 }
3865
3866 if (tso)
3867 tx_flags |= IXGBE_TX_FLAGS_TSO;
3868 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003869 (skb->ip_summed == CHECKSUM_PARTIAL))
Auke Kok9a799d72007-09-15 14:07:45 -07003870 tx_flags |= IXGBE_TX_FLAGS_CSUM;
3871
3872 ixgbe_tx_queue(adapter, tx_ring, tx_flags,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003873 ixgbe_tx_map(adapter, tx_ring, skb, first),
3874 skb->len, hdr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07003875
3876 netdev->trans_start = jiffies;
3877
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003878 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07003879
3880 return NETDEV_TX_OK;
3881}
3882
3883/**
3884 * ixgbe_get_stats - Get System Network Statistics
3885 * @netdev: network interface device structure
3886 *
3887 * Returns the address of the device statistics structure.
3888 * The statistics are actually updated from the timer callback.
3889 **/
3890static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
3891{
3892 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3893
3894 /* only return the current stats */
3895 return &adapter->net_stats;
3896}
3897
3898/**
3899 * ixgbe_set_mac - Change the Ethernet Address of the NIC
3900 * @netdev: network interface device structure
3901 * @p: pointer to an address structure
3902 *
3903 * Returns 0 on success, negative on failure
3904 **/
3905static int ixgbe_set_mac(struct net_device *netdev, void *p)
3906{
3907 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003908 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003909 struct sockaddr *addr = p;
3910
3911 if (!is_valid_ether_addr(addr->sa_data))
3912 return -EADDRNOTAVAIL;
3913
3914 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003915 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07003916
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003917 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003918
3919 return 0;
3920}
3921
3922#ifdef CONFIG_NET_POLL_CONTROLLER
3923/*
3924 * Polling 'interrupt' - used by things like netconsole to send skbs
3925 * without having to re-enable interrupts. It's not called while
3926 * the interrupt routine is executing.
3927 */
3928static void ixgbe_netpoll(struct net_device *netdev)
3929{
3930 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3931
3932 disable_irq(adapter->pdev->irq);
3933 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
3934 ixgbe_intr(adapter->pdev->irq, netdev);
3935 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
3936 enable_irq(adapter->pdev->irq);
3937}
3938#endif
3939
Stephen Hemminger0edc3522008-11-19 22:24:29 -08003940static const struct net_device_ops ixgbe_netdev_ops = {
3941 .ndo_open = ixgbe_open,
3942 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08003943 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08003944 .ndo_get_stats = ixgbe_get_stats,
3945 .ndo_set_multicast_list = ixgbe_set_rx_mode,
3946 .ndo_validate_addr = eth_validate_addr,
3947 .ndo_set_mac_address = ixgbe_set_mac,
3948 .ndo_change_mtu = ixgbe_change_mtu,
3949 .ndo_tx_timeout = ixgbe_tx_timeout,
3950 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
3951 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
3952 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
3953#ifdef CONFIG_NET_POLL_CONTROLLER
3954 .ndo_poll_controller = ixgbe_netpoll,
3955#endif
3956};
3957
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003958/**
Auke Kok9a799d72007-09-15 14:07:45 -07003959 * ixgbe_probe - Device Initialization Routine
3960 * @pdev: PCI device information struct
3961 * @ent: entry in ixgbe_pci_tbl
3962 *
3963 * Returns 0 on success, negative on failure
3964 *
3965 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
3966 * The OS initialization, configuring of the adapter private structure,
3967 * and a hardware reset occur.
3968 **/
3969static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003970 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07003971{
3972 struct net_device *netdev;
3973 struct ixgbe_adapter *adapter = NULL;
3974 struct ixgbe_hw *hw;
3975 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07003976 static int cards_found;
3977 int i, err, pci_using_dac;
3978 u16 link_status, link_speed, link_width;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003979 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07003980
3981 err = pci_enable_device(pdev);
3982 if (err)
3983 return err;
3984
3985 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
3986 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
3987 pci_using_dac = 1;
3988 } else {
3989 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
3990 if (err) {
3991 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
3992 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003993 dev_err(&pdev->dev, "No usable DMA "
3994 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003995 goto err_dma;
3996 }
3997 }
3998 pci_using_dac = 0;
3999 }
4000
4001 err = pci_request_regions(pdev, ixgbe_driver_name);
4002 if (err) {
4003 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
4004 goto err_pci_reg;
4005 }
4006
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004007 err = pci_enable_pcie_error_reporting(pdev);
4008 if (err) {
4009 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
4010 "0x%x\n", err);
4011 /* non-fatal, continue */
4012 }
4013
Auke Kok9a799d72007-09-15 14:07:45 -07004014 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07004015 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004016
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004017 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07004018 if (!netdev) {
4019 err = -ENOMEM;
4020 goto err_alloc_etherdev;
4021 }
4022
Auke Kok9a799d72007-09-15 14:07:45 -07004023 SET_NETDEV_DEV(netdev, &pdev->dev);
4024
4025 pci_set_drvdata(pdev, netdev);
4026 adapter = netdev_priv(netdev);
4027
4028 adapter->netdev = netdev;
4029 adapter->pdev = pdev;
4030 hw = &adapter->hw;
4031 hw->back = adapter;
4032 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
4033
Jeff Kirsher05857982008-09-11 19:57:00 -07004034 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
4035 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07004036 if (!hw->hw_addr) {
4037 err = -EIO;
4038 goto err_ioremap;
4039 }
4040
4041 for (i = 1; i <= 5; i++) {
4042 if (pci_resource_len(pdev, i) == 0)
4043 continue;
4044 }
4045
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004046 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07004047 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004048 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07004049 strcpy(netdev->name, pci_name(pdev));
4050
Auke Kok9a799d72007-09-15 14:07:45 -07004051 adapter->bd_number = cards_found;
4052
Auke Kok9a799d72007-09-15 14:07:45 -07004053 /* Setup hw api */
4054 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004055 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07004056
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004057 /* EEPROM */
4058 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
4059 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
4060 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
4061 if (!(eec & (1 << 8)))
4062 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
4063
4064 /* PHY */
4065 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08004066 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
4067
4068 /* set up this timer and work struct before calling get_invariants
4069 * which might start the timer
4070 */
4071 init_timer(&adapter->sfp_timer);
4072 adapter->sfp_timer.function = &ixgbe_sfp_timer;
4073 adapter->sfp_timer.data = (unsigned long) adapter;
4074
4075 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004076
Auke Kok9a799d72007-09-15 14:07:45 -07004077 err = ii->get_invariants(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004078 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
4079 /* start a kernel thread to watch for a module to arrive */
4080 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4081 mod_timer(&adapter->sfp_timer,
4082 round_jiffies(jiffies + (2 * HZ)));
4083 err = 0;
4084 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4085 DPRINTK(PROBE, ERR, "failed to load because an "
4086 "unsupported SFP+ module type was detected.\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004087 goto err_hw_init;
Donald Skidmorec4900be2008-11-20 21:11:42 -08004088 } else if (err) {
4089 goto err_hw_init;
4090 }
Auke Kok9a799d72007-09-15 14:07:45 -07004091
4092 /* setup the private structure */
4093 err = ixgbe_sw_init(adapter);
4094 if (err)
4095 goto err_sw_init;
4096
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004097 /* reset_hw fills in the perm_addr as well */
4098 err = hw->mac.ops.reset_hw(hw);
4099 if (err) {
4100 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
4101 goto err_sw_init;
4102 }
4103
Auke Kok9a799d72007-09-15 14:07:45 -07004104 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004105 NETIF_F_IP_CSUM |
4106 NETIF_F_HW_VLAN_TX |
4107 NETIF_F_HW_VLAN_RX |
4108 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004109
Jesse Brandeburge9990a92008-08-26 04:27:24 -07004110 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07004111 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07004112 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08004113 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004114
4115 netdev->vlan_features |= NETIF_F_TSO;
4116 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07004117 netdev->vlan_features |= NETIF_F_IP_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004118 netdev->vlan_features |= NETIF_F_SG;
4119
Alexander Duyck2f90b862008-11-20 20:52:10 -08004120 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4121 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4122
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004123#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004124 netdev->dcbnl_ops = &dcbnl_ops;
4125#endif
4126
Auke Kok9a799d72007-09-15 14:07:45 -07004127 if (pci_using_dac)
4128 netdev->features |= NETIF_F_HIGHDMA;
4129
Auke Kok9a799d72007-09-15 14:07:45 -07004130 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004131 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07004132 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
4133 err = -EIO;
4134 goto err_eeprom;
4135 }
4136
4137 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
4138 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
4139
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004140 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
4141 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004142 err = -EIO;
4143 goto err_eeprom;
4144 }
4145
4146 init_timer(&adapter->watchdog_timer);
4147 adapter->watchdog_timer.function = &ixgbe_watchdog;
4148 adapter->watchdog_timer.data = (unsigned long)adapter;
4149
4150 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004151 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004152
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004153 err = ixgbe_init_interrupt_scheme(adapter);
4154 if (err)
4155 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07004156
4157 /* print bus type/speed/width info */
4158 pci_read_config_word(pdev, IXGBE_PCI_LINK_STATUS, &link_status);
4159 link_speed = link_status & IXGBE_PCI_LINK_SPEED;
4160 link_width = link_status & IXGBE_PCI_LINK_WIDTH;
Johannes Berg7c510e42008-10-27 17:47:26 -07004161 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004162 ((link_speed == IXGBE_PCI_LINK_SPEED_5000) ? "5.0Gb/s" :
4163 (link_speed == IXGBE_PCI_LINK_SPEED_2500) ? "2.5Gb/s" :
4164 "Unknown"),
4165 ((link_width == IXGBE_PCI_LINK_WIDTH_8) ? "Width x8" :
4166 (link_width == IXGBE_PCI_LINK_WIDTH_4) ? "Width x4" :
4167 (link_width == IXGBE_PCI_LINK_WIDTH_2) ? "Width x2" :
4168 (link_width == IXGBE_PCI_LINK_WIDTH_1) ? "Width x1" :
4169 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07004170 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004171 ixgbe_read_pba_num_generic(hw, &part_num);
Auke Kok9a799d72007-09-15 14:07:45 -07004172 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004173 hw->mac.type, hw->phy.type,
4174 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07004175
Auke Kok0c254d82008-02-11 09:25:56 -08004176 if (link_width <= IXGBE_PCI_LINK_WIDTH_4) {
4177 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004178 "this card is not sufficient for optimal "
4179 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004180 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004181 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004182 }
4183
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08004184 /* save off EEPROM version number */
4185 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
4186
Auke Kok9a799d72007-09-15 14:07:45 -07004187 /* reset the hardware with the new settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004188 hw->mac.ops.start_hw(hw);
4189
Auke Kok9a799d72007-09-15 14:07:45 -07004190 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004191
4192 strcpy(netdev->name, "eth%d");
4193 err = register_netdev(netdev);
4194 if (err)
4195 goto err_register;
4196
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004197#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03004198 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004199 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
4200 /* always use CB2 mode, difference is masked
4201 * in the CB driver */
4202 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
4203 ixgbe_setup_dca(adapter);
4204 }
4205#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004206
4207 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
4208 cards_found++;
4209 return 0;
4210
4211err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004212 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004213err_hw_init:
4214err_sw_init:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004215 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004216err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08004217 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4218 del_timer_sync(&adapter->sfp_timer);
4219 cancel_work_sync(&adapter->sfp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004220 iounmap(hw->hw_addr);
4221err_ioremap:
4222 free_netdev(netdev);
4223err_alloc_etherdev:
4224 pci_release_regions(pdev);
4225err_pci_reg:
4226err_dma:
4227 pci_disable_device(pdev);
4228 return err;
4229}
4230
4231/**
4232 * ixgbe_remove - Device Removal Routine
4233 * @pdev: PCI device information struct
4234 *
4235 * ixgbe_remove is called by the PCI subsystem to alert the driver
4236 * that it should release a PCI device. The could be caused by a
4237 * Hot-Plug event, or because the driver is going to be removed from
4238 * memory.
4239 **/
4240static void __devexit ixgbe_remove(struct pci_dev *pdev)
4241{
4242 struct net_device *netdev = pci_get_drvdata(pdev);
4243 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004244 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004245
4246 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004247 /* clear the module not found bit to make sure the worker won't
4248 * reschedule
4249 */
4250 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07004251 del_timer_sync(&adapter->watchdog_timer);
4252
Donald Skidmorec4900be2008-11-20 21:11:42 -08004253 del_timer_sync(&adapter->sfp_timer);
4254 cancel_work_sync(&adapter->watchdog_task);
4255 cancel_work_sync(&adapter->sfp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004256 flush_scheduled_work();
4257
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004258#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004259 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
4260 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
4261 dca_remove_requester(&pdev->dev);
4262 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
4263 }
4264
4265#endif
Donald Skidmorec4900be2008-11-20 21:11:42 -08004266 if (netdev->reg_state == NETREG_REGISTERED)
4267 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004268
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004269 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004270
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004271 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004272
4273 iounmap(adapter->hw.hw_addr);
4274 pci_release_regions(pdev);
4275
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004276 DPRINTK(PROBE, INFO, "complete\n");
4277 kfree(adapter->tx_ring);
4278 kfree(adapter->rx_ring);
4279
Auke Kok9a799d72007-09-15 14:07:45 -07004280 free_netdev(netdev);
4281
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004282 err = pci_disable_pcie_error_reporting(pdev);
4283 if (err)
4284 dev_err(&pdev->dev,
4285 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
4286
Auke Kok9a799d72007-09-15 14:07:45 -07004287 pci_disable_device(pdev);
4288}
4289
4290/**
4291 * ixgbe_io_error_detected - called when PCI error is detected
4292 * @pdev: Pointer to PCI device
4293 * @state: The current pci connection state
4294 *
4295 * This function is called after a PCI bus error affecting
4296 * this device has been detected.
4297 */
4298static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004299 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07004300{
4301 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004302 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004303
4304 netif_device_detach(netdev);
4305
4306 if (netif_running(netdev))
4307 ixgbe_down(adapter);
4308 pci_disable_device(pdev);
4309
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004310 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07004311 return PCI_ERS_RESULT_NEED_RESET;
4312}
4313
4314/**
4315 * ixgbe_io_slot_reset - called after the pci bus has been reset.
4316 * @pdev: Pointer to PCI device
4317 *
4318 * Restart the card from scratch, as if from a cold-boot.
4319 */
4320static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
4321{
4322 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004323 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004324 pci_ers_result_t result;
4325 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004326
4327 if (pci_enable_device(pdev)) {
4328 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004329 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004330 result = PCI_ERS_RESULT_DISCONNECT;
4331 } else {
4332 pci_set_master(pdev);
4333 pci_restore_state(pdev);
4334
4335 pci_enable_wake(pdev, PCI_D3hot, 0);
4336 pci_enable_wake(pdev, PCI_D3cold, 0);
4337
4338 ixgbe_reset(adapter);
4339
4340 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07004341 }
Auke Kok9a799d72007-09-15 14:07:45 -07004342
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004343 err = pci_cleanup_aer_uncorrect_error_status(pdev);
4344 if (err) {
4345 dev_err(&pdev->dev,
4346 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
4347 /* non-fatal, continue */
4348 }
Auke Kok9a799d72007-09-15 14:07:45 -07004349
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004350 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07004351}
4352
4353/**
4354 * ixgbe_io_resume - called when traffic can start flowing again.
4355 * @pdev: Pointer to PCI device
4356 *
4357 * This callback is called when the error recovery driver tells us that
4358 * its OK to resume normal operation.
4359 */
4360static void ixgbe_io_resume(struct pci_dev *pdev)
4361{
4362 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004363 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004364
4365 if (netif_running(netdev)) {
4366 if (ixgbe_up(adapter)) {
4367 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
4368 return;
4369 }
4370 }
4371
4372 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004373}
4374
4375static struct pci_error_handlers ixgbe_err_handler = {
4376 .error_detected = ixgbe_io_error_detected,
4377 .slot_reset = ixgbe_io_slot_reset,
4378 .resume = ixgbe_io_resume,
4379};
4380
4381static struct pci_driver ixgbe_driver = {
4382 .name = ixgbe_driver_name,
4383 .id_table = ixgbe_pci_tbl,
4384 .probe = ixgbe_probe,
4385 .remove = __devexit_p(ixgbe_remove),
4386#ifdef CONFIG_PM
4387 .suspend = ixgbe_suspend,
4388 .resume = ixgbe_resume,
4389#endif
4390 .shutdown = ixgbe_shutdown,
4391 .err_handler = &ixgbe_err_handler
4392};
4393
4394/**
4395 * ixgbe_init_module - Driver Registration Routine
4396 *
4397 * ixgbe_init_module is the first routine called when the driver is
4398 * loaded. All it does is register with the PCI subsystem.
4399 **/
4400static int __init ixgbe_init_module(void)
4401{
4402 int ret;
4403 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
4404 ixgbe_driver_string, ixgbe_driver_version);
4405
4406 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
4407
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004408#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004409 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004410#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004411
Auke Kok9a799d72007-09-15 14:07:45 -07004412 ret = pci_register_driver(&ixgbe_driver);
4413 return ret;
4414}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004415
Auke Kok9a799d72007-09-15 14:07:45 -07004416module_init(ixgbe_init_module);
4417
4418/**
4419 * ixgbe_exit_module - Driver Exit Cleanup Routine
4420 *
4421 * ixgbe_exit_module is called just before the driver is removed
4422 * from memory.
4423 **/
4424static void __exit ixgbe_exit_module(void)
4425{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004426#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004427 dca_unregister_notify(&dca_notifier);
4428#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004429 pci_unregister_driver(&ixgbe_driver);
4430}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004431
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004432#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004433static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004434 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004435{
4436 int ret_val;
4437
4438 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004439 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004440
4441 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4442}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004443#endif /* CONFIG_IXGBE_DCA */
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004444
Auke Kok9a799d72007-09-15 14:07:45 -07004445module_exit(ixgbe_exit_module);
4446
4447/* ixgbe_main.c */