blob: e0d736cc245bd54842fa94f4cb71f089c43ac20a [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;
Don Skidmore54037502009-02-21 15:42:56 -0800939 u32 eicr;
940
941 /*
942 * Workaround for Silicon errata. Use clear-by-write instead
943 * of clear-by-read. Reading with EICS will return the
944 * interrupt causes without clearing, which later be done
945 * with the write to EICR.
946 */
947 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
948 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -0700949
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -0700950 if (eicr & IXGBE_EICR_LSC)
951 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -0800952
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700953 ixgbe_check_fan_failure(adapter, eicr);
954
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -0800955 if (!test_bit(__IXGBE_DOWN, &adapter->state))
956 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -0700957
958 return IRQ_HANDLED;
959}
960
961static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
962{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800963 struct ixgbe_q_vector *q_vector = data;
964 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700965 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800966 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -0700967
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800968 if (!q_vector->txr_count)
969 return IRQ_HANDLED;
970
971 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
972 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700973 tx_ring = &(adapter->tx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400974#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800975 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700976 ixgbe_update_tx_dca(adapter, tx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800977#endif
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700978 tx_ring->total_bytes = 0;
979 tx_ring->total_packets = 0;
980 ixgbe_clean_tx_irq(adapter, tx_ring);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800981 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700982 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800983 }
984
Auke Kok9a799d72007-09-15 14:07:45 -0700985 return IRQ_HANDLED;
986}
987
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800988/**
989 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
990 * @irq: unused
991 * @data: pointer to our q_vector struct for this interrupt vector
992 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700993static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
994{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800995 struct ixgbe_q_vector *q_vector = data;
996 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700997 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800998 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700999 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001000
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001001 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001002 for (i = 0; i < q_vector->rxr_count; i++) {
1003 rx_ring = &(adapter->rx_ring[r_idx]);
1004 rx_ring->total_bytes = 0;
1005 rx_ring->total_packets = 0;
1006 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1007 r_idx + 1);
1008 }
1009
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001010 if (!q_vector->rxr_count)
1011 return IRQ_HANDLED;
1012
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001013 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001014 rx_ring = &(adapter->rx_ring[r_idx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001015 /* disable interrupts on this vector only */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001016 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rx_ring->v_idx);
Ben Hutchings288379f2009-01-19 16:43:59 -08001017 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001018
Auke Kok9a799d72007-09-15 14:07:45 -07001019 return IRQ_HANDLED;
1020}
1021
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001022static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1023{
1024 ixgbe_msix_clean_rx(irq, data);
1025 ixgbe_msix_clean_tx(irq, data);
1026
1027 return IRQ_HANDLED;
1028}
1029
1030/**
1031 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1032 * @napi: napi struct with our devices info in it
1033 * @budget: amount of work driver is allowed to do this pass, in packets
1034 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001035 * This function is optimized for cleaning one queue only on a single
1036 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001037 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001038static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1039{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001040 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001041 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001042 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001043 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001044 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001045 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001046
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001047 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001048 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001049#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001050 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001051 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001052#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001053
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001054 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001055
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001056 /* If all Rx work done, exit the polling mode */
1057 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001058 napi_complete(napi);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001059 if (adapter->itr_setting & 3)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001060 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001061 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001062 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rx_ring->v_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07001063 }
1064
1065 return work_done;
1066}
1067
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001068/**
1069 * ixgbe_clean_rxonly_many - msix (aka one shot) rx clean routine
1070 * @napi: napi struct with our devices info in it
1071 * @budget: amount of work driver is allowed to do this pass, in packets
1072 *
1073 * This function will clean more than one rx queue associated with a
1074 * q_vector.
1075 **/
1076static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget)
1077{
1078 struct ixgbe_q_vector *q_vector =
1079 container_of(napi, struct ixgbe_q_vector, napi);
1080 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001081 struct ixgbe_ring *rx_ring = NULL;
1082 int work_done = 0, i;
1083 long r_idx;
1084 u16 enable_mask = 0;
1085
1086 /* attempt to distribute budget to each queue fairly, but don't allow
1087 * the budget to go below 1 because we'll exit polling */
1088 budget /= (q_vector->rxr_count ?: 1);
1089 budget = max(budget, 1);
1090 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1091 for (i = 0; i < q_vector->rxr_count; i++) {
1092 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001093#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001094 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1095 ixgbe_update_rx_dca(adapter, rx_ring);
1096#endif
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001097 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001098 enable_mask |= rx_ring->v_idx;
1099 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1100 r_idx + 1);
1101 }
1102
1103 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1104 rx_ring = &(adapter->rx_ring[r_idx]);
1105 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001106 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001107 napi_complete(napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001108 if (adapter->itr_setting & 3)
1109 ixgbe_set_itr_msix(q_vector);
1110 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1111 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, enable_mask);
1112 return 0;
1113 }
1114
1115 return work_done;
1116}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001117static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001118 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001119{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001120 a->q_vector[v_idx].adapter = a;
1121 set_bit(r_idx, a->q_vector[v_idx].rxr_idx);
1122 a->q_vector[v_idx].rxr_count++;
1123 a->rx_ring[r_idx].v_idx = 1 << v_idx;
1124}
Auke Kok9a799d72007-09-15 14:07:45 -07001125
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001126static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001127 int r_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001128{
1129 a->q_vector[v_idx].adapter = a;
1130 set_bit(r_idx, a->q_vector[v_idx].txr_idx);
1131 a->q_vector[v_idx].txr_count++;
1132 a->tx_ring[r_idx].v_idx = 1 << v_idx;
1133}
Auke Kok9a799d72007-09-15 14:07:45 -07001134
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001135/**
1136 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1137 * @adapter: board private structure to initialize
1138 * @vectors: allotted vector count for descriptor rings
1139 *
1140 * This function maps descriptor rings to the queue-specific vectors
1141 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1142 * one vector per ring/queue, but on a constrained vector budget, we
1143 * group the rings as "efficiently" as possible. You would add new
1144 * mapping configurations in here.
1145 **/
1146static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001147 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001148{
1149 int v_start = 0;
1150 int rxr_idx = 0, txr_idx = 0;
1151 int rxr_remaining = adapter->num_rx_queues;
1152 int txr_remaining = adapter->num_tx_queues;
1153 int i, j;
1154 int rqpv, tqpv;
1155 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001156
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001157 /* No mapping required if MSI-X is disabled. */
1158 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001159 goto out;
1160
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001161 /*
1162 * The ideal configuration...
1163 * We have enough vectors to map one per queue.
1164 */
1165 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1166 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1167 map_vector_to_rxq(adapter, v_start, rxr_idx);
1168
1169 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1170 map_vector_to_txq(adapter, v_start, txr_idx);
1171
1172 goto out;
1173 }
1174
1175 /*
1176 * If we don't have enough vectors for a 1-to-1
1177 * mapping, we'll have to group them so there are
1178 * multiple queues per vector.
1179 */
1180 /* Re-adjusting *qpv takes care of the remainder. */
1181 for (i = v_start; i < vectors; i++) {
1182 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1183 for (j = 0; j < rqpv; j++) {
1184 map_vector_to_rxq(adapter, i, rxr_idx);
1185 rxr_idx++;
1186 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001187 }
Auke Kok9a799d72007-09-15 14:07:45 -07001188 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001189 for (i = v_start; i < vectors; i++) {
1190 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1191 for (j = 0; j < tqpv; j++) {
1192 map_vector_to_txq(adapter, i, txr_idx);
1193 txr_idx++;
1194 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001195 }
Auke Kok9a799d72007-09-15 14:07:45 -07001196 }
1197
Auke Kok9a799d72007-09-15 14:07:45 -07001198out:
Auke Kok9a799d72007-09-15 14:07:45 -07001199 return err;
1200}
1201
1202/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001203 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1204 * @adapter: board private structure
1205 *
1206 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1207 * interrupts from the kernel.
1208 **/
1209static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1210{
1211 struct net_device *netdev = adapter->netdev;
1212 irqreturn_t (*handler)(int, void *);
1213 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001214 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001215
1216 /* Decrement for Other and TCP Timer vectors */
1217 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1218
1219 /* Map the Tx/Rx rings to the vectors we were allotted. */
1220 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1221 if (err)
1222 goto out;
1223
1224#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001225 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1226 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001227 for (vector = 0; vector < q_vectors; vector++) {
1228 handler = SET_HANDLER(&adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001229
1230 if(handler == &ixgbe_msix_clean_rx) {
1231 sprintf(adapter->name[vector], "%s-%s-%d",
1232 netdev->name, "rx", ri++);
1233 }
1234 else if(handler == &ixgbe_msix_clean_tx) {
1235 sprintf(adapter->name[vector], "%s-%s-%d",
1236 netdev->name, "tx", ti++);
1237 }
1238 else
1239 sprintf(adapter->name[vector], "%s-%s-%d",
1240 netdev->name, "TxRx", vector);
1241
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001242 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001243 handler, 0, adapter->name[vector],
1244 &(adapter->q_vector[vector]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001245 if (err) {
1246 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001247 "request_irq failed for MSIX interrupt "
1248 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001249 goto free_queue_irqs;
1250 }
1251 }
1252
1253 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1254 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001255 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001256 if (err) {
1257 DPRINTK(PROBE, ERR,
1258 "request_irq for msix_lsc failed: %d\n", err);
1259 goto free_queue_irqs;
1260 }
1261
1262 return 0;
1263
1264free_queue_irqs:
1265 for (i = vector - 1; i >= 0; i--)
1266 free_irq(adapter->msix_entries[--vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001267 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001268 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1269 pci_disable_msix(adapter->pdev);
1270 kfree(adapter->msix_entries);
1271 adapter->msix_entries = NULL;
1272out:
1273 return err;
1274}
1275
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001276static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1277{
1278 struct ixgbe_hw *hw = &adapter->hw;
1279 struct ixgbe_q_vector *q_vector = adapter->q_vector;
1280 u8 current_itr;
1281 u32 new_itr = q_vector->eitr;
1282 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1283 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1284
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001285 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001286 q_vector->tx_itr,
1287 tx_ring->total_packets,
1288 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001289 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001290 q_vector->rx_itr,
1291 rx_ring->total_packets,
1292 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001293
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001294 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001295
1296 switch (current_itr) {
1297 /* counts and packets in update_itr are dependent on these numbers */
1298 case lowest_latency:
1299 new_itr = 100000;
1300 break;
1301 case low_latency:
1302 new_itr = 20000; /* aka hwitr = ~200 */
1303 break;
1304 case bulk_latency:
1305 new_itr = 8000;
1306 break;
1307 default:
1308 break;
1309 }
1310
1311 if (new_itr != q_vector->eitr) {
1312 u32 itr_reg;
1313 /* do an exponential smoothing */
1314 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
1315 q_vector->eitr = new_itr;
1316 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
1317 /* must write high and low 16 bits to reset counter */
1318 IXGBE_WRITE_REG(hw, IXGBE_EITR(0), itr_reg | (itr_reg)<<16);
1319 }
1320
1321 return;
1322}
1323
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001324/**
1325 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1326 * @adapter: board private structure
1327 **/
1328static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1329{
1330 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1331 IXGBE_WRITE_FLUSH(&adapter->hw);
1332 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1333 int i;
1334 for (i = 0; i < adapter->num_msix_vectors; i++)
1335 synchronize_irq(adapter->msix_entries[i].vector);
1336 } else {
1337 synchronize_irq(adapter->pdev->irq);
1338 }
1339}
1340
1341/**
1342 * ixgbe_irq_enable - Enable default interrupt generation settings
1343 * @adapter: board private structure
1344 **/
1345static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1346{
1347 u32 mask;
1348 mask = IXGBE_EIMS_ENABLE_MASK;
David S. Miller6ab33d52008-11-20 16:44:00 -08001349 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1350 mask |= IXGBE_EIMS_GPI_SDP1;
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001351 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1352 IXGBE_WRITE_FLUSH(&adapter->hw);
1353}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001354
1355/**
1356 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001357 * @irq: interrupt number
1358 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001359 **/
1360static irqreturn_t ixgbe_intr(int irq, void *data)
1361{
1362 struct net_device *netdev = data;
1363 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1364 struct ixgbe_hw *hw = &adapter->hw;
1365 u32 eicr;
1366
Don Skidmore54037502009-02-21 15:42:56 -08001367 /*
1368 * Workaround for silicon errata. Mask the interrupts
1369 * before the read of EICR.
1370 */
1371 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1372
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001373 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1374 * therefore no explict interrupt disable is necessary */
1375 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001376 if (!eicr) {
1377 /* shared interrupt alert!
1378 * make sure interrupts are enabled because the read will
1379 * have disabled interrupts due to EIAM */
1380 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001381 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001382 }
Auke Kok9a799d72007-09-15 14:07:45 -07001383
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001384 if (eicr & IXGBE_EICR_LSC)
1385 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001386
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001387 ixgbe_check_fan_failure(adapter, eicr);
1388
Ben Hutchings288379f2009-01-19 16:43:59 -08001389 if (napi_schedule_prep(&adapter->q_vector[0].napi)) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001390 adapter->tx_ring[0].total_packets = 0;
1391 adapter->tx_ring[0].total_bytes = 0;
1392 adapter->rx_ring[0].total_packets = 0;
1393 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001394 /* would disable interrupts here but EIAM disabled it */
Ben Hutchings288379f2009-01-19 16:43:59 -08001395 __napi_schedule(&adapter->q_vector[0].napi);
Auke Kok9a799d72007-09-15 14:07:45 -07001396 }
1397
1398 return IRQ_HANDLED;
1399}
1400
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001401static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1402{
1403 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1404
1405 for (i = 0; i < q_vectors; i++) {
1406 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
1407 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1408 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1409 q_vector->rxr_count = 0;
1410 q_vector->txr_count = 0;
1411 }
1412}
1413
Auke Kok9a799d72007-09-15 14:07:45 -07001414/**
1415 * ixgbe_request_irq - initialize interrupts
1416 * @adapter: board private structure
1417 *
1418 * Attempts to configure interrupts using the best available
1419 * capabilities of the hardware and kernel.
1420 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001421static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001422{
1423 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001424 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001425
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001426 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1427 err = ixgbe_request_msix_irqs(adapter);
1428 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1429 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001430 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001431 } else {
1432 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001433 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001434 }
1435
Auke Kok9a799d72007-09-15 14:07:45 -07001436 if (err)
1437 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1438
Auke Kok9a799d72007-09-15 14:07:45 -07001439 return err;
1440}
1441
1442static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1443{
1444 struct net_device *netdev = adapter->netdev;
1445
1446 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001447 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001448
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001449 q_vectors = adapter->num_msix_vectors;
1450
1451 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001452 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001453
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001454 i--;
1455 for (; i >= 0; i--) {
1456 free_irq(adapter->msix_entries[i].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001457 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001458 }
1459
1460 ixgbe_reset_q_vectors(adapter);
1461 } else {
1462 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001463 }
1464}
1465
1466/**
Auke Kok9a799d72007-09-15 14:07:45 -07001467 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1468 *
1469 **/
1470static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1471{
Auke Kok9a799d72007-09-15 14:07:45 -07001472 struct ixgbe_hw *hw = &adapter->hw;
1473
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001474 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001475 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001476
1477 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(0), 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001478 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(0), 0);
1479
1480 map_vector_to_rxq(adapter, 0, 0);
1481 map_vector_to_txq(adapter, 0, 0);
1482
1483 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001484}
1485
1486/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001487 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001488 * @adapter: board private structure
1489 *
1490 * Configure the Tx unit of the MAC after a reset.
1491 **/
1492static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1493{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001494 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001495 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001496 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001497
1498 /* Setup the HW Tx Head and Tail descriptor pointers */
1499 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001500 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1501 j = ring->reg_idx;
1502 tdba = ring->dma;
1503 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001504 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001505 (tdba & DMA_32BIT_MASK));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001506 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1507 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1508 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1509 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1510 adapter->tx_ring[i].head = IXGBE_TDH(j);
1511 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1512 /* Disable Tx Head Writeback RO bit, since this hoses
1513 * bookkeeping if things aren't delivered in order.
1514 */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001515 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001516 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001517 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001518 }
Auke Kok9a799d72007-09-15 14:07:45 -07001519}
1520
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001521#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07001522
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001523static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1524{
1525 struct ixgbe_ring *rx_ring;
1526 u32 srrctl;
1527 int queue0;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001528 unsigned long mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001529
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001530 /* program one srrctl register per VMDq index */
1531 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
1532 long shift, len;
1533 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1534 len = sizeof(adapter->ring_feature[RING_F_VMDQ].mask) * 8;
1535 shift = find_first_bit(&mask, len);
1536 queue0 = index & mask;
1537 index = (index & mask) >> shift;
1538 /* program one srrctl per RSS queue since RDRXCTL.MVMEN is enabled */
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001539 } else {
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001540 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1541 queue0 = index & mask;
1542 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001543 }
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001544
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001545 rx_ring = &adapter->rx_ring[queue0];
1546
1547 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1548
1549 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1550 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1551
1552 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1553 srrctl |= IXGBE_RXBUFFER_2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1554 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1555 srrctl |= ((IXGBE_RX_HDR_SIZE <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001556 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1557 IXGBE_SRRCTL_BSIZEHDR_MASK);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001558 } else {
1559 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1560
1561 if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1562 srrctl |= IXGBE_RXBUFFER_2048 >>
1563 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1564 else
1565 srrctl |= rx_ring->rx_buf_len >>
1566 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1567 }
1568 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1569}
1570
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001571/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001572 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001573 * @adapter: board private structure
1574 *
1575 * Configure the Rx unit of the MAC after a reset.
1576 **/
1577static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1578{
1579 u64 rdba;
1580 struct ixgbe_hw *hw = &adapter->hw;
1581 struct net_device *netdev = adapter->netdev;
1582 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001583 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001584 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001585 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1586 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1587 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001588 u32 fctrl, hlreg0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001589 u32 reta = 0, mrqc;
1590 u32 rdrxctl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001591 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07001592
1593 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001594 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07001595
1596 /* Set the RX buffer length according to the mode */
1597 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001598 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001599 } else {
1600 if (netdev->mtu <= ETH_DATA_LEN)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001601 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001602 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001603 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07001604 }
1605
1606 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1607 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001608 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
Auke Kok9a799d72007-09-15 14:07:45 -07001609 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1610
1611 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1612 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1613 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1614 else
1615 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1616 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1617
Auke Kok9a799d72007-09-15 14:07:45 -07001618 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1619 /* disable receives while setting up the descriptors */
1620 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1621 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1622
1623 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1624 * the Base and Length of the Rx Descriptor Ring */
1625 for (i = 0; i < adapter->num_rx_queues; i++) {
1626 rdba = adapter->rx_ring[i].dma;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001627 j = adapter->rx_ring[i].reg_idx;
1628 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_32BIT_MASK));
1629 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
1630 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
1631 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
1632 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
1633 adapter->rx_ring[i].head = IXGBE_RDH(j);
1634 adapter->rx_ring[i].tail = IXGBE_RDT(j);
1635 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001636
1637 ixgbe_configure_srrctl(adapter, j);
Auke Kok9a799d72007-09-15 14:07:45 -07001638 }
1639
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001640 /*
1641 * For VMDq support of different descriptor types or
1642 * buffer sizes through the use of multiple SRRCTL
1643 * registers, RDRXCTL.MVMEN must be set to 1
1644 *
1645 * also, the manual doesn't mention it clearly but DCA hints
1646 * will only use queue 0's tags unless this bit is set. Side
1647 * effects of setting this bit are only that SRRCTL must be
1648 * fully programmed [0..15]
1649 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08001650 if (adapter->flags &
1651 (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_VMDQ_ENABLED)) {
1652 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1653 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
1654 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
1655 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001656
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001657 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07001658 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001659 for (i = 0, j = 0; i < 128; i++, j++) {
1660 if (j == adapter->ring_feature[RING_F_RSS].indices)
1661 j = 0;
1662 /* reta = 4-byte sliding window of
1663 * 0x00..(indices-1)(indices-1)00..etc. */
1664 reta = (reta << 8) | (j * 0x11);
1665 if ((i & 3) == 3)
1666 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07001667 }
1668
1669 /* Fill out hash function seeds */
1670 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001671 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07001672
1673 mrqc = IXGBE_MRQC_RSSEN
1674 /* Perform hash on these packet types */
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001675 | IXGBE_MRQC_RSS_FIELD_IPV4
1676 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1677 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1678 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
1679 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
1680 | IXGBE_MRQC_RSS_FIELD_IPV6
1681 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1682 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
1683 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07001684 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Auke Kok9a799d72007-09-15 14:07:45 -07001685 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001686
1687 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1688
1689 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
1690 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
1691 /* Disable indicating checksum in descriptor, enables
1692 * RSS hash */
1693 rxcsum |= IXGBE_RXCSUM_PCSD;
1694 }
1695 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
1696 /* Enable IPv4 payload checksum for UDP fragments
1697 * if PCSD is not set */
1698 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1699 }
1700
1701 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
Auke Kok9a799d72007-09-15 14:07:45 -07001702}
1703
Auke Kok9a799d72007-09-15 14:07:45 -07001704static void ixgbe_vlan_rx_add_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
1709 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001710 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07001711}
1712
1713static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1714{
1715 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001716 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001717
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001718 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1719 ixgbe_irq_disable(adapter);
1720
Auke Kok9a799d72007-09-15 14:07:45 -07001721 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001722
1723 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1724 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001725
1726 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001727 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07001728}
1729
Don Skidmore068c89b2009-01-19 16:54:36 -08001730static void ixgbe_vlan_rx_register(struct net_device *netdev,
1731 struct vlan_group *grp)
1732{
1733 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1734 u32 ctrl;
1735
1736 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1737 ixgbe_irq_disable(adapter);
1738 adapter->vlgrp = grp;
1739
1740 /*
1741 * For a DCB driver, always enable VLAN tag stripping so we can
1742 * still receive traffic from a DCB-enabled host even if we're
1743 * not in DCB mode.
1744 */
1745 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1746 ctrl |= IXGBE_VLNCTRL_VME;
1747 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1748 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1749 ixgbe_vlan_rx_add_vid(netdev, 0);
1750
1751 if (grp) {
1752 /* enable VLAN tag insert/strip */
1753 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1754 ctrl |= IXGBE_VLNCTRL_VME;
1755 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1756 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1757 }
1758
1759 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1760 ixgbe_irq_enable(adapter);
1761}
1762
Auke Kok9a799d72007-09-15 14:07:45 -07001763static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
1764{
1765 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1766
1767 if (adapter->vlgrp) {
1768 u16 vid;
1769 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1770 if (!vlan_group_get_device(adapter->vlgrp, vid))
1771 continue;
1772 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
1773 }
1774 }
1775}
1776
Christopher Leech2c5645c2008-08-26 04:27:02 -07001777static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
1778{
1779 struct dev_mc_list *mc_ptr;
1780 u8 *addr = *mc_addr_ptr;
1781 *vmdq = 0;
1782
1783 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
1784 if (mc_ptr->next)
1785 *mc_addr_ptr = mc_ptr->next->dmi_addr;
1786 else
1787 *mc_addr_ptr = NULL;
1788
1789 return addr;
1790}
1791
Auke Kok9a799d72007-09-15 14:07:45 -07001792/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07001793 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07001794 * @netdev: network interface device structure
1795 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07001796 * The set_rx_method entry point is called whenever the unicast/multicast
1797 * address list or the network interface flags are updated. This routine is
1798 * responsible for configuring the hardware for proper unicast, multicast and
1799 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07001800 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07001801static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001802{
1803 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1804 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07001805 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001806 u8 *addr_list = NULL;
1807 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001808
1809 /* Check for Promiscuous and All Multicast modes */
1810
1811 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07001812 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07001813
1814 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07001815 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001816 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07001817 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07001818 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07001819 if (netdev->flags & IFF_ALLMULTI) {
1820 fctrl |= IXGBE_FCTRL_MPE;
1821 fctrl &= ~IXGBE_FCTRL_UPE;
1822 } else {
1823 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1824 }
Alexander Duyck3d016252008-08-26 18:30:04 -07001825 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001826 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001827 }
1828
1829 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07001830 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001831
Christopher Leech2c5645c2008-08-26 04:27:02 -07001832 /* reprogram secondary unicast list */
1833 addr_count = netdev->uc_count;
1834 if (addr_count)
1835 addr_list = netdev->uc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001836 hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count,
1837 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07001838
Christopher Leech2c5645c2008-08-26 04:27:02 -07001839 /* reprogram multicast list */
1840 addr_count = netdev->mc_count;
1841 if (addr_count)
1842 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001843 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
1844 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07001845}
1846
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001847static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
1848{
1849 int q_idx;
1850 struct ixgbe_q_vector *q_vector;
1851 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1852
1853 /* legacy and MSI only use one vector */
1854 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1855 q_vectors = 1;
1856
1857 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001858 struct napi_struct *napi;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001859 q_vector = &adapter->q_vector[q_idx];
1860 if (!q_vector->rxr_count)
1861 continue;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001862 napi = &q_vector->napi;
1863 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) &&
1864 (q_vector->rxr_count > 1))
1865 napi->poll = &ixgbe_clean_rxonly_many;
1866
1867 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001868 }
1869}
1870
1871static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
1872{
1873 int q_idx;
1874 struct ixgbe_q_vector *q_vector;
1875 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1876
1877 /* legacy and MSI only use one vector */
1878 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1879 q_vectors = 1;
1880
1881 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1882 q_vector = &adapter->q_vector[q_idx];
1883 if (!q_vector->rxr_count)
1884 continue;
1885 napi_disable(&q_vector->napi);
1886 }
1887}
1888
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08001889#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08001890/*
1891 * ixgbe_configure_dcb - Configure DCB hardware
1892 * @adapter: ixgbe adapter struct
1893 *
1894 * This is called by the driver on open to configure the DCB hardware.
1895 * This is also called by the gennetlink interface when reconfiguring
1896 * the DCB state.
1897 */
1898static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
1899{
1900 struct ixgbe_hw *hw = &adapter->hw;
1901 u32 txdctl, vlnctrl;
1902 int i, j;
1903
1904 ixgbe_dcb_check_config(&adapter->dcb_cfg);
1905 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
1906 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
1907
1908 /* reconfigure the hardware */
1909 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
1910
1911 for (i = 0; i < adapter->num_tx_queues; i++) {
1912 j = adapter->tx_ring[i].reg_idx;
1913 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
1914 /* PThresh workaround for Tx hang with DFP enabled. */
1915 txdctl |= 32;
1916 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
1917 }
1918 /* Enable VLAN tag insert/strip */
1919 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1920 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
1921 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
1922 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1923 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
1924}
1925
1926#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001927static void ixgbe_configure(struct ixgbe_adapter *adapter)
1928{
1929 struct net_device *netdev = adapter->netdev;
1930 int i;
1931
Christopher Leech2c5645c2008-08-26 04:27:02 -07001932 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001933
1934 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08001935#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08001936 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
1937 netif_set_gso_max_size(netdev, 32768);
1938 ixgbe_configure_dcb(adapter);
1939 } else {
1940 netif_set_gso_max_size(netdev, 65536);
1941 }
1942#else
1943 netif_set_gso_max_size(netdev, 65536);
1944#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001945
1946 ixgbe_configure_tx(adapter);
1947 ixgbe_configure_rx(adapter);
1948 for (i = 0; i < adapter->num_rx_queues; i++)
1949 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001950 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07001951}
1952
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001953/**
1954 * ixgbe_link_config - set up initial link with default speed and duplex
1955 * @hw: pointer to private hardware struct
1956 *
1957 * Returns 0 on success, negative on failure
1958 **/
1959static int ixgbe_link_config(struct ixgbe_hw *hw)
1960{
1961 u32 autoneg;
1962 bool link_up = false;
1963 u32 ret = IXGBE_ERR_LINK_SETUP;
1964
1965 if (hw->mac.ops.check_link)
1966 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1967
1968 if (ret)
1969 goto link_cfg_out;
1970
1971 if (hw->mac.ops.get_link_capabilities)
1972 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
1973 &hw->mac.autoneg);
1974 if (ret)
1975 goto link_cfg_out;
1976
1977 if (hw->mac.ops.setup_link_speed)
1978 ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up);
1979
1980link_cfg_out:
1981 return ret;
1982}
1983
Auke Kok9a799d72007-09-15 14:07:45 -07001984static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
1985{
1986 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07001987 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001988 int i, j = 0;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001989 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001990 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001991 u32 txdctl, rxdctl, mhadd;
1992 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07001993
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08001994 ixgbe_get_hw_control(adapter);
1995
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001996 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
1997 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001998 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1999 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002000 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002001 } else {
2002 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002003 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002004 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002005 /* XXX: to interrupt immediately for EICS writes, enable this */
2006 /* gpie |= IXGBE_GPIE_EIMEN; */
2007 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2008 }
2009
2010 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2011 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2012 * specifically only auto mask tx and rx interrupts */
2013 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002014 }
2015
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002016 /* Enable fan failure interrupt if media type is copper */
2017 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2018 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2019 gpie |= IXGBE_SDP1_GPIEN;
2020 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2021 }
2022
Auke Kok9a799d72007-09-15 14:07:45 -07002023 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002024 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2025 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2026 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2027
2028 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2029 }
2030
2031 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002032 j = adapter->tx_ring[i].reg_idx;
2033 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002034 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2035 txdctl |= (8 << 16);
Auke Kok9a799d72007-09-15 14:07:45 -07002036 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002037 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002038 }
2039
2040 for (i = 0; i < adapter->num_rx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002041 j = adapter->rx_ring[i].reg_idx;
2042 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2043 /* enable PTHRESH=32 descriptors (half the internal cache)
2044 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2045 * this also removes a pesky rx_no_buffer_count increment */
2046 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002047 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002048 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002049 }
2050 /* enable all receives */
2051 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2052 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2053 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxdctl);
2054
2055 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2056 ixgbe_configure_msix(adapter);
2057 else
2058 ixgbe_configure_msi_and_legacy(adapter);
2059
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08002060 ixgbe_napi_add_all(adapter);
2061
Auke Kok9a799d72007-09-15 14:07:45 -07002062 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002063 ixgbe_napi_enable_all(adapter);
2064
2065 /* clear any pending interrupts, may auto mask */
2066 IXGBE_READ_REG(hw, IXGBE_EICR);
2067
Auke Kok9a799d72007-09-15 14:07:45 -07002068 ixgbe_irq_enable(adapter);
2069
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002070 err = ixgbe_link_config(hw);
2071 if (err)
2072 dev_err(&adapter->pdev->dev, "link_config FAILED %d\n", err);
2073
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002074 /* enable transmits */
2075 netif_tx_start_all_queues(netdev);
2076
Auke Kok9a799d72007-09-15 14:07:45 -07002077 /* bring the link up in the watchdog, this could race with our first
2078 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002079 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2080 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002081 mod_timer(&adapter->watchdog_timer, jiffies);
2082 return 0;
2083}
2084
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002085void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2086{
2087 WARN_ON(in_interrupt());
2088 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2089 msleep(1);
2090 ixgbe_down(adapter);
2091 ixgbe_up(adapter);
2092 clear_bit(__IXGBE_RESETTING, &adapter->state);
2093}
2094
Auke Kok9a799d72007-09-15 14:07:45 -07002095int ixgbe_up(struct ixgbe_adapter *adapter)
2096{
2097 /* hardware has been reset, we need to reload some things */
2098 ixgbe_configure(adapter);
2099
2100 return ixgbe_up_complete(adapter);
2101}
2102
2103void ixgbe_reset(struct ixgbe_adapter *adapter)
2104{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002105 struct ixgbe_hw *hw = &adapter->hw;
2106 if (hw->mac.ops.init_hw(hw))
2107 dev_err(&adapter->pdev->dev, "Hardware Error\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002108
2109 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002110 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002111
2112}
2113
Auke Kok9a799d72007-09-15 14:07:45 -07002114/**
2115 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2116 * @adapter: board private structure
2117 * @rx_ring: ring to free buffers from
2118 **/
2119static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002120 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002121{
2122 struct pci_dev *pdev = adapter->pdev;
2123 unsigned long size;
2124 unsigned int i;
2125
2126 /* Free all the Rx ring sk_buffs */
2127
2128 for (i = 0; i < rx_ring->count; i++) {
2129 struct ixgbe_rx_buffer *rx_buffer_info;
2130
2131 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2132 if (rx_buffer_info->dma) {
2133 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002134 rx_ring->rx_buf_len,
2135 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002136 rx_buffer_info->dma = 0;
2137 }
2138 if (rx_buffer_info->skb) {
2139 dev_kfree_skb(rx_buffer_info->skb);
2140 rx_buffer_info->skb = NULL;
2141 }
2142 if (!rx_buffer_info->page)
2143 continue;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002144 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2145 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002146 rx_buffer_info->page_dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002147 put_page(rx_buffer_info->page);
2148 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002149 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002150 }
2151
2152 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2153 memset(rx_ring->rx_buffer_info, 0, size);
2154
2155 /* Zero out the descriptor ring */
2156 memset(rx_ring->desc, 0, rx_ring->size);
2157
2158 rx_ring->next_to_clean = 0;
2159 rx_ring->next_to_use = 0;
2160
2161 writel(0, adapter->hw.hw_addr + rx_ring->head);
2162 writel(0, adapter->hw.hw_addr + rx_ring->tail);
2163}
2164
2165/**
2166 * ixgbe_clean_tx_ring - Free Tx Buffers
2167 * @adapter: board private structure
2168 * @tx_ring: ring to be cleaned
2169 **/
2170static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002171 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002172{
2173 struct ixgbe_tx_buffer *tx_buffer_info;
2174 unsigned long size;
2175 unsigned int i;
2176
2177 /* Free all the Tx ring sk_buffs */
2178
2179 for (i = 0; i < tx_ring->count; i++) {
2180 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2181 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2182 }
2183
2184 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2185 memset(tx_ring->tx_buffer_info, 0, size);
2186
2187 /* Zero out the descriptor ring */
2188 memset(tx_ring->desc, 0, tx_ring->size);
2189
2190 tx_ring->next_to_use = 0;
2191 tx_ring->next_to_clean = 0;
2192
2193 writel(0, adapter->hw.hw_addr + tx_ring->head);
2194 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2195}
2196
2197/**
Auke Kok9a799d72007-09-15 14:07:45 -07002198 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2199 * @adapter: board private structure
2200 **/
2201static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2202{
2203 int i;
2204
2205 for (i = 0; i < adapter->num_rx_queues; i++)
2206 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2207}
2208
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002209/**
2210 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2211 * @adapter: board private structure
2212 **/
2213static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2214{
2215 int i;
2216
2217 for (i = 0; i < adapter->num_tx_queues; i++)
2218 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2219}
2220
Auke Kok9a799d72007-09-15 14:07:45 -07002221void ixgbe_down(struct ixgbe_adapter *adapter)
2222{
2223 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002224 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002225 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002226 u32 txdctl;
2227 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002228
2229 /* signal that we are down to the interrupt handler */
2230 set_bit(__IXGBE_DOWN, &adapter->state);
2231
2232 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002233 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2234 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002235
2236 netif_tx_disable(netdev);
2237
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002238 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002239 msleep(10);
2240
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002241 netif_tx_stop_all_queues(netdev);
2242
Auke Kok9a799d72007-09-15 14:07:45 -07002243 ixgbe_irq_disable(adapter);
2244
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002245 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002246
Auke Kok9a799d72007-09-15 14:07:45 -07002247 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002248 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002249
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002250 /* disable transmits in the hardware now that interrupts are off */
2251 for (i = 0; i < adapter->num_tx_queues; i++) {
2252 j = adapter->tx_ring[i].reg_idx;
2253 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2254 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2255 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2256 }
2257
Auke Kok9a799d72007-09-15 14:07:45 -07002258 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002259
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002260#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002261 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2262 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
2263 dca_remove_requester(&adapter->pdev->dev);
2264 }
2265
2266#endif
Paul Larson6f4a0e42008-06-24 17:00:56 -07002267 if (!pci_channel_offline(adapter->pdev))
2268 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002269 ixgbe_clean_all_tx_rings(adapter);
2270 ixgbe_clean_all_rx_rings(adapter);
2271
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002272#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002273 /* since we reset the hardware DCA settings were cleared */
2274 if (dca_add_requester(&adapter->pdev->dev) == 0) {
2275 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
2276 /* always use CB2 mode, difference is masked
2277 * in the CB driver */
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002278 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002279 ixgbe_setup_dca(adapter);
2280 }
2281#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002282}
2283
Auke Kok9a799d72007-09-15 14:07:45 -07002284/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002285 * ixgbe_poll - NAPI Rx polling callback
2286 * @napi: structure for representing this polling device
2287 * @budget: how many packets driver is allowed to clean
2288 *
2289 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002290 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002291static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002292{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002293 struct ixgbe_q_vector *q_vector = container_of(napi,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002294 struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002295 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -07002296 int tx_cleaned, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002297
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002298#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002299 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2300 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2301 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2302 }
2303#endif
2304
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002305 tx_cleaned = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002306 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002307
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002308 if (tx_cleaned)
2309 work_done = budget;
2310
David S. Miller53e52c72008-01-07 21:06:12 -08002311 /* If budget not fully consumed, exit the polling mode */
2312 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002313 napi_complete(napi);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002314 if (adapter->itr_setting & 3)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002315 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002316 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2317 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002318 }
Auke Kok9a799d72007-09-15 14:07:45 -07002319 return work_done;
2320}
2321
2322/**
2323 * ixgbe_tx_timeout - Respond to a Tx Hang
2324 * @netdev: network interface device structure
2325 **/
2326static void ixgbe_tx_timeout(struct net_device *netdev)
2327{
2328 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2329
2330 /* Do the reset outside of interrupt context */
2331 schedule_work(&adapter->reset_task);
2332}
2333
2334static void ixgbe_reset_task(struct work_struct *work)
2335{
2336 struct ixgbe_adapter *adapter;
2337 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2338
Alexander Duyck2f90b862008-11-20 20:52:10 -08002339 /* If we're already down or resetting, just bail */
2340 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2341 test_bit(__IXGBE_RESETTING, &adapter->state))
2342 return;
2343
Auke Kok9a799d72007-09-15 14:07:45 -07002344 adapter->tx_timeout_count++;
2345
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002346 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002347}
2348
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002349#ifdef CONFIG_IXGBE_DCB
2350static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002351{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002352 bool ret = false;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002353
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002354 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2355 adapter->ring_feature[RING_F_DCB].mask = 0x7 << 3;
2356 adapter->num_rx_queues =
2357 adapter->ring_feature[RING_F_DCB].indices;
2358 adapter->num_tx_queues =
2359 adapter->ring_feature[RING_F_DCB].indices;
2360 ret = true;
2361 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002362 ret = false;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002363 }
2364
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002365 return ret;
2366}
2367#endif
2368
2369static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
2370{
2371 bool ret = false;
2372
2373 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2374 adapter->ring_feature[RING_F_RSS].mask = 0xF;
2375 adapter->num_rx_queues =
2376 adapter->ring_feature[RING_F_RSS].indices;
2377 adapter->num_tx_queues =
2378 adapter->ring_feature[RING_F_RSS].indices;
2379 ret = true;
2380 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002381 ret = false;
2382 }
2383
2384 return ret;
2385}
2386
2387static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2388{
2389 /* Start with base case */
2390 adapter->num_rx_queues = 1;
2391 adapter->num_tx_queues = 1;
2392
2393#ifdef CONFIG_IXGBE_DCB
2394 if (ixgbe_set_dcb_queues(adapter))
2395 return;
2396
2397#endif
2398 if (ixgbe_set_rss_queues(adapter))
2399 return;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002400}
2401
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002402static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002403 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002404{
2405 int err, vector_threshold;
2406
2407 /* We'll want at least 3 (vector_threshold):
2408 * 1) TxQ[0] Cleanup
2409 * 2) RxQ[0] Cleanup
2410 * 3) Other (Link Status Change, etc.)
2411 * 4) TCP Timer (optional)
2412 */
2413 vector_threshold = MIN_MSIX_COUNT;
2414
2415 /* The more we get, the more we will assign to Tx/Rx Cleanup
2416 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2417 * Right now, we simply care about how many we'll get; we'll
2418 * set them up later while requesting irq's.
2419 */
2420 while (vectors >= vector_threshold) {
2421 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002422 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002423 if (!err) /* Success in acquiring all requested vectors. */
2424 break;
2425 else if (err < 0)
2426 vectors = 0; /* Nasty failure, quit now */
2427 else /* err == number of vectors we should try again with */
2428 vectors = err;
2429 }
2430
2431 if (vectors < vector_threshold) {
2432 /* Can't allocate enough MSI-X interrupts? Oh well.
2433 * This just means we'll go with either a single MSI
2434 * vector or fall back to legacy interrupts.
2435 */
2436 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2437 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2438 kfree(adapter->msix_entries);
2439 adapter->msix_entries = NULL;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002440 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002441 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002442 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002443 } else {
2444 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08002445 /*
2446 * Adjust for only the vectors we'll use, which is minimum
2447 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
2448 * vectors we were allocated.
2449 */
2450 adapter->num_msix_vectors = min(vectors,
2451 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002452 }
2453}
2454
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002455/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002456 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002457 * @adapter: board private structure to initialize
2458 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002459 * Cache the descriptor ring offsets for RSS to the assigned rings.
2460 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002461 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002462static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002463{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002464 int i;
2465 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002466
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002467 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2468 for (i = 0; i < adapter->num_rx_queues; i++)
2469 adapter->rx_ring[i].reg_idx = i;
2470 for (i = 0; i < adapter->num_tx_queues; i++)
2471 adapter->tx_ring[i].reg_idx = i;
2472 ret = true;
2473 } else {
2474 ret = false;
2475 }
2476
2477 return ret;
2478}
2479
2480#ifdef CONFIG_IXGBE_DCB
2481/**
2482 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
2483 * @adapter: board private structure to initialize
2484 *
2485 * Cache the descriptor ring offsets for DCB to the assigned rings.
2486 *
2487 **/
2488static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
2489{
2490 int i;
2491 bool ret = false;
2492 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2493
2494 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2495 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002496 /* the number of queues is assumed to be symmetric */
2497 for (i = 0; i < dcb_i; i++) {
2498 adapter->rx_ring[i].reg_idx = i << 3;
2499 adapter->tx_ring[i].reg_idx = i << 2;
2500 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002501 ret = true;
2502 } else {
2503 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002504 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002505 } else {
2506 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002507 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002508
2509 return ret;
2510}
2511#endif
2512
2513/**
2514 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2515 * @adapter: board private structure to initialize
2516 *
2517 * Once we know the feature-set enabled for the device, we'll cache
2518 * the register offset the descriptor ring is assigned to.
2519 *
2520 * Note, the order the various feature calls is important. It must start with
2521 * the "most" features enabled at the same time, then trickle down to the
2522 * least amount of features turned on at once.
2523 **/
2524static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
2525{
2526 /* start with default case */
2527 adapter->rx_ring[0].reg_idx = 0;
2528 adapter->tx_ring[0].reg_idx = 0;
2529
2530#ifdef CONFIG_IXGBE_DCB
2531 if (ixgbe_cache_ring_dcb(adapter))
2532 return;
2533
2534#endif
2535 if (ixgbe_cache_ring_rss(adapter))
2536 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002537}
2538
Auke Kok9a799d72007-09-15 14:07:45 -07002539/**
2540 * ixgbe_alloc_queues - Allocate memory for all rings
2541 * @adapter: board private structure to initialize
2542 *
2543 * We allocate one ring per queue at run-time since we don't know the
Wang Chena4d2f342008-12-03 22:05:58 -08002544 * number of queues at compile-time.
Auke Kok9a799d72007-09-15 14:07:45 -07002545 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002546static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002547{
2548 int i;
2549
2550 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002551 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07002552 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002553 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07002554
2555 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002556 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002557 if (!adapter->rx_ring)
2558 goto err_rx_ring_allocation;
2559
2560 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002561 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002562 adapter->tx_ring[i].queue_index = i;
2563 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002564
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002565 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002566 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002567 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07002568 }
2569
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002570 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002571
2572 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002573
2574err_rx_ring_allocation:
2575 kfree(adapter->tx_ring);
2576err_tx_ring_allocation:
2577 return -ENOMEM;
2578}
2579
2580/**
2581 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
2582 * @adapter: board private structure to initialize
2583 *
2584 * Attempt to configure the interrupts using the best available
2585 * capabilities of the hardware and the kernel.
2586 **/
Al Virofeea6a52008-11-27 15:34:07 -08002587static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002588{
2589 int err = 0;
2590 int vector, v_budget;
2591
2592 /*
2593 * It's easy to be greedy for MSI-X vectors, but it really
2594 * doesn't do us much good if we have a lot more vectors
2595 * than CPU's. So let's be conservative and only ask for
2596 * (roughly) twice the number of vectors as there are CPU's.
2597 */
2598 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002599 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002600
2601 /*
2602 * At the same time, hardware can only support a maximum of
2603 * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq,
2604 * we can easily reach upwards of 64 Rx descriptor queues and
2605 * 32 Tx queues. Thus, we cap it off in those rare cases where
2606 * the cpu count also exceeds our vector limit.
2607 */
2608 v_budget = min(v_budget, MAX_MSIX_COUNT);
2609
2610 /* A failure in MSI-X entry allocation isn't fatal, but it does
2611 * mean we disable MSI-X capabilities of the adapter. */
2612 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002613 sizeof(struct msix_entry), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002614 if (!adapter->msix_entries) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002615 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002616 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2617 ixgbe_set_num_queues(adapter);
2618 kfree(adapter->tx_ring);
2619 kfree(adapter->rx_ring);
2620 err = ixgbe_alloc_queues(adapter);
2621 if (err) {
2622 DPRINTK(PROBE, ERR, "Unable to allocate memory "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002623 "for queues\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002624 goto out;
2625 }
2626
2627 goto try_msi;
2628 }
2629
2630 for (vector = 0; vector < v_budget; vector++)
2631 adapter->msix_entries[vector].entry = vector;
2632
2633 ixgbe_acquire_msix_vectors(adapter, v_budget);
2634
2635 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2636 goto out;
2637
2638try_msi:
2639 err = pci_enable_msi(adapter->pdev);
2640 if (!err) {
2641 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
2642 } else {
2643 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002644 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002645 /* reset err */
2646 err = 0;
2647 }
2648
2649out:
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08002650 /* Notify the stack of the (possibly) reduced Tx Queue count. */
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002651 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002652
2653 return err;
2654}
2655
Alexander Duyck2f90b862008-11-20 20:52:10 -08002656void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002657{
2658 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2659 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2660 pci_disable_msix(adapter->pdev);
2661 kfree(adapter->msix_entries);
2662 adapter->msix_entries = NULL;
2663 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2664 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
2665 pci_disable_msi(adapter->pdev);
2666 }
2667 return;
2668}
2669
2670/**
2671 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
2672 * @adapter: board private structure to initialize
2673 *
2674 * We determine which interrupt scheme to use based on...
2675 * - Kernel support (MSI, MSI-X)
2676 * - which can be user-defined (via MODULE_PARAM)
2677 * - Hardware queue count (num_*_queues)
2678 * - defined by miscellaneous hardware support/features (RSS, etc.)
2679 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002680int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002681{
2682 int err;
2683
2684 /* Number of supported queues */
2685 ixgbe_set_num_queues(adapter);
2686
2687 err = ixgbe_alloc_queues(adapter);
2688 if (err) {
2689 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
2690 goto err_alloc_queues;
2691 }
2692
2693 err = ixgbe_set_interrupt_capability(adapter);
2694 if (err) {
2695 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
2696 goto err_set_interrupt;
2697 }
2698
2699 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002700 "Tx Queue count = %u\n",
2701 (adapter->num_rx_queues > 1) ? "Enabled" :
2702 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002703
2704 set_bit(__IXGBE_DOWN, &adapter->state);
2705
2706 return 0;
2707
2708err_set_interrupt:
2709 kfree(adapter->tx_ring);
2710 kfree(adapter->rx_ring);
2711err_alloc_queues:
2712 return err;
Auke Kok9a799d72007-09-15 14:07:45 -07002713}
2714
2715/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08002716 * ixgbe_sfp_timer - worker thread to find a missing module
2717 * @data: pointer to our adapter struct
2718 **/
2719static void ixgbe_sfp_timer(unsigned long data)
2720{
2721 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
2722
2723 /* Do the sfp_timer outside of interrupt context due to the
2724 * delays that sfp+ detection requires
2725 */
2726 schedule_work(&adapter->sfp_task);
2727}
2728
2729/**
2730 * ixgbe_sfp_task - worker thread to find a missing module
2731 * @work: pointer to work_struct containing our data
2732 **/
2733static void ixgbe_sfp_task(struct work_struct *work)
2734{
2735 struct ixgbe_adapter *adapter = container_of(work,
2736 struct ixgbe_adapter,
2737 sfp_task);
2738 struct ixgbe_hw *hw = &adapter->hw;
2739
2740 if ((hw->phy.type == ixgbe_phy_nl) &&
2741 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
2742 s32 ret = hw->phy.ops.identify_sfp(hw);
2743 if (ret)
2744 goto reschedule;
2745 ret = hw->phy.ops.reset(hw);
2746 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2747 DPRINTK(PROBE, ERR, "failed to initialize because an "
2748 "unsupported SFP+ module type was detected.\n"
2749 "Reload the driver after installing a "
2750 "supported module.\n");
2751 unregister_netdev(adapter->netdev);
2752 } else {
2753 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
2754 hw->phy.sfp_type);
2755 }
2756 /* don't need this routine any more */
2757 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
2758 }
2759 return;
2760reschedule:
2761 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
2762 mod_timer(&adapter->sfp_timer,
2763 round_jiffies(jiffies + (2 * HZ)));
2764}
2765
2766/**
Auke Kok9a799d72007-09-15 14:07:45 -07002767 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
2768 * @adapter: board private structure to initialize
2769 *
2770 * ixgbe_sw_init initializes the Adapter private data structure.
2771 * Fields are initialized based on PCI device information and
2772 * OS network device settings (MTU size).
2773 **/
2774static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
2775{
2776 struct ixgbe_hw *hw = &adapter->hw;
2777 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002778 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002779#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002780 int j;
2781 struct tc_configuration *tc;
2782#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002783
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002784 /* PCI config space info */
2785
2786 hw->vendor_id = pdev->vendor;
2787 hw->device_id = pdev->device;
2788 hw->revision_id = pdev->revision;
2789 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2790 hw->subsystem_device_id = pdev->subsystem_device;
2791
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002792 /* Set capability flags */
2793 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
2794 adapter->ring_feature[RING_F_RSS].indices = rss;
2795 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002796 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08002797 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002798
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002799#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002800 /* Configure DCB traffic classes */
2801 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
2802 tc = &adapter->dcb_cfg.tc_config[j];
2803 tc->path[DCB_TX_CONFIG].bwg_id = 0;
2804 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
2805 tc->path[DCB_RX_CONFIG].bwg_id = 0;
2806 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
2807 tc->dcb_pfc = pfc_disabled;
2808 }
2809 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
2810 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
2811 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
2812 adapter->dcb_cfg.round_robin_enable = false;
2813 adapter->dcb_set_bitmap = 0x00;
2814 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
2815 adapter->ring_feature[RING_F_DCB].indices);
2816
2817#endif
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002818 if (hw->mac.ops.get_media_type &&
2819 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper))
2820 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Auke Kok9a799d72007-09-15 14:07:45 -07002821
2822 /* default flow control settings */
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002823 hw->fc.requested_mode = ixgbe_fc_none;
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07002824 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
2825 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
2826 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
2827 hw->fc.send_xon = true;
Auke Kok9a799d72007-09-15 14:07:45 -07002828
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002829 /* enable itr by default in dynamic mode */
2830 adapter->itr_setting = 1;
2831 adapter->eitr_param = 20000;
2832
2833 /* set defaults for eitr in MegaBytes */
2834 adapter->eitr_low = 10;
2835 adapter->eitr_high = 20;
2836
2837 /* set default ring sizes */
2838 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
2839 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
2840
Auke Kok9a799d72007-09-15 14:07:45 -07002841 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002842 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002843 dev_err(&pdev->dev, "EEPROM initialization failed\n");
2844 return -EIO;
2845 }
2846
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002847 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07002848 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
2849
Auke Kok9a799d72007-09-15 14:07:45 -07002850 set_bit(__IXGBE_DOWN, &adapter->state);
2851
2852 return 0;
2853}
2854
2855/**
2856 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
2857 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002858 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07002859 *
2860 * Return 0 on success, negative on failure
2861 **/
2862int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002863 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002864{
2865 struct pci_dev *pdev = adapter->pdev;
2866 int size;
2867
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002868 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2869 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002870 if (!tx_ring->tx_buffer_info)
2871 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002872 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07002873
2874 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08002875 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002876 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07002877
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002878 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
2879 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002880 if (!tx_ring->desc)
2881 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07002882
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002883 tx_ring->next_to_use = 0;
2884 tx_ring->next_to_clean = 0;
2885 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07002886 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002887
2888err:
2889 vfree(tx_ring->tx_buffer_info);
2890 tx_ring->tx_buffer_info = NULL;
2891 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
2892 "descriptor ring\n");
2893 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07002894}
2895
2896/**
Alexander Duyck69888672008-09-11 20:05:39 -07002897 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
2898 * @adapter: board private structure
2899 *
2900 * If this function returns with an error, then it's possible one or
2901 * more of the rings is populated (while the rest are not). It is the
2902 * callers duty to clean those orphaned rings.
2903 *
2904 * Return 0 on success, negative on failure
2905 **/
2906static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
2907{
2908 int i, err = 0;
2909
2910 for (i = 0; i < adapter->num_tx_queues; i++) {
2911 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
2912 if (!err)
2913 continue;
2914 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
2915 break;
2916 }
2917
2918 return err;
2919}
2920
2921/**
Auke Kok9a799d72007-09-15 14:07:45 -07002922 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
2923 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002924 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07002925 *
2926 * Returns 0 on success, negative on failure
2927 **/
2928int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002929 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002930{
2931 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002932 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002933
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002934 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2935 rx_ring->rx_buffer_info = vmalloc(size);
2936 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07002937 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002938 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002939 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07002940 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002941 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07002942
Auke Kok9a799d72007-09-15 14:07:45 -07002943 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002944 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
2945 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07002946
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002947 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07002948
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002949 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07002950 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002951 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002952 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002953 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07002954 }
2955
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002956 rx_ring->next_to_clean = 0;
2957 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002958
2959 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002960
2961alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002962 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07002963}
2964
2965/**
Alexander Duyck69888672008-09-11 20:05:39 -07002966 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
2967 * @adapter: board private structure
2968 *
2969 * If this function returns with an error, then it's possible one or
2970 * more of the rings is populated (while the rest are not). It is the
2971 * callers duty to clean those orphaned rings.
2972 *
2973 * Return 0 on success, negative on failure
2974 **/
2975
2976static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
2977{
2978 int i, err = 0;
2979
2980 for (i = 0; i < adapter->num_rx_queues; i++) {
2981 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
2982 if (!err)
2983 continue;
2984 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
2985 break;
2986 }
2987
2988 return err;
2989}
2990
2991/**
Auke Kok9a799d72007-09-15 14:07:45 -07002992 * ixgbe_free_tx_resources - Free Tx Resources per Queue
2993 * @adapter: board private structure
2994 * @tx_ring: Tx descriptor ring for a specific queue
2995 *
2996 * Free all transmit software resources
2997 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07002998void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
2999 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003000{
3001 struct pci_dev *pdev = adapter->pdev;
3002
3003 ixgbe_clean_tx_ring(adapter, tx_ring);
3004
3005 vfree(tx_ring->tx_buffer_info);
3006 tx_ring->tx_buffer_info = NULL;
3007
3008 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
3009
3010 tx_ring->desc = NULL;
3011}
3012
3013/**
3014 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
3015 * @adapter: board private structure
3016 *
3017 * Free all transmit software resources
3018 **/
3019static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
3020{
3021 int i;
3022
3023 for (i = 0; i < adapter->num_tx_queues; i++)
3024 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
3025}
3026
3027/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003028 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07003029 * @adapter: board private structure
3030 * @rx_ring: ring to clean the resources from
3031 *
3032 * Free all receive software resources
3033 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003034void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
3035 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003036{
3037 struct pci_dev *pdev = adapter->pdev;
3038
3039 ixgbe_clean_rx_ring(adapter, rx_ring);
3040
3041 vfree(rx_ring->rx_buffer_info);
3042 rx_ring->rx_buffer_info = NULL;
3043
3044 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
3045
3046 rx_ring->desc = NULL;
3047}
3048
3049/**
3050 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
3051 * @adapter: board private structure
3052 *
3053 * Free all receive software resources
3054 **/
3055static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
3056{
3057 int i;
3058
3059 for (i = 0; i < adapter->num_rx_queues; i++)
3060 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
3061}
3062
3063/**
Auke Kok9a799d72007-09-15 14:07:45 -07003064 * ixgbe_change_mtu - Change the Maximum Transfer Unit
3065 * @netdev: network interface device structure
3066 * @new_mtu: new value for maximum frame size
3067 *
3068 * Returns 0 on success, negative on failure
3069 **/
3070static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
3071{
3072 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3073 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3074
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07003075 /* MTU < 68 is an error and causes problems on some kernels */
3076 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07003077 return -EINVAL;
3078
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003079 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003080 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003081 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07003082 netdev->mtu = new_mtu;
3083
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003084 if (netif_running(netdev))
3085 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003086
3087 return 0;
3088}
3089
3090/**
3091 * ixgbe_open - Called when a network interface is made active
3092 * @netdev: network interface device structure
3093 *
3094 * Returns 0 on success, negative value on failure
3095 *
3096 * The open entry point is called when a network interface is made
3097 * active by the system (IFF_UP). At this point all resources needed
3098 * for transmit and receive operations are allocated, the interrupt
3099 * handler is registered with the OS, the watchdog timer is started,
3100 * and the stack is notified that the interface is ready.
3101 **/
3102static int ixgbe_open(struct net_device *netdev)
3103{
3104 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3105 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003106
Auke Kok4bebfaa2008-02-11 09:26:01 -08003107 /* disallow open during test */
3108 if (test_bit(__IXGBE_TESTING, &adapter->state))
3109 return -EBUSY;
3110
Auke Kok9a799d72007-09-15 14:07:45 -07003111 /* allocate transmit descriptors */
3112 err = ixgbe_setup_all_tx_resources(adapter);
3113 if (err)
3114 goto err_setup_tx;
3115
Auke Kok9a799d72007-09-15 14:07:45 -07003116 /* allocate receive descriptors */
3117 err = ixgbe_setup_all_rx_resources(adapter);
3118 if (err)
3119 goto err_setup_rx;
3120
3121 ixgbe_configure(adapter);
3122
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003123 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003124 if (err)
3125 goto err_req_irq;
3126
Auke Kok9a799d72007-09-15 14:07:45 -07003127 err = ixgbe_up_complete(adapter);
3128 if (err)
3129 goto err_up;
3130
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003131 netif_tx_start_all_queues(netdev);
3132
Auke Kok9a799d72007-09-15 14:07:45 -07003133 return 0;
3134
3135err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003136 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003137 ixgbe_free_irq(adapter);
3138err_req_irq:
3139 ixgbe_free_all_rx_resources(adapter);
3140err_setup_rx:
3141 ixgbe_free_all_tx_resources(adapter);
3142err_setup_tx:
3143 ixgbe_reset(adapter);
3144
3145 return err;
3146}
3147
3148/**
3149 * ixgbe_close - Disables a network interface
3150 * @netdev: network interface device structure
3151 *
3152 * Returns 0, this is not allowed to fail
3153 *
3154 * The close entry point is called when an interface is de-activated
3155 * by the OS. The hardware is still under the drivers control, but
3156 * needs to be disabled. A global MAC reset is issued to stop the
3157 * hardware, and all transmit and receive resources are freed.
3158 **/
3159static int ixgbe_close(struct net_device *netdev)
3160{
3161 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003162
3163 ixgbe_down(adapter);
3164 ixgbe_free_irq(adapter);
3165
3166 ixgbe_free_all_tx_resources(adapter);
3167 ixgbe_free_all_rx_resources(adapter);
3168
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003169 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003170
3171 return 0;
3172}
3173
3174/**
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003175 * ixgbe_napi_add_all - prep napi structs for use
3176 * @adapter: private struct
3177 * helper function to napi_add each possible q_vector->napi
3178 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08003179void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003180{
3181 int q_idx, q_vectors;
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003182 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003183 int (*poll)(struct napi_struct *, int);
3184
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003185 /* check if we already have our netdev->napi_list populated */
3186 if (&netdev->napi_list != netdev->napi_list.next)
3187 return;
3188
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003189 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3190 poll = &ixgbe_clean_rxonly;
3191 /* Only enable as many vectors as we have rx queues. */
3192 q_vectors = adapter->num_rx_queues;
3193 } else {
3194 poll = &ixgbe_poll;
3195 /* only one q_vector for legacy modes */
3196 q_vectors = 1;
3197 }
3198
3199 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3200 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3201 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
3202 }
3203}
3204
Alexander Duyck2f90b862008-11-20 20:52:10 -08003205void ixgbe_napi_del_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003206{
3207 int q_idx;
3208 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3209
3210 /* legacy and MSI only use one vector */
3211 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3212 q_vectors = 1;
3213
3214 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3215 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3216 if (!q_vector->rxr_count)
3217 continue;
3218 netif_napi_del(&q_vector->napi);
3219 }
3220}
3221
3222#ifdef CONFIG_PM
3223static int ixgbe_resume(struct pci_dev *pdev)
3224{
3225 struct net_device *netdev = pci_get_drvdata(pdev);
3226 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3227 u32 err;
3228
3229 pci_set_power_state(pdev, PCI_D0);
3230 pci_restore_state(pdev);
3231 err = pci_enable_device(pdev);
3232 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07003233 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003234 "suspend\n");
3235 return err;
3236 }
3237 pci_set_master(pdev);
3238
3239 pci_enable_wake(pdev, PCI_D3hot, 0);
3240 pci_enable_wake(pdev, PCI_D3cold, 0);
3241
3242 err = ixgbe_init_interrupt_scheme(adapter);
3243 if (err) {
3244 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
3245 "device\n");
3246 return err;
3247 }
3248
3249 ixgbe_napi_add_all(adapter);
3250 ixgbe_reset(adapter);
3251
3252 if (netif_running(netdev)) {
3253 err = ixgbe_open(adapter->netdev);
3254 if (err)
3255 return err;
3256 }
3257
3258 netif_device_attach(netdev);
3259
3260 return 0;
3261}
3262
3263#endif /* CONFIG_PM */
3264static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
3265{
3266 struct net_device *netdev = pci_get_drvdata(pdev);
3267 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3268#ifdef CONFIG_PM
3269 int retval = 0;
3270#endif
3271
3272 netif_device_detach(netdev);
3273
3274 if (netif_running(netdev)) {
3275 ixgbe_down(adapter);
3276 ixgbe_free_irq(adapter);
3277 ixgbe_free_all_tx_resources(adapter);
3278 ixgbe_free_all_rx_resources(adapter);
3279 }
3280 ixgbe_reset_interrupt_capability(adapter);
3281 ixgbe_napi_del_all(adapter);
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003282 INIT_LIST_HEAD(&netdev->napi_list);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003283 kfree(adapter->tx_ring);
3284 kfree(adapter->rx_ring);
3285
3286#ifdef CONFIG_PM
3287 retval = pci_save_state(pdev);
3288 if (retval)
3289 return retval;
3290#endif
3291
3292 pci_enable_wake(pdev, PCI_D3hot, 0);
3293 pci_enable_wake(pdev, PCI_D3cold, 0);
3294
3295 ixgbe_release_hw_control(adapter);
3296
3297 pci_disable_device(pdev);
3298
3299 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3300
3301 return 0;
3302}
3303
3304static void ixgbe_shutdown(struct pci_dev *pdev)
3305{
3306 ixgbe_suspend(pdev, PMSG_SUSPEND);
3307}
3308
3309/**
Auke Kok9a799d72007-09-15 14:07:45 -07003310 * ixgbe_update_stats - Update the board statistics counters.
3311 * @adapter: board private structure
3312 **/
3313void ixgbe_update_stats(struct ixgbe_adapter *adapter)
3314{
3315 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003316 u64 total_mpc = 0;
3317 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003318
3319 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003320 for (i = 0; i < 8; i++) {
3321 /* for packet buffers not used, the register should read 0 */
3322 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
3323 missed_rx += mpc;
3324 adapter->stats.mpc[i] += mpc;
3325 total_mpc += adapter->stats.mpc[i];
3326 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08003327 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
3328 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
3329 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
3330 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
3331 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3332 IXGBE_PXONRXC(i));
3333 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
3334 IXGBE_PXONTXC(i));
3335 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3336 IXGBE_PXOFFRXC(i));
3337 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
3338 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003339 }
3340 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
3341 /* work around hardware counting issue */
3342 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07003343
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003344 /* 82598 hardware only has a 32 bit counter in the high register */
Auke Kok9a799d72007-09-15 14:07:45 -07003345 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003346 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
3347 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
Auke Kok9a799d72007-09-15 14:07:45 -07003348 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
3349 adapter->stats.bprc += bprc;
3350 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
3351 adapter->stats.mprc -= bprc;
3352 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
3353 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
3354 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
3355 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
3356 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
3357 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
3358 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003359 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
3360 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Auke Kok9a799d72007-09-15 14:07:45 -07003361 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003362 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
3363 adapter->stats.lxontxc += lxon;
3364 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
3365 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07003366 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3367 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003368 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
3369 /*
3370 * 82598 errata - tx of flow control packets is included in tx counters
3371 */
3372 xon_off_tot = lxon + lxoff;
3373 adapter->stats.gptc -= xon_off_tot;
3374 adapter->stats.mptc -= xon_off_tot;
3375 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07003376 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3377 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
3378 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07003379 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
3380 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003381 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003382 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3383 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3384 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3385 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3386 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003387 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3388
3389 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07003390 adapter->net_stats.multicast = adapter->stats.mprc;
3391
3392 /* Rx Errors */
3393 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003394 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07003395 adapter->net_stats.rx_dropped = 0;
3396 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3397 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003398 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07003399}
3400
3401/**
3402 * ixgbe_watchdog - Timer Call-back
3403 * @data: pointer to adapter cast into an unsigned long
3404 **/
3405static void ixgbe_watchdog(unsigned long data)
3406{
3407 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003408 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003409
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003410 /* Do the watchdog outside of interrupt context due to the lovely
3411 * delays that some of the newer hardware requires */
3412 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
3413 /* Cause software interrupt to ensure rx rings are cleaned */
3414 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3415 u32 eics =
3416 (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1;
3417 IXGBE_WRITE_REG(hw, IXGBE_EICS, eics);
3418 } else {
3419 /* For legacy and MSI interrupts don't set any bits that
3420 * are enabled for EIAM, because this operation would
3421 * set *both* EIMS and EICS for any bit in EIAM */
3422 IXGBE_WRITE_REG(hw, IXGBE_EICS,
3423 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
3424 }
3425 /* Reset the timer */
3426 mod_timer(&adapter->watchdog_timer,
3427 round_jiffies(jiffies + 2 * HZ));
3428 }
3429
3430 schedule_work(&adapter->watchdog_task);
3431}
3432
3433/**
Alexander Duyck69888672008-09-11 20:05:39 -07003434 * ixgbe_watchdog_task - worker thread to bring link up
3435 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003436 **/
3437static void ixgbe_watchdog_task(struct work_struct *work)
3438{
3439 struct ixgbe_adapter *adapter = container_of(work,
3440 struct ixgbe_adapter,
3441 watchdog_task);
3442 struct net_device *netdev = adapter->netdev;
3443 struct ixgbe_hw *hw = &adapter->hw;
3444 u32 link_speed = adapter->link_speed;
3445 bool link_up = adapter->link_up;
3446
3447 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
3448
3449 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3450 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
3451 if (link_up ||
3452 time_after(jiffies, (adapter->link_check_timeout +
3453 IXGBE_TRY_LINK_TIMEOUT))) {
3454 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
3455 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
3456 }
3457 adapter->link_up = link_up;
3458 adapter->link_speed = link_speed;
3459 }
Auke Kok9a799d72007-09-15 14:07:45 -07003460
3461 if (link_up) {
3462 if (!netif_carrier_ok(netdev)) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003463 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3464 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
Auke Kok9a799d72007-09-15 14:07:45 -07003465#define FLOW_RX (frctl & IXGBE_FCTRL_RFCE)
3466#define FLOW_TX (rmcs & IXGBE_RMCS_TFCE_802_3X)
Jeff Kirshera46e5342008-11-27 00:22:21 -08003467 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
3468 "Flow Control: %s\n",
3469 netdev->name,
3470 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
3471 "10 Gbps" :
3472 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
3473 "1 Gbps" : "unknown speed")),
3474 ((FLOW_RX && FLOW_TX) ? "RX/TX" :
3475 (FLOW_RX ? "RX" :
3476 (FLOW_TX ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07003477
3478 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003479 } else {
3480 /* Force detection of hung controller */
3481 adapter->detect_tx_hung = true;
3482 }
3483 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003484 adapter->link_up = false;
3485 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003486 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08003487 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
3488 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07003489 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003490 }
3491 }
3492
3493 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003494 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07003495}
3496
Auke Kok9a799d72007-09-15 14:07:45 -07003497static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003498 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
3499 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07003500{
3501 struct ixgbe_adv_tx_context_desc *context_desc;
3502 unsigned int i;
3503 int err;
3504 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003505 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
3506 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07003507
3508 if (skb_is_gso(skb)) {
3509 if (skb_header_cloned(skb)) {
3510 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3511 if (err)
3512 return err;
3513 }
3514 l4len = tcp_hdrlen(skb);
3515 *hdr_len += l4len;
3516
Al Viro8327d002007-12-10 18:54:12 +00003517 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003518 struct iphdr *iph = ip_hdr(skb);
3519 iph->tot_len = 0;
3520 iph->check = 0;
3521 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003522 iph->daddr, 0,
3523 IPPROTO_TCP,
3524 0);
Auke Kok9a799d72007-09-15 14:07:45 -07003525 adapter->hw_tso_ctxt++;
3526 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3527 ipv6_hdr(skb)->payload_len = 0;
3528 tcp_hdr(skb)->check =
3529 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003530 &ipv6_hdr(skb)->daddr,
3531 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07003532 adapter->hw_tso6_ctxt++;
3533 }
3534
3535 i = tx_ring->next_to_use;
3536
3537 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3538 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3539
3540 /* VLAN MACLEN IPLEN */
3541 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3542 vlan_macip_lens |=
3543 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3544 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003545 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003546 *hdr_len += skb_network_offset(skb);
3547 vlan_macip_lens |=
3548 (skb_transport_header(skb) - skb_network_header(skb));
3549 *hdr_len +=
3550 (skb_transport_header(skb) - skb_network_header(skb));
3551 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3552 context_desc->seqnum_seed = 0;
3553
3554 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003555 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003556 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07003557
Al Viro8327d002007-12-10 18:54:12 +00003558 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07003559 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3560 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3561 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3562
3563 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003564 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07003565 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
3566 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003567 /* use index 1 for TSO */
3568 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003569 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
3570
3571 tx_buffer_info->time_stamp = jiffies;
3572 tx_buffer_info->next_to_watch = i;
3573
3574 i++;
3575 if (i == tx_ring->count)
3576 i = 0;
3577 tx_ring->next_to_use = i;
3578
3579 return true;
3580 }
3581 return false;
3582}
3583
3584static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003585 struct ixgbe_ring *tx_ring,
3586 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07003587{
3588 struct ixgbe_adv_tx_context_desc *context_desc;
3589 unsigned int i;
3590 struct ixgbe_tx_buffer *tx_buffer_info;
3591 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3592
3593 if (skb->ip_summed == CHECKSUM_PARTIAL ||
3594 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
3595 i = tx_ring->next_to_use;
3596 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3597 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3598
3599 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3600 vlan_macip_lens |=
3601 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3602 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003603 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003604 if (skb->ip_summed == CHECKSUM_PARTIAL)
3605 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003606 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07003607
3608 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3609 context_desc->seqnum_seed = 0;
3610
3611 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003612 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07003613
3614 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08003615 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08003616 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07003617 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08003618 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3619 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003620 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08003621 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08003622 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08003623 /* XXX what about other V6 headers?? */
3624 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3625 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003626 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08003627 break;
Auke Kok41825d72008-02-12 15:20:33 -08003628 default:
3629 if (unlikely(net_ratelimit())) {
3630 DPRINTK(PROBE, WARNING,
3631 "partial checksum but proto=%x!\n",
3632 skb->protocol);
3633 }
3634 break;
3635 }
Auke Kok9a799d72007-09-15 14:07:45 -07003636 }
3637
3638 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003639 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07003640 context_desc->mss_l4len_idx = 0;
3641
3642 tx_buffer_info->time_stamp = jiffies;
3643 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003644
Auke Kok9a799d72007-09-15 14:07:45 -07003645 adapter->hw_csum_tx_good++;
3646 i++;
3647 if (i == tx_ring->count)
3648 i = 0;
3649 tx_ring->next_to_use = i;
3650
3651 return true;
3652 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003653
Auke Kok9a799d72007-09-15 14:07:45 -07003654 return false;
3655}
3656
3657static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003658 struct ixgbe_ring *tx_ring,
3659 struct sk_buff *skb, unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07003660{
3661 struct ixgbe_tx_buffer *tx_buffer_info;
3662 unsigned int len = skb->len;
3663 unsigned int offset = 0, size, count = 0, i;
3664 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3665 unsigned int f;
3666
3667 len -= skb->data_len;
3668
3669 i = tx_ring->next_to_use;
3670
3671 while (len) {
3672 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3673 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3674
3675 tx_buffer_info->length = size;
3676 tx_buffer_info->dma = pci_map_single(adapter->pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003677 skb->data + offset,
3678 size, PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003679 tx_buffer_info->time_stamp = jiffies;
3680 tx_buffer_info->next_to_watch = i;
3681
3682 len -= size;
3683 offset += size;
3684 count++;
3685 i++;
3686 if (i == tx_ring->count)
3687 i = 0;
3688 }
3689
3690 for (f = 0; f < nr_frags; f++) {
3691 struct skb_frag_struct *frag;
3692
3693 frag = &skb_shinfo(skb)->frags[f];
3694 len = frag->size;
3695 offset = frag->page_offset;
3696
3697 while (len) {
3698 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3699 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3700
3701 tx_buffer_info->length = size;
3702 tx_buffer_info->dma = pci_map_page(adapter->pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003703 frag->page,
3704 offset,
3705 size,
3706 PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003707 tx_buffer_info->time_stamp = jiffies;
3708 tx_buffer_info->next_to_watch = i;
3709
3710 len -= size;
3711 offset += size;
3712 count++;
3713 i++;
3714 if (i == tx_ring->count)
3715 i = 0;
3716 }
3717 }
3718 if (i == 0)
3719 i = tx_ring->count - 1;
3720 else
3721 i = i - 1;
3722 tx_ring->tx_buffer_info[i].skb = skb;
3723 tx_ring->tx_buffer_info[first].next_to_watch = i;
3724
3725 return count;
3726}
3727
3728static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003729 struct ixgbe_ring *tx_ring,
3730 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07003731{
3732 union ixgbe_adv_tx_desc *tx_desc = NULL;
3733 struct ixgbe_tx_buffer *tx_buffer_info;
3734 u32 olinfo_status = 0, cmd_type_len = 0;
3735 unsigned int i;
3736 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
3737
3738 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
3739
3740 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
3741
3742 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3743 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
3744
3745 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
3746 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
3747
3748 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003749 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003750
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003751 /* use index 1 context for tso */
3752 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003753 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
3754 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003755 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003756
3757 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
3758 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003759 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003760
3761 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
3762
3763 i = tx_ring->next_to_use;
3764 while (count--) {
3765 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3766 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
3767 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
3768 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003769 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07003770 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07003771 i++;
3772 if (i == tx_ring->count)
3773 i = 0;
3774 }
3775
3776 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
3777
3778 /*
3779 * Force memory writes to complete before letting h/w
3780 * know there are new descriptors to fetch. (Only
3781 * applicable for weak-ordered memory model archs,
3782 * such as IA-64).
3783 */
3784 wmb();
3785
3786 tx_ring->next_to_use = i;
3787 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3788}
3789
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003790static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003791 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003792{
3793 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3794
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003795 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003796 /* Herbert's original patch had:
3797 * smp_mb__after_netif_stop_queue();
3798 * but since that doesn't exist yet, just open code it. */
3799 smp_mb();
3800
3801 /* We need to check again in a case another CPU has just
3802 * made room available. */
3803 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
3804 return -EBUSY;
3805
3806 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07003807 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003808 ++adapter->restart_queue;
3809 return 0;
3810}
3811
3812static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003813 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003814{
3815 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
3816 return 0;
3817 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
3818}
3819
Auke Kok9a799d72007-09-15 14:07:45 -07003820static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3821{
3822 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3823 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07003824 unsigned int first;
3825 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003826 u8 hdr_len = 0;
3827 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07003828 int count = 0;
3829 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003830
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003831 r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003832 tx_ring = &adapter->tx_ring[r_idx];
Auke Kok9a799d72007-09-15 14:07:45 -07003833
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003834 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3835 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003836 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3837 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
3838 tx_flags |= (skb->queue_mapping << 13);
3839 }
3840 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3841 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3842 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3843 tx_flags |= (skb->queue_mapping << 13);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003844 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3845 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07003846 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003847 /* three things can cause us to need a context descriptor */
3848 if (skb_is_gso(skb) ||
3849 (skb->ip_summed == CHECKSUM_PARTIAL) ||
3850 (tx_flags & IXGBE_TX_FLAGS_VLAN))
Auke Kok9a799d72007-09-15 14:07:45 -07003851 count++;
3852
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003853 count += TXD_USE_COUNT(skb_headlen(skb));
3854 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07003855 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
3856
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003857 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003858 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07003859 return NETDEV_TX_BUSY;
3860 }
Auke Kok9a799d72007-09-15 14:07:45 -07003861
Al Viro8327d002007-12-10 18:54:12 +00003862 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07003863 tx_flags |= IXGBE_TX_FLAGS_IPV4;
3864 first = tx_ring->next_to_use;
3865 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
3866 if (tso < 0) {
3867 dev_kfree_skb_any(skb);
3868 return NETDEV_TX_OK;
3869 }
3870
3871 if (tso)
3872 tx_flags |= IXGBE_TX_FLAGS_TSO;
3873 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003874 (skb->ip_summed == CHECKSUM_PARTIAL))
Auke Kok9a799d72007-09-15 14:07:45 -07003875 tx_flags |= IXGBE_TX_FLAGS_CSUM;
3876
3877 ixgbe_tx_queue(adapter, tx_ring, tx_flags,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003878 ixgbe_tx_map(adapter, tx_ring, skb, first),
3879 skb->len, hdr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07003880
3881 netdev->trans_start = jiffies;
3882
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003883 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07003884
3885 return NETDEV_TX_OK;
3886}
3887
3888/**
3889 * ixgbe_get_stats - Get System Network Statistics
3890 * @netdev: network interface device structure
3891 *
3892 * Returns the address of the device statistics structure.
3893 * The statistics are actually updated from the timer callback.
3894 **/
3895static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
3896{
3897 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3898
3899 /* only return the current stats */
3900 return &adapter->net_stats;
3901}
3902
3903/**
3904 * ixgbe_set_mac - Change the Ethernet Address of the NIC
3905 * @netdev: network interface device structure
3906 * @p: pointer to an address structure
3907 *
3908 * Returns 0 on success, negative on failure
3909 **/
3910static int ixgbe_set_mac(struct net_device *netdev, void *p)
3911{
3912 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003913 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003914 struct sockaddr *addr = p;
3915
3916 if (!is_valid_ether_addr(addr->sa_data))
3917 return -EADDRNOTAVAIL;
3918
3919 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003920 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07003921
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003922 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003923
3924 return 0;
3925}
3926
3927#ifdef CONFIG_NET_POLL_CONTROLLER
3928/*
3929 * Polling 'interrupt' - used by things like netconsole to send skbs
3930 * without having to re-enable interrupts. It's not called while
3931 * the interrupt routine is executing.
3932 */
3933static void ixgbe_netpoll(struct net_device *netdev)
3934{
3935 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3936
3937 disable_irq(adapter->pdev->irq);
3938 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
3939 ixgbe_intr(adapter->pdev->irq, netdev);
3940 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
3941 enable_irq(adapter->pdev->irq);
3942}
3943#endif
3944
Stephen Hemminger0edc3522008-11-19 22:24:29 -08003945static const struct net_device_ops ixgbe_netdev_ops = {
3946 .ndo_open = ixgbe_open,
3947 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08003948 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08003949 .ndo_get_stats = ixgbe_get_stats,
3950 .ndo_set_multicast_list = ixgbe_set_rx_mode,
3951 .ndo_validate_addr = eth_validate_addr,
3952 .ndo_set_mac_address = ixgbe_set_mac,
3953 .ndo_change_mtu = ixgbe_change_mtu,
3954 .ndo_tx_timeout = ixgbe_tx_timeout,
3955 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
3956 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
3957 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
3958#ifdef CONFIG_NET_POLL_CONTROLLER
3959 .ndo_poll_controller = ixgbe_netpoll,
3960#endif
3961};
3962
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003963/**
Auke Kok9a799d72007-09-15 14:07:45 -07003964 * ixgbe_probe - Device Initialization Routine
3965 * @pdev: PCI device information struct
3966 * @ent: entry in ixgbe_pci_tbl
3967 *
3968 * Returns 0 on success, negative on failure
3969 *
3970 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
3971 * The OS initialization, configuring of the adapter private structure,
3972 * and a hardware reset occur.
3973 **/
3974static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003975 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07003976{
3977 struct net_device *netdev;
3978 struct ixgbe_adapter *adapter = NULL;
3979 struct ixgbe_hw *hw;
3980 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07003981 static int cards_found;
3982 int i, err, pci_using_dac;
3983 u16 link_status, link_speed, link_width;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003984 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07003985
3986 err = pci_enable_device(pdev);
3987 if (err)
3988 return err;
3989
3990 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
3991 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
3992 pci_using_dac = 1;
3993 } else {
3994 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
3995 if (err) {
3996 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
3997 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003998 dev_err(&pdev->dev, "No usable DMA "
3999 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004000 goto err_dma;
4001 }
4002 }
4003 pci_using_dac = 0;
4004 }
4005
4006 err = pci_request_regions(pdev, ixgbe_driver_name);
4007 if (err) {
4008 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
4009 goto err_pci_reg;
4010 }
4011
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004012 err = pci_enable_pcie_error_reporting(pdev);
4013 if (err) {
4014 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
4015 "0x%x\n", err);
4016 /* non-fatal, continue */
4017 }
4018
Auke Kok9a799d72007-09-15 14:07:45 -07004019 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07004020 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004021
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004022 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07004023 if (!netdev) {
4024 err = -ENOMEM;
4025 goto err_alloc_etherdev;
4026 }
4027
Auke Kok9a799d72007-09-15 14:07:45 -07004028 SET_NETDEV_DEV(netdev, &pdev->dev);
4029
4030 pci_set_drvdata(pdev, netdev);
4031 adapter = netdev_priv(netdev);
4032
4033 adapter->netdev = netdev;
4034 adapter->pdev = pdev;
4035 hw = &adapter->hw;
4036 hw->back = adapter;
4037 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
4038
Jeff Kirsher05857982008-09-11 19:57:00 -07004039 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
4040 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07004041 if (!hw->hw_addr) {
4042 err = -EIO;
4043 goto err_ioremap;
4044 }
4045
4046 for (i = 1; i <= 5; i++) {
4047 if (pci_resource_len(pdev, i) == 0)
4048 continue;
4049 }
4050
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004051 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07004052 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004053 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07004054 strcpy(netdev->name, pci_name(pdev));
4055
Auke Kok9a799d72007-09-15 14:07:45 -07004056 adapter->bd_number = cards_found;
4057
Auke Kok9a799d72007-09-15 14:07:45 -07004058 /* Setup hw api */
4059 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004060 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07004061
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004062 /* EEPROM */
4063 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
4064 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
4065 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
4066 if (!(eec & (1 << 8)))
4067 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
4068
4069 /* PHY */
4070 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08004071 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
4072
4073 /* set up this timer and work struct before calling get_invariants
4074 * which might start the timer
4075 */
4076 init_timer(&adapter->sfp_timer);
4077 adapter->sfp_timer.function = &ixgbe_sfp_timer;
4078 adapter->sfp_timer.data = (unsigned long) adapter;
4079
4080 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004081
Auke Kok9a799d72007-09-15 14:07:45 -07004082 err = ii->get_invariants(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004083 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
4084 /* start a kernel thread to watch for a module to arrive */
4085 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4086 mod_timer(&adapter->sfp_timer,
4087 round_jiffies(jiffies + (2 * HZ)));
4088 err = 0;
4089 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4090 DPRINTK(PROBE, ERR, "failed to load because an "
4091 "unsupported SFP+ module type was detected.\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004092 goto err_hw_init;
Donald Skidmorec4900be2008-11-20 21:11:42 -08004093 } else if (err) {
4094 goto err_hw_init;
4095 }
Auke Kok9a799d72007-09-15 14:07:45 -07004096
4097 /* setup the private structure */
4098 err = ixgbe_sw_init(adapter);
4099 if (err)
4100 goto err_sw_init;
4101
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004102 /* reset_hw fills in the perm_addr as well */
4103 err = hw->mac.ops.reset_hw(hw);
4104 if (err) {
4105 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
4106 goto err_sw_init;
4107 }
4108
Auke Kok9a799d72007-09-15 14:07:45 -07004109 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004110 NETIF_F_IP_CSUM |
4111 NETIF_F_HW_VLAN_TX |
4112 NETIF_F_HW_VLAN_RX |
4113 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004114
Jesse Brandeburge9990a92008-08-26 04:27:24 -07004115 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07004116 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07004117 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08004118 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004119
4120 netdev->vlan_features |= NETIF_F_TSO;
4121 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07004122 netdev->vlan_features |= NETIF_F_IP_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004123 netdev->vlan_features |= NETIF_F_SG;
4124
Alexander Duyck2f90b862008-11-20 20:52:10 -08004125 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4126 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4127
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004128#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004129 netdev->dcbnl_ops = &dcbnl_ops;
4130#endif
4131
Auke Kok9a799d72007-09-15 14:07:45 -07004132 if (pci_using_dac)
4133 netdev->features |= NETIF_F_HIGHDMA;
4134
Auke Kok9a799d72007-09-15 14:07:45 -07004135 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004136 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07004137 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
4138 err = -EIO;
4139 goto err_eeprom;
4140 }
4141
4142 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
4143 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
4144
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004145 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
4146 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004147 err = -EIO;
4148 goto err_eeprom;
4149 }
4150
4151 init_timer(&adapter->watchdog_timer);
4152 adapter->watchdog_timer.function = &ixgbe_watchdog;
4153 adapter->watchdog_timer.data = (unsigned long)adapter;
4154
4155 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004156 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004157
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004158 err = ixgbe_init_interrupt_scheme(adapter);
4159 if (err)
4160 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07004161
4162 /* print bus type/speed/width info */
4163 pci_read_config_word(pdev, IXGBE_PCI_LINK_STATUS, &link_status);
4164 link_speed = link_status & IXGBE_PCI_LINK_SPEED;
4165 link_width = link_status & IXGBE_PCI_LINK_WIDTH;
Johannes Berg7c510e42008-10-27 17:47:26 -07004166 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004167 ((link_speed == IXGBE_PCI_LINK_SPEED_5000) ? "5.0Gb/s" :
4168 (link_speed == IXGBE_PCI_LINK_SPEED_2500) ? "2.5Gb/s" :
4169 "Unknown"),
4170 ((link_width == IXGBE_PCI_LINK_WIDTH_8) ? "Width x8" :
4171 (link_width == IXGBE_PCI_LINK_WIDTH_4) ? "Width x4" :
4172 (link_width == IXGBE_PCI_LINK_WIDTH_2) ? "Width x2" :
4173 (link_width == IXGBE_PCI_LINK_WIDTH_1) ? "Width x1" :
4174 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07004175 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004176 ixgbe_read_pba_num_generic(hw, &part_num);
Auke Kok9a799d72007-09-15 14:07:45 -07004177 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004178 hw->mac.type, hw->phy.type,
4179 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07004180
Auke Kok0c254d82008-02-11 09:25:56 -08004181 if (link_width <= IXGBE_PCI_LINK_WIDTH_4) {
4182 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004183 "this card is not sufficient for optimal "
4184 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004185 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004186 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004187 }
4188
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08004189 /* save off EEPROM version number */
4190 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
4191
Auke Kok9a799d72007-09-15 14:07:45 -07004192 /* reset the hardware with the new settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004193 hw->mac.ops.start_hw(hw);
4194
Auke Kok9a799d72007-09-15 14:07:45 -07004195 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004196
4197 strcpy(netdev->name, "eth%d");
4198 err = register_netdev(netdev);
4199 if (err)
4200 goto err_register;
4201
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004202#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03004203 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004204 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
4205 /* always use CB2 mode, difference is masked
4206 * in the CB driver */
4207 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
4208 ixgbe_setup_dca(adapter);
4209 }
4210#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004211
4212 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
4213 cards_found++;
4214 return 0;
4215
4216err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004217 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004218err_hw_init:
4219err_sw_init:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004220 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004221err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08004222 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4223 del_timer_sync(&adapter->sfp_timer);
4224 cancel_work_sync(&adapter->sfp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004225 iounmap(hw->hw_addr);
4226err_ioremap:
4227 free_netdev(netdev);
4228err_alloc_etherdev:
4229 pci_release_regions(pdev);
4230err_pci_reg:
4231err_dma:
4232 pci_disable_device(pdev);
4233 return err;
4234}
4235
4236/**
4237 * ixgbe_remove - Device Removal Routine
4238 * @pdev: PCI device information struct
4239 *
4240 * ixgbe_remove is called by the PCI subsystem to alert the driver
4241 * that it should release a PCI device. The could be caused by a
4242 * Hot-Plug event, or because the driver is going to be removed from
4243 * memory.
4244 **/
4245static void __devexit ixgbe_remove(struct pci_dev *pdev)
4246{
4247 struct net_device *netdev = pci_get_drvdata(pdev);
4248 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004249 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004250
4251 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004252 /* clear the module not found bit to make sure the worker won't
4253 * reschedule
4254 */
4255 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07004256 del_timer_sync(&adapter->watchdog_timer);
4257
Donald Skidmorec4900be2008-11-20 21:11:42 -08004258 del_timer_sync(&adapter->sfp_timer);
4259 cancel_work_sync(&adapter->watchdog_task);
4260 cancel_work_sync(&adapter->sfp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004261 flush_scheduled_work();
4262
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004263#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004264 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
4265 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
4266 dca_remove_requester(&pdev->dev);
4267 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
4268 }
4269
4270#endif
Donald Skidmorec4900be2008-11-20 21:11:42 -08004271 if (netdev->reg_state == NETREG_REGISTERED)
4272 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004273
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004274 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004275
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004276 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004277
4278 iounmap(adapter->hw.hw_addr);
4279 pci_release_regions(pdev);
4280
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004281 DPRINTK(PROBE, INFO, "complete\n");
4282 kfree(adapter->tx_ring);
4283 kfree(adapter->rx_ring);
4284
Auke Kok9a799d72007-09-15 14:07:45 -07004285 free_netdev(netdev);
4286
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004287 err = pci_disable_pcie_error_reporting(pdev);
4288 if (err)
4289 dev_err(&pdev->dev,
4290 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
4291
Auke Kok9a799d72007-09-15 14:07:45 -07004292 pci_disable_device(pdev);
4293}
4294
4295/**
4296 * ixgbe_io_error_detected - called when PCI error is detected
4297 * @pdev: Pointer to PCI device
4298 * @state: The current pci connection state
4299 *
4300 * This function is called after a PCI bus error affecting
4301 * this device has been detected.
4302 */
4303static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004304 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07004305{
4306 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004307 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004308
4309 netif_device_detach(netdev);
4310
4311 if (netif_running(netdev))
4312 ixgbe_down(adapter);
4313 pci_disable_device(pdev);
4314
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004315 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07004316 return PCI_ERS_RESULT_NEED_RESET;
4317}
4318
4319/**
4320 * ixgbe_io_slot_reset - called after the pci bus has been reset.
4321 * @pdev: Pointer to PCI device
4322 *
4323 * Restart the card from scratch, as if from a cold-boot.
4324 */
4325static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
4326{
4327 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004328 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004329 pci_ers_result_t result;
4330 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004331
4332 if (pci_enable_device(pdev)) {
4333 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004334 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004335 result = PCI_ERS_RESULT_DISCONNECT;
4336 } else {
4337 pci_set_master(pdev);
4338 pci_restore_state(pdev);
4339
4340 pci_enable_wake(pdev, PCI_D3hot, 0);
4341 pci_enable_wake(pdev, PCI_D3cold, 0);
4342
4343 ixgbe_reset(adapter);
4344
4345 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07004346 }
Auke Kok9a799d72007-09-15 14:07:45 -07004347
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004348 err = pci_cleanup_aer_uncorrect_error_status(pdev);
4349 if (err) {
4350 dev_err(&pdev->dev,
4351 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
4352 /* non-fatal, continue */
4353 }
Auke Kok9a799d72007-09-15 14:07:45 -07004354
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004355 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07004356}
4357
4358/**
4359 * ixgbe_io_resume - called when traffic can start flowing again.
4360 * @pdev: Pointer to PCI device
4361 *
4362 * This callback is called when the error recovery driver tells us that
4363 * its OK to resume normal operation.
4364 */
4365static void ixgbe_io_resume(struct pci_dev *pdev)
4366{
4367 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004368 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004369
4370 if (netif_running(netdev)) {
4371 if (ixgbe_up(adapter)) {
4372 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
4373 return;
4374 }
4375 }
4376
4377 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004378}
4379
4380static struct pci_error_handlers ixgbe_err_handler = {
4381 .error_detected = ixgbe_io_error_detected,
4382 .slot_reset = ixgbe_io_slot_reset,
4383 .resume = ixgbe_io_resume,
4384};
4385
4386static struct pci_driver ixgbe_driver = {
4387 .name = ixgbe_driver_name,
4388 .id_table = ixgbe_pci_tbl,
4389 .probe = ixgbe_probe,
4390 .remove = __devexit_p(ixgbe_remove),
4391#ifdef CONFIG_PM
4392 .suspend = ixgbe_suspend,
4393 .resume = ixgbe_resume,
4394#endif
4395 .shutdown = ixgbe_shutdown,
4396 .err_handler = &ixgbe_err_handler
4397};
4398
4399/**
4400 * ixgbe_init_module - Driver Registration Routine
4401 *
4402 * ixgbe_init_module is the first routine called when the driver is
4403 * loaded. All it does is register with the PCI subsystem.
4404 **/
4405static int __init ixgbe_init_module(void)
4406{
4407 int ret;
4408 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
4409 ixgbe_driver_string, ixgbe_driver_version);
4410
4411 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
4412
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004413#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004414 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004415#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004416
Auke Kok9a799d72007-09-15 14:07:45 -07004417 ret = pci_register_driver(&ixgbe_driver);
4418 return ret;
4419}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004420
Auke Kok9a799d72007-09-15 14:07:45 -07004421module_init(ixgbe_init_module);
4422
4423/**
4424 * ixgbe_exit_module - Driver Exit Cleanup Routine
4425 *
4426 * ixgbe_exit_module is called just before the driver is removed
4427 * from memory.
4428 **/
4429static void __exit ixgbe_exit_module(void)
4430{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004431#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004432 dca_unregister_notify(&dca_notifier);
4433#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004434 pci_unregister_driver(&ixgbe_driver);
4435}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004436
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004437#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004438static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004439 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004440{
4441 int ret_val;
4442
4443 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004444 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004445
4446 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4447}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004448#endif /* CONFIG_IXGBE_DCA */
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004449
Auke Kok9a799d72007-09-15 14:07:45 -07004450module_exit(ixgbe_exit_module);
4451
4452/* ixgbe_main.c */