blob: 65642355a836b8402f4793fda0900731eebb7514 [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) {
Jesse Brandeburg32344a32009-02-24 16:37:31 -08001553 u16 bufsz = IXGBE_RXBUFFER_2048;
1554 /* grow the amount we can receive on large page machines */
1555 if (bufsz < (PAGE_SIZE / 2))
1556 bufsz = (PAGE_SIZE / 2);
1557 /* cap the bufsz at our largest descriptor size */
1558 bufsz = min((u16)IXGBE_MAX_RXBUFFER, bufsz);
1559
1560 srrctl |= bufsz >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001561 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1562 srrctl |= ((IXGBE_RX_HDR_SIZE <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001563 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1564 IXGBE_SRRCTL_BSIZEHDR_MASK);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001565 } else {
1566 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1567
1568 if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1569 srrctl |= IXGBE_RXBUFFER_2048 >>
1570 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1571 else
1572 srrctl |= rx_ring->rx_buf_len >>
1573 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1574 }
1575 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1576}
1577
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001578/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001579 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001580 * @adapter: board private structure
1581 *
1582 * Configure the Rx unit of the MAC after a reset.
1583 **/
1584static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1585{
1586 u64 rdba;
1587 struct ixgbe_hw *hw = &adapter->hw;
1588 struct net_device *netdev = adapter->netdev;
1589 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001590 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001591 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001592 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1593 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1594 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001595 u32 fctrl, hlreg0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001596 u32 reta = 0, mrqc;
1597 u32 rdrxctl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001598 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07001599
1600 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001601 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07001602
1603 /* Set the RX buffer length according to the mode */
1604 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001605 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001606 } else {
1607 if (netdev->mtu <= ETH_DATA_LEN)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001608 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001609 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001610 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07001611 }
1612
1613 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1614 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001615 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
Auke Kok9a799d72007-09-15 14:07:45 -07001616 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1617
1618 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1619 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1620 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1621 else
1622 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1623 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1624
Auke Kok9a799d72007-09-15 14:07:45 -07001625 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1626 /* disable receives while setting up the descriptors */
1627 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1628 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1629
1630 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1631 * the Base and Length of the Rx Descriptor Ring */
1632 for (i = 0; i < adapter->num_rx_queues; i++) {
1633 rdba = adapter->rx_ring[i].dma;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001634 j = adapter->rx_ring[i].reg_idx;
1635 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_32BIT_MASK));
1636 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
1637 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
1638 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
1639 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
1640 adapter->rx_ring[i].head = IXGBE_RDH(j);
1641 adapter->rx_ring[i].tail = IXGBE_RDT(j);
1642 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001643
1644 ixgbe_configure_srrctl(adapter, j);
Auke Kok9a799d72007-09-15 14:07:45 -07001645 }
1646
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001647 /*
1648 * For VMDq support of different descriptor types or
1649 * buffer sizes through the use of multiple SRRCTL
1650 * registers, RDRXCTL.MVMEN must be set to 1
1651 *
1652 * also, the manual doesn't mention it clearly but DCA hints
1653 * will only use queue 0's tags unless this bit is set. Side
1654 * effects of setting this bit are only that SRRCTL must be
1655 * fully programmed [0..15]
1656 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08001657 if (adapter->flags &
1658 (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_VMDQ_ENABLED)) {
1659 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1660 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
1661 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
1662 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001663
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001664 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07001665 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001666 for (i = 0, j = 0; i < 128; i++, j++) {
1667 if (j == adapter->ring_feature[RING_F_RSS].indices)
1668 j = 0;
1669 /* reta = 4-byte sliding window of
1670 * 0x00..(indices-1)(indices-1)00..etc. */
1671 reta = (reta << 8) | (j * 0x11);
1672 if ((i & 3) == 3)
1673 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07001674 }
1675
1676 /* Fill out hash function seeds */
1677 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001678 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07001679
1680 mrqc = IXGBE_MRQC_RSSEN
1681 /* Perform hash on these packet types */
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001682 | IXGBE_MRQC_RSS_FIELD_IPV4
1683 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1684 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1685 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
1686 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
1687 | IXGBE_MRQC_RSS_FIELD_IPV6
1688 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1689 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
1690 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07001691 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Auke Kok9a799d72007-09-15 14:07:45 -07001692 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001693
1694 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1695
1696 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
1697 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
1698 /* Disable indicating checksum in descriptor, enables
1699 * RSS hash */
1700 rxcsum |= IXGBE_RXCSUM_PCSD;
1701 }
1702 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
1703 /* Enable IPv4 payload checksum for UDP fragments
1704 * if PCSD is not set */
1705 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1706 }
1707
1708 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
Auke Kok9a799d72007-09-15 14:07:45 -07001709}
1710
Auke Kok9a799d72007-09-15 14:07:45 -07001711static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1712{
1713 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001714 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001715
1716 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001717 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07001718}
1719
1720static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1721{
1722 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001723 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001724
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001725 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1726 ixgbe_irq_disable(adapter);
1727
Auke Kok9a799d72007-09-15 14:07:45 -07001728 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001729
1730 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1731 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001732
1733 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001734 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07001735}
1736
Don Skidmore068c89b2009-01-19 16:54:36 -08001737static void ixgbe_vlan_rx_register(struct net_device *netdev,
1738 struct vlan_group *grp)
1739{
1740 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1741 u32 ctrl;
1742
1743 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1744 ixgbe_irq_disable(adapter);
1745 adapter->vlgrp = grp;
1746
1747 /*
1748 * For a DCB driver, always enable VLAN tag stripping so we can
1749 * still receive traffic from a DCB-enabled host even if we're
1750 * not in DCB mode.
1751 */
1752 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1753 ctrl |= IXGBE_VLNCTRL_VME;
1754 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1755 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1756 ixgbe_vlan_rx_add_vid(netdev, 0);
1757
1758 if (grp) {
1759 /* enable VLAN tag insert/strip */
1760 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1761 ctrl |= IXGBE_VLNCTRL_VME;
1762 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1763 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1764 }
1765
1766 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1767 ixgbe_irq_enable(adapter);
1768}
1769
Auke Kok9a799d72007-09-15 14:07:45 -07001770static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
1771{
1772 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1773
1774 if (adapter->vlgrp) {
1775 u16 vid;
1776 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1777 if (!vlan_group_get_device(adapter->vlgrp, vid))
1778 continue;
1779 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
1780 }
1781 }
1782}
1783
Christopher Leech2c5645c2008-08-26 04:27:02 -07001784static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
1785{
1786 struct dev_mc_list *mc_ptr;
1787 u8 *addr = *mc_addr_ptr;
1788 *vmdq = 0;
1789
1790 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
1791 if (mc_ptr->next)
1792 *mc_addr_ptr = mc_ptr->next->dmi_addr;
1793 else
1794 *mc_addr_ptr = NULL;
1795
1796 return addr;
1797}
1798
Auke Kok9a799d72007-09-15 14:07:45 -07001799/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07001800 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07001801 * @netdev: network interface device structure
1802 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07001803 * The set_rx_method entry point is called whenever the unicast/multicast
1804 * address list or the network interface flags are updated. This routine is
1805 * responsible for configuring the hardware for proper unicast, multicast and
1806 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07001807 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07001808static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001809{
1810 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1811 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07001812 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001813 u8 *addr_list = NULL;
1814 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001815
1816 /* Check for Promiscuous and All Multicast modes */
1817
1818 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07001819 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07001820
1821 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07001822 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001823 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07001824 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07001825 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07001826 if (netdev->flags & IFF_ALLMULTI) {
1827 fctrl |= IXGBE_FCTRL_MPE;
1828 fctrl &= ~IXGBE_FCTRL_UPE;
1829 } else {
1830 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1831 }
Alexander Duyck3d016252008-08-26 18:30:04 -07001832 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001833 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001834 }
1835
1836 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07001837 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001838
Christopher Leech2c5645c2008-08-26 04:27:02 -07001839 /* reprogram secondary unicast list */
1840 addr_count = netdev->uc_count;
1841 if (addr_count)
1842 addr_list = netdev->uc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001843 hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count,
1844 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07001845
Christopher Leech2c5645c2008-08-26 04:27:02 -07001846 /* reprogram multicast list */
1847 addr_count = netdev->mc_count;
1848 if (addr_count)
1849 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001850 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
1851 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07001852}
1853
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001854static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
1855{
1856 int q_idx;
1857 struct ixgbe_q_vector *q_vector;
1858 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1859
1860 /* legacy and MSI only use one vector */
1861 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1862 q_vectors = 1;
1863
1864 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001865 struct napi_struct *napi;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001866 q_vector = &adapter->q_vector[q_idx];
1867 if (!q_vector->rxr_count)
1868 continue;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001869 napi = &q_vector->napi;
1870 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) &&
1871 (q_vector->rxr_count > 1))
1872 napi->poll = &ixgbe_clean_rxonly_many;
1873
1874 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001875 }
1876}
1877
1878static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
1879{
1880 int q_idx;
1881 struct ixgbe_q_vector *q_vector;
1882 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1883
1884 /* legacy and MSI only use one vector */
1885 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1886 q_vectors = 1;
1887
1888 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1889 q_vector = &adapter->q_vector[q_idx];
1890 if (!q_vector->rxr_count)
1891 continue;
1892 napi_disable(&q_vector->napi);
1893 }
1894}
1895
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08001896#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08001897/*
1898 * ixgbe_configure_dcb - Configure DCB hardware
1899 * @adapter: ixgbe adapter struct
1900 *
1901 * This is called by the driver on open to configure the DCB hardware.
1902 * This is also called by the gennetlink interface when reconfiguring
1903 * the DCB state.
1904 */
1905static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
1906{
1907 struct ixgbe_hw *hw = &adapter->hw;
1908 u32 txdctl, vlnctrl;
1909 int i, j;
1910
1911 ixgbe_dcb_check_config(&adapter->dcb_cfg);
1912 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
1913 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
1914
1915 /* reconfigure the hardware */
1916 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
1917
1918 for (i = 0; i < adapter->num_tx_queues; i++) {
1919 j = adapter->tx_ring[i].reg_idx;
1920 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
1921 /* PThresh workaround for Tx hang with DFP enabled. */
1922 txdctl |= 32;
1923 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
1924 }
1925 /* Enable VLAN tag insert/strip */
1926 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1927 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
1928 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
1929 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1930 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
1931}
1932
1933#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001934static void ixgbe_configure(struct ixgbe_adapter *adapter)
1935{
1936 struct net_device *netdev = adapter->netdev;
1937 int i;
1938
Christopher Leech2c5645c2008-08-26 04:27:02 -07001939 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001940
1941 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08001942#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08001943 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
1944 netif_set_gso_max_size(netdev, 32768);
1945 ixgbe_configure_dcb(adapter);
1946 } else {
1947 netif_set_gso_max_size(netdev, 65536);
1948 }
1949#else
1950 netif_set_gso_max_size(netdev, 65536);
1951#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001952
1953 ixgbe_configure_tx(adapter);
1954 ixgbe_configure_rx(adapter);
1955 for (i = 0; i < adapter->num_rx_queues; i++)
1956 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001957 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07001958}
1959
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001960/**
1961 * ixgbe_link_config - set up initial link with default speed and duplex
1962 * @hw: pointer to private hardware struct
1963 *
1964 * Returns 0 on success, negative on failure
1965 **/
1966static int ixgbe_link_config(struct ixgbe_hw *hw)
1967{
1968 u32 autoneg;
1969 bool link_up = false;
1970 u32 ret = IXGBE_ERR_LINK_SETUP;
1971
1972 if (hw->mac.ops.check_link)
1973 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1974
1975 if (ret)
1976 goto link_cfg_out;
1977
1978 if (hw->mac.ops.get_link_capabilities)
1979 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
1980 &hw->mac.autoneg);
1981 if (ret)
1982 goto link_cfg_out;
1983
1984 if (hw->mac.ops.setup_link_speed)
1985 ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up);
1986
1987link_cfg_out:
1988 return ret;
1989}
1990
Auke Kok9a799d72007-09-15 14:07:45 -07001991static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
1992{
1993 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07001994 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001995 int i, j = 0;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08001996 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001997 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001998 u32 txdctl, rxdctl, mhadd;
1999 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002000
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002001 ixgbe_get_hw_control(adapter);
2002
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002003 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2004 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002005 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2006 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002007 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002008 } else {
2009 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002010 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002011 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002012 /* XXX: to interrupt immediately for EICS writes, enable this */
2013 /* gpie |= IXGBE_GPIE_EIMEN; */
2014 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2015 }
2016
2017 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2018 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2019 * specifically only auto mask tx and rx interrupts */
2020 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002021 }
2022
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002023 /* Enable fan failure interrupt if media type is copper */
2024 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2025 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2026 gpie |= IXGBE_SDP1_GPIEN;
2027 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2028 }
2029
Auke Kok9a799d72007-09-15 14:07:45 -07002030 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002031 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2032 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2033 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2034
2035 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2036 }
2037
2038 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002039 j = adapter->tx_ring[i].reg_idx;
2040 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002041 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2042 txdctl |= (8 << 16);
Auke Kok9a799d72007-09-15 14:07:45 -07002043 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002044 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002045 }
2046
2047 for (i = 0; i < adapter->num_rx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002048 j = adapter->rx_ring[i].reg_idx;
2049 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2050 /* enable PTHRESH=32 descriptors (half the internal cache)
2051 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2052 * this also removes a pesky rx_no_buffer_count increment */
2053 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002054 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002055 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002056 }
2057 /* enable all receives */
2058 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2059 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2060 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxdctl);
2061
2062 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2063 ixgbe_configure_msix(adapter);
2064 else
2065 ixgbe_configure_msi_and_legacy(adapter);
2066
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08002067 ixgbe_napi_add_all(adapter);
2068
Auke Kok9a799d72007-09-15 14:07:45 -07002069 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002070 ixgbe_napi_enable_all(adapter);
2071
2072 /* clear any pending interrupts, may auto mask */
2073 IXGBE_READ_REG(hw, IXGBE_EICR);
2074
Auke Kok9a799d72007-09-15 14:07:45 -07002075 ixgbe_irq_enable(adapter);
2076
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002077 err = ixgbe_link_config(hw);
2078 if (err)
2079 dev_err(&adapter->pdev->dev, "link_config FAILED %d\n", err);
2080
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002081 /* enable transmits */
2082 netif_tx_start_all_queues(netdev);
2083
Auke Kok9a799d72007-09-15 14:07:45 -07002084 /* bring the link up in the watchdog, this could race with our first
2085 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002086 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2087 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002088 mod_timer(&adapter->watchdog_timer, jiffies);
2089 return 0;
2090}
2091
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002092void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2093{
2094 WARN_ON(in_interrupt());
2095 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2096 msleep(1);
2097 ixgbe_down(adapter);
2098 ixgbe_up(adapter);
2099 clear_bit(__IXGBE_RESETTING, &adapter->state);
2100}
2101
Auke Kok9a799d72007-09-15 14:07:45 -07002102int ixgbe_up(struct ixgbe_adapter *adapter)
2103{
2104 /* hardware has been reset, we need to reload some things */
2105 ixgbe_configure(adapter);
2106
2107 return ixgbe_up_complete(adapter);
2108}
2109
2110void ixgbe_reset(struct ixgbe_adapter *adapter)
2111{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002112 struct ixgbe_hw *hw = &adapter->hw;
2113 if (hw->mac.ops.init_hw(hw))
2114 dev_err(&adapter->pdev->dev, "Hardware Error\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002115
2116 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002117 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002118
2119}
2120
Auke Kok9a799d72007-09-15 14:07:45 -07002121/**
2122 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2123 * @adapter: board private structure
2124 * @rx_ring: ring to free buffers from
2125 **/
2126static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002127 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002128{
2129 struct pci_dev *pdev = adapter->pdev;
2130 unsigned long size;
2131 unsigned int i;
2132
2133 /* Free all the Rx ring sk_buffs */
2134
2135 for (i = 0; i < rx_ring->count; i++) {
2136 struct ixgbe_rx_buffer *rx_buffer_info;
2137
2138 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2139 if (rx_buffer_info->dma) {
2140 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002141 rx_ring->rx_buf_len,
2142 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002143 rx_buffer_info->dma = 0;
2144 }
2145 if (rx_buffer_info->skb) {
2146 dev_kfree_skb(rx_buffer_info->skb);
2147 rx_buffer_info->skb = NULL;
2148 }
2149 if (!rx_buffer_info->page)
2150 continue;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002151 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2152 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002153 rx_buffer_info->page_dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002154 put_page(rx_buffer_info->page);
2155 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002156 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002157 }
2158
2159 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2160 memset(rx_ring->rx_buffer_info, 0, size);
2161
2162 /* Zero out the descriptor ring */
2163 memset(rx_ring->desc, 0, rx_ring->size);
2164
2165 rx_ring->next_to_clean = 0;
2166 rx_ring->next_to_use = 0;
2167
2168 writel(0, adapter->hw.hw_addr + rx_ring->head);
2169 writel(0, adapter->hw.hw_addr + rx_ring->tail);
2170}
2171
2172/**
2173 * ixgbe_clean_tx_ring - Free Tx Buffers
2174 * @adapter: board private structure
2175 * @tx_ring: ring to be cleaned
2176 **/
2177static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002178 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002179{
2180 struct ixgbe_tx_buffer *tx_buffer_info;
2181 unsigned long size;
2182 unsigned int i;
2183
2184 /* Free all the Tx ring sk_buffs */
2185
2186 for (i = 0; i < tx_ring->count; i++) {
2187 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2188 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2189 }
2190
2191 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2192 memset(tx_ring->tx_buffer_info, 0, size);
2193
2194 /* Zero out the descriptor ring */
2195 memset(tx_ring->desc, 0, tx_ring->size);
2196
2197 tx_ring->next_to_use = 0;
2198 tx_ring->next_to_clean = 0;
2199
2200 writel(0, adapter->hw.hw_addr + tx_ring->head);
2201 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2202}
2203
2204/**
Auke Kok9a799d72007-09-15 14:07:45 -07002205 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2206 * @adapter: board private structure
2207 **/
2208static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2209{
2210 int i;
2211
2212 for (i = 0; i < adapter->num_rx_queues; i++)
2213 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2214}
2215
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002216/**
2217 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2218 * @adapter: board private structure
2219 **/
2220static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2221{
2222 int i;
2223
2224 for (i = 0; i < adapter->num_tx_queues; i++)
2225 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2226}
2227
Auke Kok9a799d72007-09-15 14:07:45 -07002228void ixgbe_down(struct ixgbe_adapter *adapter)
2229{
2230 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002231 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002232 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002233 u32 txdctl;
2234 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002235
2236 /* signal that we are down to the interrupt handler */
2237 set_bit(__IXGBE_DOWN, &adapter->state);
2238
2239 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002240 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2241 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002242
2243 netif_tx_disable(netdev);
2244
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002245 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002246 msleep(10);
2247
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002248 netif_tx_stop_all_queues(netdev);
2249
Auke Kok9a799d72007-09-15 14:07:45 -07002250 ixgbe_irq_disable(adapter);
2251
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002252 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002253
Auke Kok9a799d72007-09-15 14:07:45 -07002254 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002255 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002256
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002257 /* disable transmits in the hardware now that interrupts are off */
2258 for (i = 0; i < adapter->num_tx_queues; i++) {
2259 j = adapter->tx_ring[i].reg_idx;
2260 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2261 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2262 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2263 }
2264
Auke Kok9a799d72007-09-15 14:07:45 -07002265 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002266
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002267#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002268 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2269 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
2270 dca_remove_requester(&adapter->pdev->dev);
2271 }
2272
2273#endif
Paul Larson6f4a0e42008-06-24 17:00:56 -07002274 if (!pci_channel_offline(adapter->pdev))
2275 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002276 ixgbe_clean_all_tx_rings(adapter);
2277 ixgbe_clean_all_rx_rings(adapter);
2278
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002279#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002280 /* since we reset the hardware DCA settings were cleared */
2281 if (dca_add_requester(&adapter->pdev->dev) == 0) {
2282 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
2283 /* always use CB2 mode, difference is masked
2284 * in the CB driver */
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002285 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002286 ixgbe_setup_dca(adapter);
2287 }
2288#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002289}
2290
Auke Kok9a799d72007-09-15 14:07:45 -07002291/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002292 * ixgbe_poll - NAPI Rx polling callback
2293 * @napi: structure for representing this polling device
2294 * @budget: how many packets driver is allowed to clean
2295 *
2296 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002297 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002298static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002299{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002300 struct ixgbe_q_vector *q_vector = container_of(napi,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002301 struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002302 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -07002303 int tx_cleaned, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002304
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002305#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002306 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2307 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2308 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2309 }
2310#endif
2311
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002312 tx_cleaned = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002313 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002314
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002315 if (tx_cleaned)
2316 work_done = budget;
2317
David S. Miller53e52c72008-01-07 21:06:12 -08002318 /* If budget not fully consumed, exit the polling mode */
2319 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002320 napi_complete(napi);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002321 if (adapter->itr_setting & 3)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002322 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002323 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2324 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002325 }
Auke Kok9a799d72007-09-15 14:07:45 -07002326 return work_done;
2327}
2328
2329/**
2330 * ixgbe_tx_timeout - Respond to a Tx Hang
2331 * @netdev: network interface device structure
2332 **/
2333static void ixgbe_tx_timeout(struct net_device *netdev)
2334{
2335 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2336
2337 /* Do the reset outside of interrupt context */
2338 schedule_work(&adapter->reset_task);
2339}
2340
2341static void ixgbe_reset_task(struct work_struct *work)
2342{
2343 struct ixgbe_adapter *adapter;
2344 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2345
Alexander Duyck2f90b862008-11-20 20:52:10 -08002346 /* If we're already down or resetting, just bail */
2347 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2348 test_bit(__IXGBE_RESETTING, &adapter->state))
2349 return;
2350
Auke Kok9a799d72007-09-15 14:07:45 -07002351 adapter->tx_timeout_count++;
2352
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002353 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002354}
2355
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002356#ifdef CONFIG_IXGBE_DCB
2357static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002358{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002359 bool ret = false;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002360
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002361 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2362 adapter->ring_feature[RING_F_DCB].mask = 0x7 << 3;
2363 adapter->num_rx_queues =
2364 adapter->ring_feature[RING_F_DCB].indices;
2365 adapter->num_tx_queues =
2366 adapter->ring_feature[RING_F_DCB].indices;
2367 ret = true;
2368 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002369 ret = false;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002370 }
2371
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002372 return ret;
2373}
2374#endif
2375
2376static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
2377{
2378 bool ret = false;
2379
2380 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2381 adapter->ring_feature[RING_F_RSS].mask = 0xF;
2382 adapter->num_rx_queues =
2383 adapter->ring_feature[RING_F_RSS].indices;
2384 adapter->num_tx_queues =
2385 adapter->ring_feature[RING_F_RSS].indices;
2386 ret = true;
2387 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002388 ret = false;
2389 }
2390
2391 return ret;
2392}
2393
2394static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2395{
2396 /* Start with base case */
2397 adapter->num_rx_queues = 1;
2398 adapter->num_tx_queues = 1;
2399
2400#ifdef CONFIG_IXGBE_DCB
2401 if (ixgbe_set_dcb_queues(adapter))
2402 return;
2403
2404#endif
2405 if (ixgbe_set_rss_queues(adapter))
2406 return;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002407}
2408
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002409static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002410 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002411{
2412 int err, vector_threshold;
2413
2414 /* We'll want at least 3 (vector_threshold):
2415 * 1) TxQ[0] Cleanup
2416 * 2) RxQ[0] Cleanup
2417 * 3) Other (Link Status Change, etc.)
2418 * 4) TCP Timer (optional)
2419 */
2420 vector_threshold = MIN_MSIX_COUNT;
2421
2422 /* The more we get, the more we will assign to Tx/Rx Cleanup
2423 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2424 * Right now, we simply care about how many we'll get; we'll
2425 * set them up later while requesting irq's.
2426 */
2427 while (vectors >= vector_threshold) {
2428 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002429 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002430 if (!err) /* Success in acquiring all requested vectors. */
2431 break;
2432 else if (err < 0)
2433 vectors = 0; /* Nasty failure, quit now */
2434 else /* err == number of vectors we should try again with */
2435 vectors = err;
2436 }
2437
2438 if (vectors < vector_threshold) {
2439 /* Can't allocate enough MSI-X interrupts? Oh well.
2440 * This just means we'll go with either a single MSI
2441 * vector or fall back to legacy interrupts.
2442 */
2443 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2444 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2445 kfree(adapter->msix_entries);
2446 adapter->msix_entries = NULL;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002447 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002448 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002449 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002450 } else {
2451 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08002452 /*
2453 * Adjust for only the vectors we'll use, which is minimum
2454 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
2455 * vectors we were allocated.
2456 */
2457 adapter->num_msix_vectors = min(vectors,
2458 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002459 }
2460}
2461
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002462/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002463 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002464 * @adapter: board private structure to initialize
2465 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002466 * Cache the descriptor ring offsets for RSS to the assigned rings.
2467 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002468 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002469static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002470{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002471 int i;
2472 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002473
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002474 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
2475 for (i = 0; i < adapter->num_rx_queues; i++)
2476 adapter->rx_ring[i].reg_idx = i;
2477 for (i = 0; i < adapter->num_tx_queues; i++)
2478 adapter->tx_ring[i].reg_idx = i;
2479 ret = true;
2480 } else {
2481 ret = false;
2482 }
2483
2484 return ret;
2485}
2486
2487#ifdef CONFIG_IXGBE_DCB
2488/**
2489 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
2490 * @adapter: board private structure to initialize
2491 *
2492 * Cache the descriptor ring offsets for DCB to the assigned rings.
2493 *
2494 **/
2495static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
2496{
2497 int i;
2498 bool ret = false;
2499 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2500
2501 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2502 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002503 /* the number of queues is assumed to be symmetric */
2504 for (i = 0; i < dcb_i; i++) {
2505 adapter->rx_ring[i].reg_idx = i << 3;
2506 adapter->tx_ring[i].reg_idx = i << 2;
2507 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002508 ret = true;
2509 } else {
2510 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002511 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002512 } else {
2513 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002514 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08002515
2516 return ret;
2517}
2518#endif
2519
2520/**
2521 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2522 * @adapter: board private structure to initialize
2523 *
2524 * Once we know the feature-set enabled for the device, we'll cache
2525 * the register offset the descriptor ring is assigned to.
2526 *
2527 * Note, the order the various feature calls is important. It must start with
2528 * the "most" features enabled at the same time, then trickle down to the
2529 * least amount of features turned on at once.
2530 **/
2531static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
2532{
2533 /* start with default case */
2534 adapter->rx_ring[0].reg_idx = 0;
2535 adapter->tx_ring[0].reg_idx = 0;
2536
2537#ifdef CONFIG_IXGBE_DCB
2538 if (ixgbe_cache_ring_dcb(adapter))
2539 return;
2540
2541#endif
2542 if (ixgbe_cache_ring_rss(adapter))
2543 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002544}
2545
Auke Kok9a799d72007-09-15 14:07:45 -07002546/**
2547 * ixgbe_alloc_queues - Allocate memory for all rings
2548 * @adapter: board private structure to initialize
2549 *
2550 * We allocate one ring per queue at run-time since we don't know the
Wang Chena4d2f342008-12-03 22:05:58 -08002551 * number of queues at compile-time.
Auke Kok9a799d72007-09-15 14:07:45 -07002552 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002553static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002554{
2555 int i;
2556
2557 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002558 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07002559 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002560 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07002561
2562 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002563 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002564 if (!adapter->rx_ring)
2565 goto err_rx_ring_allocation;
2566
2567 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002568 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002569 adapter->tx_ring[i].queue_index = i;
2570 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002571
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002572 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002573 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002574 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07002575 }
2576
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002577 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002578
2579 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002580
2581err_rx_ring_allocation:
2582 kfree(adapter->tx_ring);
2583err_tx_ring_allocation:
2584 return -ENOMEM;
2585}
2586
2587/**
2588 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
2589 * @adapter: board private structure to initialize
2590 *
2591 * Attempt to configure the interrupts using the best available
2592 * capabilities of the hardware and the kernel.
2593 **/
Al Virofeea6a52008-11-27 15:34:07 -08002594static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002595{
2596 int err = 0;
2597 int vector, v_budget;
2598
2599 /*
2600 * It's easy to be greedy for MSI-X vectors, but it really
2601 * doesn't do us much good if we have a lot more vectors
2602 * than CPU's. So let's be conservative and only ask for
2603 * (roughly) twice the number of vectors as there are CPU's.
2604 */
2605 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002606 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002607
2608 /*
2609 * At the same time, hardware can only support a maximum of
2610 * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq,
2611 * we can easily reach upwards of 64 Rx descriptor queues and
2612 * 32 Tx queues. Thus, we cap it off in those rare cases where
2613 * the cpu count also exceeds our vector limit.
2614 */
2615 v_budget = min(v_budget, MAX_MSIX_COUNT);
2616
2617 /* A failure in MSI-X entry allocation isn't fatal, but it does
2618 * mean we disable MSI-X capabilities of the adapter. */
2619 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002620 sizeof(struct msix_entry), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002621 if (!adapter->msix_entries) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002622 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002623 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2624 ixgbe_set_num_queues(adapter);
2625 kfree(adapter->tx_ring);
2626 kfree(adapter->rx_ring);
2627 err = ixgbe_alloc_queues(adapter);
2628 if (err) {
2629 DPRINTK(PROBE, ERR, "Unable to allocate memory "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002630 "for queues\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002631 goto out;
2632 }
2633
2634 goto try_msi;
2635 }
2636
2637 for (vector = 0; vector < v_budget; vector++)
2638 adapter->msix_entries[vector].entry = vector;
2639
2640 ixgbe_acquire_msix_vectors(adapter, v_budget);
2641
2642 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2643 goto out;
2644
2645try_msi:
2646 err = pci_enable_msi(adapter->pdev);
2647 if (!err) {
2648 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
2649 } else {
2650 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002651 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002652 /* reset err */
2653 err = 0;
2654 }
2655
2656out:
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08002657 /* Notify the stack of the (possibly) reduced Tx Queue count. */
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002658 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002659
2660 return err;
2661}
2662
Alexander Duyck2f90b862008-11-20 20:52:10 -08002663void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002664{
2665 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2666 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2667 pci_disable_msix(adapter->pdev);
2668 kfree(adapter->msix_entries);
2669 adapter->msix_entries = NULL;
2670 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2671 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
2672 pci_disable_msi(adapter->pdev);
2673 }
2674 return;
2675}
2676
2677/**
2678 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
2679 * @adapter: board private structure to initialize
2680 *
2681 * We determine which interrupt scheme to use based on...
2682 * - Kernel support (MSI, MSI-X)
2683 * - which can be user-defined (via MODULE_PARAM)
2684 * - Hardware queue count (num_*_queues)
2685 * - defined by miscellaneous hardware support/features (RSS, etc.)
2686 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002687int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002688{
2689 int err;
2690
2691 /* Number of supported queues */
2692 ixgbe_set_num_queues(adapter);
2693
2694 err = ixgbe_alloc_queues(adapter);
2695 if (err) {
2696 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
2697 goto err_alloc_queues;
2698 }
2699
2700 err = ixgbe_set_interrupt_capability(adapter);
2701 if (err) {
2702 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
2703 goto err_set_interrupt;
2704 }
2705
2706 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002707 "Tx Queue count = %u\n",
2708 (adapter->num_rx_queues > 1) ? "Enabled" :
2709 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002710
2711 set_bit(__IXGBE_DOWN, &adapter->state);
2712
2713 return 0;
2714
2715err_set_interrupt:
2716 kfree(adapter->tx_ring);
2717 kfree(adapter->rx_ring);
2718err_alloc_queues:
2719 return err;
Auke Kok9a799d72007-09-15 14:07:45 -07002720}
2721
2722/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08002723 * ixgbe_sfp_timer - worker thread to find a missing module
2724 * @data: pointer to our adapter struct
2725 **/
2726static void ixgbe_sfp_timer(unsigned long data)
2727{
2728 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
2729
2730 /* Do the sfp_timer outside of interrupt context due to the
2731 * delays that sfp+ detection requires
2732 */
2733 schedule_work(&adapter->sfp_task);
2734}
2735
2736/**
2737 * ixgbe_sfp_task - worker thread to find a missing module
2738 * @work: pointer to work_struct containing our data
2739 **/
2740static void ixgbe_sfp_task(struct work_struct *work)
2741{
2742 struct ixgbe_adapter *adapter = container_of(work,
2743 struct ixgbe_adapter,
2744 sfp_task);
2745 struct ixgbe_hw *hw = &adapter->hw;
2746
2747 if ((hw->phy.type == ixgbe_phy_nl) &&
2748 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
2749 s32 ret = hw->phy.ops.identify_sfp(hw);
2750 if (ret)
2751 goto reschedule;
2752 ret = hw->phy.ops.reset(hw);
2753 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2754 DPRINTK(PROBE, ERR, "failed to initialize because an "
2755 "unsupported SFP+ module type was detected.\n"
2756 "Reload the driver after installing a "
2757 "supported module.\n");
2758 unregister_netdev(adapter->netdev);
2759 } else {
2760 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
2761 hw->phy.sfp_type);
2762 }
2763 /* don't need this routine any more */
2764 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
2765 }
2766 return;
2767reschedule:
2768 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
2769 mod_timer(&adapter->sfp_timer,
2770 round_jiffies(jiffies + (2 * HZ)));
2771}
2772
2773/**
Auke Kok9a799d72007-09-15 14:07:45 -07002774 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
2775 * @adapter: board private structure to initialize
2776 *
2777 * ixgbe_sw_init initializes the Adapter private data structure.
2778 * Fields are initialized based on PCI device information and
2779 * OS network device settings (MTU size).
2780 **/
2781static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
2782{
2783 struct ixgbe_hw *hw = &adapter->hw;
2784 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002785 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002786#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002787 int j;
2788 struct tc_configuration *tc;
2789#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002790
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002791 /* PCI config space info */
2792
2793 hw->vendor_id = pdev->vendor;
2794 hw->device_id = pdev->device;
2795 hw->revision_id = pdev->revision;
2796 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2797 hw->subsystem_device_id = pdev->subsystem_device;
2798
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002799 /* Set capability flags */
2800 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
2801 adapter->ring_feature[RING_F_RSS].indices = rss;
2802 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002803 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08002804 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002805
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002806#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002807 /* Configure DCB traffic classes */
2808 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
2809 tc = &adapter->dcb_cfg.tc_config[j];
2810 tc->path[DCB_TX_CONFIG].bwg_id = 0;
2811 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
2812 tc->path[DCB_RX_CONFIG].bwg_id = 0;
2813 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
2814 tc->dcb_pfc = pfc_disabled;
2815 }
2816 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
2817 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
2818 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
2819 adapter->dcb_cfg.round_robin_enable = false;
2820 adapter->dcb_set_bitmap = 0x00;
2821 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
2822 adapter->ring_feature[RING_F_DCB].indices);
2823
2824#endif
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002825 if (hw->mac.ops.get_media_type &&
2826 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper))
2827 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Auke Kok9a799d72007-09-15 14:07:45 -07002828
2829 /* default flow control settings */
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002830 hw->fc.requested_mode = ixgbe_fc_none;
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07002831 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
2832 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
2833 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
2834 hw->fc.send_xon = true;
Auke Kok9a799d72007-09-15 14:07:45 -07002835
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002836 /* enable itr by default in dynamic mode */
2837 adapter->itr_setting = 1;
2838 adapter->eitr_param = 20000;
2839
2840 /* set defaults for eitr in MegaBytes */
2841 adapter->eitr_low = 10;
2842 adapter->eitr_high = 20;
2843
2844 /* set default ring sizes */
2845 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
2846 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
2847
Auke Kok9a799d72007-09-15 14:07:45 -07002848 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002849 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002850 dev_err(&pdev->dev, "EEPROM initialization failed\n");
2851 return -EIO;
2852 }
2853
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002854 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07002855 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
2856
Auke Kok9a799d72007-09-15 14:07:45 -07002857 set_bit(__IXGBE_DOWN, &adapter->state);
2858
2859 return 0;
2860}
2861
2862/**
2863 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
2864 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002865 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07002866 *
2867 * Return 0 on success, negative on failure
2868 **/
2869int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002870 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002871{
2872 struct pci_dev *pdev = adapter->pdev;
2873 int size;
2874
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002875 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2876 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002877 if (!tx_ring->tx_buffer_info)
2878 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002879 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07002880
2881 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08002882 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002883 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07002884
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002885 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
2886 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002887 if (!tx_ring->desc)
2888 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07002889
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002890 tx_ring->next_to_use = 0;
2891 tx_ring->next_to_clean = 0;
2892 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07002893 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002894
2895err:
2896 vfree(tx_ring->tx_buffer_info);
2897 tx_ring->tx_buffer_info = NULL;
2898 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
2899 "descriptor ring\n");
2900 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07002901}
2902
2903/**
Alexander Duyck69888672008-09-11 20:05:39 -07002904 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
2905 * @adapter: board private structure
2906 *
2907 * If this function returns with an error, then it's possible one or
2908 * more of the rings is populated (while the rest are not). It is the
2909 * callers duty to clean those orphaned rings.
2910 *
2911 * Return 0 on success, negative on failure
2912 **/
2913static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
2914{
2915 int i, err = 0;
2916
2917 for (i = 0; i < adapter->num_tx_queues; i++) {
2918 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
2919 if (!err)
2920 continue;
2921 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
2922 break;
2923 }
2924
2925 return err;
2926}
2927
2928/**
Auke Kok9a799d72007-09-15 14:07:45 -07002929 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
2930 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002931 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07002932 *
2933 * Returns 0 on success, negative on failure
2934 **/
2935int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002936 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002937{
2938 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002939 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002940
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002941 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2942 rx_ring->rx_buffer_info = vmalloc(size);
2943 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07002944 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002945 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002946 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07002947 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002948 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07002949
Auke Kok9a799d72007-09-15 14:07:45 -07002950 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002951 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
2952 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07002953
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002954 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07002955
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002956 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07002957 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002958 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002959 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002960 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07002961 }
2962
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002963 rx_ring->next_to_clean = 0;
2964 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002965
2966 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002967
2968alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002969 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07002970}
2971
2972/**
Alexander Duyck69888672008-09-11 20:05:39 -07002973 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
2974 * @adapter: board private structure
2975 *
2976 * If this function returns with an error, then it's possible one or
2977 * more of the rings is populated (while the rest are not). It is the
2978 * callers duty to clean those orphaned rings.
2979 *
2980 * Return 0 on success, negative on failure
2981 **/
2982
2983static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
2984{
2985 int i, err = 0;
2986
2987 for (i = 0; i < adapter->num_rx_queues; i++) {
2988 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
2989 if (!err)
2990 continue;
2991 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
2992 break;
2993 }
2994
2995 return err;
2996}
2997
2998/**
Auke Kok9a799d72007-09-15 14:07:45 -07002999 * ixgbe_free_tx_resources - Free Tx Resources per Queue
3000 * @adapter: board private structure
3001 * @tx_ring: Tx descriptor ring for a specific queue
3002 *
3003 * Free all transmit software resources
3004 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003005void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
3006 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003007{
3008 struct pci_dev *pdev = adapter->pdev;
3009
3010 ixgbe_clean_tx_ring(adapter, tx_ring);
3011
3012 vfree(tx_ring->tx_buffer_info);
3013 tx_ring->tx_buffer_info = NULL;
3014
3015 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
3016
3017 tx_ring->desc = NULL;
3018}
3019
3020/**
3021 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
3022 * @adapter: board private structure
3023 *
3024 * Free all transmit software resources
3025 **/
3026static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
3027{
3028 int i;
3029
3030 for (i = 0; i < adapter->num_tx_queues; i++)
3031 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
3032}
3033
3034/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003035 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07003036 * @adapter: board private structure
3037 * @rx_ring: ring to clean the resources from
3038 *
3039 * Free all receive software resources
3040 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003041void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
3042 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003043{
3044 struct pci_dev *pdev = adapter->pdev;
3045
3046 ixgbe_clean_rx_ring(adapter, rx_ring);
3047
3048 vfree(rx_ring->rx_buffer_info);
3049 rx_ring->rx_buffer_info = NULL;
3050
3051 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
3052
3053 rx_ring->desc = NULL;
3054}
3055
3056/**
3057 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
3058 * @adapter: board private structure
3059 *
3060 * Free all receive software resources
3061 **/
3062static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
3063{
3064 int i;
3065
3066 for (i = 0; i < adapter->num_rx_queues; i++)
3067 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
3068}
3069
3070/**
Auke Kok9a799d72007-09-15 14:07:45 -07003071 * ixgbe_change_mtu - Change the Maximum Transfer Unit
3072 * @netdev: network interface device structure
3073 * @new_mtu: new value for maximum frame size
3074 *
3075 * Returns 0 on success, negative on failure
3076 **/
3077static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
3078{
3079 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3080 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3081
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07003082 /* MTU < 68 is an error and causes problems on some kernels */
3083 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07003084 return -EINVAL;
3085
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003086 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003087 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003088 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07003089 netdev->mtu = new_mtu;
3090
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003091 if (netif_running(netdev))
3092 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003093
3094 return 0;
3095}
3096
3097/**
3098 * ixgbe_open - Called when a network interface is made active
3099 * @netdev: network interface device structure
3100 *
3101 * Returns 0 on success, negative value on failure
3102 *
3103 * The open entry point is called when a network interface is made
3104 * active by the system (IFF_UP). At this point all resources needed
3105 * for transmit and receive operations are allocated, the interrupt
3106 * handler is registered with the OS, the watchdog timer is started,
3107 * and the stack is notified that the interface is ready.
3108 **/
3109static int ixgbe_open(struct net_device *netdev)
3110{
3111 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3112 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003113
Auke Kok4bebfaa2008-02-11 09:26:01 -08003114 /* disallow open during test */
3115 if (test_bit(__IXGBE_TESTING, &adapter->state))
3116 return -EBUSY;
3117
Auke Kok9a799d72007-09-15 14:07:45 -07003118 /* allocate transmit descriptors */
3119 err = ixgbe_setup_all_tx_resources(adapter);
3120 if (err)
3121 goto err_setup_tx;
3122
Auke Kok9a799d72007-09-15 14:07:45 -07003123 /* allocate receive descriptors */
3124 err = ixgbe_setup_all_rx_resources(adapter);
3125 if (err)
3126 goto err_setup_rx;
3127
3128 ixgbe_configure(adapter);
3129
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003130 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003131 if (err)
3132 goto err_req_irq;
3133
Auke Kok9a799d72007-09-15 14:07:45 -07003134 err = ixgbe_up_complete(adapter);
3135 if (err)
3136 goto err_up;
3137
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003138 netif_tx_start_all_queues(netdev);
3139
Auke Kok9a799d72007-09-15 14:07:45 -07003140 return 0;
3141
3142err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003143 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003144 ixgbe_free_irq(adapter);
3145err_req_irq:
3146 ixgbe_free_all_rx_resources(adapter);
3147err_setup_rx:
3148 ixgbe_free_all_tx_resources(adapter);
3149err_setup_tx:
3150 ixgbe_reset(adapter);
3151
3152 return err;
3153}
3154
3155/**
3156 * ixgbe_close - Disables a network interface
3157 * @netdev: network interface device structure
3158 *
3159 * Returns 0, this is not allowed to fail
3160 *
3161 * The close entry point is called when an interface is de-activated
3162 * by the OS. The hardware is still under the drivers control, but
3163 * needs to be disabled. A global MAC reset is issued to stop the
3164 * hardware, and all transmit and receive resources are freed.
3165 **/
3166static int ixgbe_close(struct net_device *netdev)
3167{
3168 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003169
3170 ixgbe_down(adapter);
3171 ixgbe_free_irq(adapter);
3172
3173 ixgbe_free_all_tx_resources(adapter);
3174 ixgbe_free_all_rx_resources(adapter);
3175
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003176 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003177
3178 return 0;
3179}
3180
3181/**
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003182 * ixgbe_napi_add_all - prep napi structs for use
3183 * @adapter: private struct
3184 * helper function to napi_add each possible q_vector->napi
3185 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08003186void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003187{
3188 int q_idx, q_vectors;
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003189 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003190 int (*poll)(struct napi_struct *, int);
3191
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003192 /* check if we already have our netdev->napi_list populated */
3193 if (&netdev->napi_list != netdev->napi_list.next)
3194 return;
3195
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003196 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3197 poll = &ixgbe_clean_rxonly;
3198 /* Only enable as many vectors as we have rx queues. */
3199 q_vectors = adapter->num_rx_queues;
3200 } else {
3201 poll = &ixgbe_poll;
3202 /* only one q_vector for legacy modes */
3203 q_vectors = 1;
3204 }
3205
3206 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3207 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3208 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
3209 }
3210}
3211
Alexander Duyck2f90b862008-11-20 20:52:10 -08003212void ixgbe_napi_del_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003213{
3214 int q_idx;
3215 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3216
3217 /* legacy and MSI only use one vector */
3218 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3219 q_vectors = 1;
3220
3221 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3222 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3223 if (!q_vector->rxr_count)
3224 continue;
3225 netif_napi_del(&q_vector->napi);
3226 }
3227}
3228
3229#ifdef CONFIG_PM
3230static int ixgbe_resume(struct pci_dev *pdev)
3231{
3232 struct net_device *netdev = pci_get_drvdata(pdev);
3233 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3234 u32 err;
3235
3236 pci_set_power_state(pdev, PCI_D0);
3237 pci_restore_state(pdev);
3238 err = pci_enable_device(pdev);
3239 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07003240 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003241 "suspend\n");
3242 return err;
3243 }
3244 pci_set_master(pdev);
3245
3246 pci_enable_wake(pdev, PCI_D3hot, 0);
3247 pci_enable_wake(pdev, PCI_D3cold, 0);
3248
3249 err = ixgbe_init_interrupt_scheme(adapter);
3250 if (err) {
3251 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
3252 "device\n");
3253 return err;
3254 }
3255
3256 ixgbe_napi_add_all(adapter);
3257 ixgbe_reset(adapter);
3258
3259 if (netif_running(netdev)) {
3260 err = ixgbe_open(adapter->netdev);
3261 if (err)
3262 return err;
3263 }
3264
3265 netif_device_attach(netdev);
3266
3267 return 0;
3268}
3269
3270#endif /* CONFIG_PM */
3271static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
3272{
3273 struct net_device *netdev = pci_get_drvdata(pdev);
3274 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3275#ifdef CONFIG_PM
3276 int retval = 0;
3277#endif
3278
3279 netif_device_detach(netdev);
3280
3281 if (netif_running(netdev)) {
3282 ixgbe_down(adapter);
3283 ixgbe_free_irq(adapter);
3284 ixgbe_free_all_tx_resources(adapter);
3285 ixgbe_free_all_rx_resources(adapter);
3286 }
3287 ixgbe_reset_interrupt_capability(adapter);
3288 ixgbe_napi_del_all(adapter);
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003289 INIT_LIST_HEAD(&netdev->napi_list);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003290 kfree(adapter->tx_ring);
3291 kfree(adapter->rx_ring);
3292
3293#ifdef CONFIG_PM
3294 retval = pci_save_state(pdev);
3295 if (retval)
3296 return retval;
3297#endif
3298
3299 pci_enable_wake(pdev, PCI_D3hot, 0);
3300 pci_enable_wake(pdev, PCI_D3cold, 0);
3301
3302 ixgbe_release_hw_control(adapter);
3303
3304 pci_disable_device(pdev);
3305
3306 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3307
3308 return 0;
3309}
3310
3311static void ixgbe_shutdown(struct pci_dev *pdev)
3312{
3313 ixgbe_suspend(pdev, PMSG_SUSPEND);
3314}
3315
3316/**
Auke Kok9a799d72007-09-15 14:07:45 -07003317 * ixgbe_update_stats - Update the board statistics counters.
3318 * @adapter: board private structure
3319 **/
3320void ixgbe_update_stats(struct ixgbe_adapter *adapter)
3321{
3322 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003323 u64 total_mpc = 0;
3324 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003325
3326 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003327 for (i = 0; i < 8; i++) {
3328 /* for packet buffers not used, the register should read 0 */
3329 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
3330 missed_rx += mpc;
3331 adapter->stats.mpc[i] += mpc;
3332 total_mpc += adapter->stats.mpc[i];
3333 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08003334 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
3335 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
3336 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
3337 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
3338 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3339 IXGBE_PXONRXC(i));
3340 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
3341 IXGBE_PXONTXC(i));
3342 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3343 IXGBE_PXOFFRXC(i));
3344 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
3345 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003346 }
3347 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
3348 /* work around hardware counting issue */
3349 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07003350
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003351 /* 82598 hardware only has a 32 bit counter in the high register */
Auke Kok9a799d72007-09-15 14:07:45 -07003352 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003353 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
3354 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
Auke Kok9a799d72007-09-15 14:07:45 -07003355 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
3356 adapter->stats.bprc += bprc;
3357 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
3358 adapter->stats.mprc -= bprc;
3359 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
3360 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
3361 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
3362 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
3363 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
3364 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
3365 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003366 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
3367 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Auke Kok9a799d72007-09-15 14:07:45 -07003368 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003369 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
3370 adapter->stats.lxontxc += lxon;
3371 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
3372 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07003373 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3374 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003375 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
3376 /*
3377 * 82598 errata - tx of flow control packets is included in tx counters
3378 */
3379 xon_off_tot = lxon + lxoff;
3380 adapter->stats.gptc -= xon_off_tot;
3381 adapter->stats.mptc -= xon_off_tot;
3382 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07003383 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3384 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
3385 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07003386 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
3387 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003388 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003389 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3390 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3391 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3392 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3393 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003394 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3395
3396 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07003397 adapter->net_stats.multicast = adapter->stats.mprc;
3398
3399 /* Rx Errors */
3400 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003401 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07003402 adapter->net_stats.rx_dropped = 0;
3403 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3404 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003405 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07003406}
3407
3408/**
3409 * ixgbe_watchdog - Timer Call-back
3410 * @data: pointer to adapter cast into an unsigned long
3411 **/
3412static void ixgbe_watchdog(unsigned long data)
3413{
3414 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003415 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003416
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003417 /* Do the watchdog outside of interrupt context due to the lovely
3418 * delays that some of the newer hardware requires */
3419 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
3420 /* Cause software interrupt to ensure rx rings are cleaned */
3421 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3422 u32 eics =
3423 (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1;
3424 IXGBE_WRITE_REG(hw, IXGBE_EICS, eics);
3425 } else {
3426 /* For legacy and MSI interrupts don't set any bits that
3427 * are enabled for EIAM, because this operation would
3428 * set *both* EIMS and EICS for any bit in EIAM */
3429 IXGBE_WRITE_REG(hw, IXGBE_EICS,
3430 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
3431 }
3432 /* Reset the timer */
3433 mod_timer(&adapter->watchdog_timer,
3434 round_jiffies(jiffies + 2 * HZ));
3435 }
3436
3437 schedule_work(&adapter->watchdog_task);
3438}
3439
3440/**
Alexander Duyck69888672008-09-11 20:05:39 -07003441 * ixgbe_watchdog_task - worker thread to bring link up
3442 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003443 **/
3444static void ixgbe_watchdog_task(struct work_struct *work)
3445{
3446 struct ixgbe_adapter *adapter = container_of(work,
3447 struct ixgbe_adapter,
3448 watchdog_task);
3449 struct net_device *netdev = adapter->netdev;
3450 struct ixgbe_hw *hw = &adapter->hw;
3451 u32 link_speed = adapter->link_speed;
3452 bool link_up = adapter->link_up;
3453
3454 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
3455
3456 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3457 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
3458 if (link_up ||
3459 time_after(jiffies, (adapter->link_check_timeout +
3460 IXGBE_TRY_LINK_TIMEOUT))) {
3461 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
3462 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
3463 }
3464 adapter->link_up = link_up;
3465 adapter->link_speed = link_speed;
3466 }
Auke Kok9a799d72007-09-15 14:07:45 -07003467
3468 if (link_up) {
3469 if (!netif_carrier_ok(netdev)) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003470 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3471 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
Auke Kok9a799d72007-09-15 14:07:45 -07003472#define FLOW_RX (frctl & IXGBE_FCTRL_RFCE)
3473#define FLOW_TX (rmcs & IXGBE_RMCS_TFCE_802_3X)
Jeff Kirshera46e5342008-11-27 00:22:21 -08003474 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
3475 "Flow Control: %s\n",
3476 netdev->name,
3477 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
3478 "10 Gbps" :
3479 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
3480 "1 Gbps" : "unknown speed")),
3481 ((FLOW_RX && FLOW_TX) ? "RX/TX" :
3482 (FLOW_RX ? "RX" :
3483 (FLOW_TX ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07003484
3485 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003486 } else {
3487 /* Force detection of hung controller */
3488 adapter->detect_tx_hung = true;
3489 }
3490 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003491 adapter->link_up = false;
3492 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003493 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08003494 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
3495 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07003496 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003497 }
3498 }
3499
3500 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003501 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07003502}
3503
Auke Kok9a799d72007-09-15 14:07:45 -07003504static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003505 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
3506 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07003507{
3508 struct ixgbe_adv_tx_context_desc *context_desc;
3509 unsigned int i;
3510 int err;
3511 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003512 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
3513 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07003514
3515 if (skb_is_gso(skb)) {
3516 if (skb_header_cloned(skb)) {
3517 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3518 if (err)
3519 return err;
3520 }
3521 l4len = tcp_hdrlen(skb);
3522 *hdr_len += l4len;
3523
Al Viro8327d002007-12-10 18:54:12 +00003524 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003525 struct iphdr *iph = ip_hdr(skb);
3526 iph->tot_len = 0;
3527 iph->check = 0;
3528 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003529 iph->daddr, 0,
3530 IPPROTO_TCP,
3531 0);
Auke Kok9a799d72007-09-15 14:07:45 -07003532 adapter->hw_tso_ctxt++;
3533 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3534 ipv6_hdr(skb)->payload_len = 0;
3535 tcp_hdr(skb)->check =
3536 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003537 &ipv6_hdr(skb)->daddr,
3538 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07003539 adapter->hw_tso6_ctxt++;
3540 }
3541
3542 i = tx_ring->next_to_use;
3543
3544 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3545 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3546
3547 /* VLAN MACLEN IPLEN */
3548 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3549 vlan_macip_lens |=
3550 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3551 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003552 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003553 *hdr_len += skb_network_offset(skb);
3554 vlan_macip_lens |=
3555 (skb_transport_header(skb) - skb_network_header(skb));
3556 *hdr_len +=
3557 (skb_transport_header(skb) - skb_network_header(skb));
3558 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3559 context_desc->seqnum_seed = 0;
3560
3561 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003562 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003563 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07003564
Al Viro8327d002007-12-10 18:54:12 +00003565 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07003566 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3567 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3568 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3569
3570 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003571 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07003572 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
3573 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003574 /* use index 1 for TSO */
3575 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003576 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
3577
3578 tx_buffer_info->time_stamp = jiffies;
3579 tx_buffer_info->next_to_watch = i;
3580
3581 i++;
3582 if (i == tx_ring->count)
3583 i = 0;
3584 tx_ring->next_to_use = i;
3585
3586 return true;
3587 }
3588 return false;
3589}
3590
3591static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003592 struct ixgbe_ring *tx_ring,
3593 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07003594{
3595 struct ixgbe_adv_tx_context_desc *context_desc;
3596 unsigned int i;
3597 struct ixgbe_tx_buffer *tx_buffer_info;
3598 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3599
3600 if (skb->ip_summed == CHECKSUM_PARTIAL ||
3601 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
3602 i = tx_ring->next_to_use;
3603 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3604 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3605
3606 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3607 vlan_macip_lens |=
3608 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3609 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003610 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003611 if (skb->ip_summed == CHECKSUM_PARTIAL)
3612 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003613 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07003614
3615 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3616 context_desc->seqnum_seed = 0;
3617
3618 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003619 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07003620
3621 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08003622 switch (skb->protocol) {
Harvey Harrison09640e632009-02-01 00:45:17 -08003623 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07003624 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08003625 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3626 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003627 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08003628 break;
Harvey Harrison09640e632009-02-01 00:45:17 -08003629 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08003630 /* XXX what about other V6 headers?? */
3631 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3632 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003633 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08003634 break;
Auke Kok41825d72008-02-12 15:20:33 -08003635 default:
3636 if (unlikely(net_ratelimit())) {
3637 DPRINTK(PROBE, WARNING,
3638 "partial checksum but proto=%x!\n",
3639 skb->protocol);
3640 }
3641 break;
3642 }
Auke Kok9a799d72007-09-15 14:07:45 -07003643 }
3644
3645 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003646 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07003647 context_desc->mss_l4len_idx = 0;
3648
3649 tx_buffer_info->time_stamp = jiffies;
3650 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003651
Auke Kok9a799d72007-09-15 14:07:45 -07003652 adapter->hw_csum_tx_good++;
3653 i++;
3654 if (i == tx_ring->count)
3655 i = 0;
3656 tx_ring->next_to_use = i;
3657
3658 return true;
3659 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003660
Auke Kok9a799d72007-09-15 14:07:45 -07003661 return false;
3662}
3663
3664static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003665 struct ixgbe_ring *tx_ring,
3666 struct sk_buff *skb, unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07003667{
3668 struct ixgbe_tx_buffer *tx_buffer_info;
3669 unsigned int len = skb->len;
3670 unsigned int offset = 0, size, count = 0, i;
3671 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3672 unsigned int f;
3673
3674 len -= skb->data_len;
3675
3676 i = tx_ring->next_to_use;
3677
3678 while (len) {
3679 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3680 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3681
3682 tx_buffer_info->length = size;
3683 tx_buffer_info->dma = pci_map_single(adapter->pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003684 skb->data + offset,
3685 size, PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003686 tx_buffer_info->time_stamp = jiffies;
3687 tx_buffer_info->next_to_watch = i;
3688
3689 len -= size;
3690 offset += size;
3691 count++;
3692 i++;
3693 if (i == tx_ring->count)
3694 i = 0;
3695 }
3696
3697 for (f = 0; f < nr_frags; f++) {
3698 struct skb_frag_struct *frag;
3699
3700 frag = &skb_shinfo(skb)->frags[f];
3701 len = frag->size;
3702 offset = frag->page_offset;
3703
3704 while (len) {
3705 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3706 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3707
3708 tx_buffer_info->length = size;
3709 tx_buffer_info->dma = pci_map_page(adapter->pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003710 frag->page,
3711 offset,
3712 size,
3713 PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003714 tx_buffer_info->time_stamp = jiffies;
3715 tx_buffer_info->next_to_watch = i;
3716
3717 len -= size;
3718 offset += size;
3719 count++;
3720 i++;
3721 if (i == tx_ring->count)
3722 i = 0;
3723 }
3724 }
3725 if (i == 0)
3726 i = tx_ring->count - 1;
3727 else
3728 i = i - 1;
3729 tx_ring->tx_buffer_info[i].skb = skb;
3730 tx_ring->tx_buffer_info[first].next_to_watch = i;
3731
3732 return count;
3733}
3734
3735static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003736 struct ixgbe_ring *tx_ring,
3737 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07003738{
3739 union ixgbe_adv_tx_desc *tx_desc = NULL;
3740 struct ixgbe_tx_buffer *tx_buffer_info;
3741 u32 olinfo_status = 0, cmd_type_len = 0;
3742 unsigned int i;
3743 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
3744
3745 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
3746
3747 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
3748
3749 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3750 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
3751
3752 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
3753 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
3754
3755 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003756 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003757
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003758 /* use index 1 context for tso */
3759 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003760 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
3761 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003762 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003763
3764 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
3765 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003766 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003767
3768 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
3769
3770 i = tx_ring->next_to_use;
3771 while (count--) {
3772 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3773 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
3774 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
3775 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003776 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07003777 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07003778 i++;
3779 if (i == tx_ring->count)
3780 i = 0;
3781 }
3782
3783 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
3784
3785 /*
3786 * Force memory writes to complete before letting h/w
3787 * know there are new descriptors to fetch. (Only
3788 * applicable for weak-ordered memory model archs,
3789 * such as IA-64).
3790 */
3791 wmb();
3792
3793 tx_ring->next_to_use = i;
3794 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3795}
3796
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003797static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003798 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003799{
3800 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3801
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003802 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003803 /* Herbert's original patch had:
3804 * smp_mb__after_netif_stop_queue();
3805 * but since that doesn't exist yet, just open code it. */
3806 smp_mb();
3807
3808 /* We need to check again in a case another CPU has just
3809 * made room available. */
3810 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
3811 return -EBUSY;
3812
3813 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07003814 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003815 ++adapter->restart_queue;
3816 return 0;
3817}
3818
3819static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003820 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003821{
3822 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
3823 return 0;
3824 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
3825}
3826
Auke Kok9a799d72007-09-15 14:07:45 -07003827static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3828{
3829 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3830 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07003831 unsigned int first;
3832 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003833 u8 hdr_len = 0;
3834 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07003835 int count = 0;
3836 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003837
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003838 r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003839 tx_ring = &adapter->tx_ring[r_idx];
Auke Kok9a799d72007-09-15 14:07:45 -07003840
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003841 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3842 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003843 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3844 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
3845 tx_flags |= (skb->queue_mapping << 13);
3846 }
3847 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3848 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3849 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3850 tx_flags |= (skb->queue_mapping << 13);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003851 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3852 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07003853 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003854 /* three things can cause us to need a context descriptor */
3855 if (skb_is_gso(skb) ||
3856 (skb->ip_summed == CHECKSUM_PARTIAL) ||
3857 (tx_flags & IXGBE_TX_FLAGS_VLAN))
Auke Kok9a799d72007-09-15 14:07:45 -07003858 count++;
3859
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003860 count += TXD_USE_COUNT(skb_headlen(skb));
3861 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07003862 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
3863
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003864 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003865 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07003866 return NETDEV_TX_BUSY;
3867 }
Auke Kok9a799d72007-09-15 14:07:45 -07003868
Al Viro8327d002007-12-10 18:54:12 +00003869 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07003870 tx_flags |= IXGBE_TX_FLAGS_IPV4;
3871 first = tx_ring->next_to_use;
3872 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
3873 if (tso < 0) {
3874 dev_kfree_skb_any(skb);
3875 return NETDEV_TX_OK;
3876 }
3877
3878 if (tso)
3879 tx_flags |= IXGBE_TX_FLAGS_TSO;
3880 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003881 (skb->ip_summed == CHECKSUM_PARTIAL))
Auke Kok9a799d72007-09-15 14:07:45 -07003882 tx_flags |= IXGBE_TX_FLAGS_CSUM;
3883
3884 ixgbe_tx_queue(adapter, tx_ring, tx_flags,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003885 ixgbe_tx_map(adapter, tx_ring, skb, first),
3886 skb->len, hdr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07003887
3888 netdev->trans_start = jiffies;
3889
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003890 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07003891
3892 return NETDEV_TX_OK;
3893}
3894
3895/**
3896 * ixgbe_get_stats - Get System Network Statistics
3897 * @netdev: network interface device structure
3898 *
3899 * Returns the address of the device statistics structure.
3900 * The statistics are actually updated from the timer callback.
3901 **/
3902static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
3903{
3904 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3905
3906 /* only return the current stats */
3907 return &adapter->net_stats;
3908}
3909
3910/**
3911 * ixgbe_set_mac - Change the Ethernet Address of the NIC
3912 * @netdev: network interface device structure
3913 * @p: pointer to an address structure
3914 *
3915 * Returns 0 on success, negative on failure
3916 **/
3917static int ixgbe_set_mac(struct net_device *netdev, void *p)
3918{
3919 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003920 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003921 struct sockaddr *addr = p;
3922
3923 if (!is_valid_ether_addr(addr->sa_data))
3924 return -EADDRNOTAVAIL;
3925
3926 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003927 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07003928
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003929 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003930
3931 return 0;
3932}
3933
3934#ifdef CONFIG_NET_POLL_CONTROLLER
3935/*
3936 * Polling 'interrupt' - used by things like netconsole to send skbs
3937 * without having to re-enable interrupts. It's not called while
3938 * the interrupt routine is executing.
3939 */
3940static void ixgbe_netpoll(struct net_device *netdev)
3941{
3942 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3943
3944 disable_irq(adapter->pdev->irq);
3945 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
3946 ixgbe_intr(adapter->pdev->irq, netdev);
3947 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
3948 enable_irq(adapter->pdev->irq);
3949}
3950#endif
3951
Stephen Hemminger0edc3522008-11-19 22:24:29 -08003952static const struct net_device_ops ixgbe_netdev_ops = {
3953 .ndo_open = ixgbe_open,
3954 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08003955 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08003956 .ndo_get_stats = ixgbe_get_stats,
3957 .ndo_set_multicast_list = ixgbe_set_rx_mode,
3958 .ndo_validate_addr = eth_validate_addr,
3959 .ndo_set_mac_address = ixgbe_set_mac,
3960 .ndo_change_mtu = ixgbe_change_mtu,
3961 .ndo_tx_timeout = ixgbe_tx_timeout,
3962 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
3963 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
3964 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
3965#ifdef CONFIG_NET_POLL_CONTROLLER
3966 .ndo_poll_controller = ixgbe_netpoll,
3967#endif
3968};
3969
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003970/**
Auke Kok9a799d72007-09-15 14:07:45 -07003971 * ixgbe_probe - Device Initialization Routine
3972 * @pdev: PCI device information struct
3973 * @ent: entry in ixgbe_pci_tbl
3974 *
3975 * Returns 0 on success, negative on failure
3976 *
3977 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
3978 * The OS initialization, configuring of the adapter private structure,
3979 * and a hardware reset occur.
3980 **/
3981static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003982 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07003983{
3984 struct net_device *netdev;
3985 struct ixgbe_adapter *adapter = NULL;
3986 struct ixgbe_hw *hw;
3987 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07003988 static int cards_found;
3989 int i, err, pci_using_dac;
3990 u16 link_status, link_speed, link_width;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003991 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07003992
3993 err = pci_enable_device(pdev);
3994 if (err)
3995 return err;
3996
3997 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
3998 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
3999 pci_using_dac = 1;
4000 } else {
4001 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4002 if (err) {
4003 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
4004 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004005 dev_err(&pdev->dev, "No usable DMA "
4006 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004007 goto err_dma;
4008 }
4009 }
4010 pci_using_dac = 0;
4011 }
4012
4013 err = pci_request_regions(pdev, ixgbe_driver_name);
4014 if (err) {
4015 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
4016 goto err_pci_reg;
4017 }
4018
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004019 err = pci_enable_pcie_error_reporting(pdev);
4020 if (err) {
4021 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
4022 "0x%x\n", err);
4023 /* non-fatal, continue */
4024 }
4025
Auke Kok9a799d72007-09-15 14:07:45 -07004026 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07004027 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004028
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004029 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07004030 if (!netdev) {
4031 err = -ENOMEM;
4032 goto err_alloc_etherdev;
4033 }
4034
Auke Kok9a799d72007-09-15 14:07:45 -07004035 SET_NETDEV_DEV(netdev, &pdev->dev);
4036
4037 pci_set_drvdata(pdev, netdev);
4038 adapter = netdev_priv(netdev);
4039
4040 adapter->netdev = netdev;
4041 adapter->pdev = pdev;
4042 hw = &adapter->hw;
4043 hw->back = adapter;
4044 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
4045
Jeff Kirsher05857982008-09-11 19:57:00 -07004046 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
4047 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07004048 if (!hw->hw_addr) {
4049 err = -EIO;
4050 goto err_ioremap;
4051 }
4052
4053 for (i = 1; i <= 5; i++) {
4054 if (pci_resource_len(pdev, i) == 0)
4055 continue;
4056 }
4057
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004058 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07004059 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004060 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07004061 strcpy(netdev->name, pci_name(pdev));
4062
Auke Kok9a799d72007-09-15 14:07:45 -07004063 adapter->bd_number = cards_found;
4064
Auke Kok9a799d72007-09-15 14:07:45 -07004065 /* Setup hw api */
4066 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004067 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07004068
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004069 /* EEPROM */
4070 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
4071 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
4072 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
4073 if (!(eec & (1 << 8)))
4074 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
4075
4076 /* PHY */
4077 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08004078 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
4079
4080 /* set up this timer and work struct before calling get_invariants
4081 * which might start the timer
4082 */
4083 init_timer(&adapter->sfp_timer);
4084 adapter->sfp_timer.function = &ixgbe_sfp_timer;
4085 adapter->sfp_timer.data = (unsigned long) adapter;
4086
4087 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004088
Auke Kok9a799d72007-09-15 14:07:45 -07004089 err = ii->get_invariants(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004090 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
4091 /* start a kernel thread to watch for a module to arrive */
4092 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4093 mod_timer(&adapter->sfp_timer,
4094 round_jiffies(jiffies + (2 * HZ)));
4095 err = 0;
4096 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4097 DPRINTK(PROBE, ERR, "failed to load because an "
4098 "unsupported SFP+ module type was detected.\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004099 goto err_hw_init;
Donald Skidmorec4900be2008-11-20 21:11:42 -08004100 } else if (err) {
4101 goto err_hw_init;
4102 }
Auke Kok9a799d72007-09-15 14:07:45 -07004103
4104 /* setup the private structure */
4105 err = ixgbe_sw_init(adapter);
4106 if (err)
4107 goto err_sw_init;
4108
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004109 /* reset_hw fills in the perm_addr as well */
4110 err = hw->mac.ops.reset_hw(hw);
4111 if (err) {
4112 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
4113 goto err_sw_init;
4114 }
4115
Auke Kok9a799d72007-09-15 14:07:45 -07004116 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004117 NETIF_F_IP_CSUM |
4118 NETIF_F_HW_VLAN_TX |
4119 NETIF_F_HW_VLAN_RX |
4120 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004121
Jesse Brandeburge9990a92008-08-26 04:27:24 -07004122 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07004123 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07004124 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08004125 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004126
4127 netdev->vlan_features |= NETIF_F_TSO;
4128 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07004129 netdev->vlan_features |= NETIF_F_IP_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004130 netdev->vlan_features |= NETIF_F_SG;
4131
Alexander Duyck2f90b862008-11-20 20:52:10 -08004132 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4133 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4134
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004135#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004136 netdev->dcbnl_ops = &dcbnl_ops;
4137#endif
4138
Auke Kok9a799d72007-09-15 14:07:45 -07004139 if (pci_using_dac)
4140 netdev->features |= NETIF_F_HIGHDMA;
4141
Auke Kok9a799d72007-09-15 14:07:45 -07004142 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004143 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07004144 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
4145 err = -EIO;
4146 goto err_eeprom;
4147 }
4148
4149 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
4150 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
4151
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004152 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
4153 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004154 err = -EIO;
4155 goto err_eeprom;
4156 }
4157
4158 init_timer(&adapter->watchdog_timer);
4159 adapter->watchdog_timer.function = &ixgbe_watchdog;
4160 adapter->watchdog_timer.data = (unsigned long)adapter;
4161
4162 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004163 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004164
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004165 err = ixgbe_init_interrupt_scheme(adapter);
4166 if (err)
4167 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07004168
4169 /* print bus type/speed/width info */
4170 pci_read_config_word(pdev, IXGBE_PCI_LINK_STATUS, &link_status);
4171 link_speed = link_status & IXGBE_PCI_LINK_SPEED;
4172 link_width = link_status & IXGBE_PCI_LINK_WIDTH;
Johannes Berg7c510e42008-10-27 17:47:26 -07004173 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004174 ((link_speed == IXGBE_PCI_LINK_SPEED_5000) ? "5.0Gb/s" :
4175 (link_speed == IXGBE_PCI_LINK_SPEED_2500) ? "2.5Gb/s" :
4176 "Unknown"),
4177 ((link_width == IXGBE_PCI_LINK_WIDTH_8) ? "Width x8" :
4178 (link_width == IXGBE_PCI_LINK_WIDTH_4) ? "Width x4" :
4179 (link_width == IXGBE_PCI_LINK_WIDTH_2) ? "Width x2" :
4180 (link_width == IXGBE_PCI_LINK_WIDTH_1) ? "Width x1" :
4181 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07004182 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004183 ixgbe_read_pba_num_generic(hw, &part_num);
Auke Kok9a799d72007-09-15 14:07:45 -07004184 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004185 hw->mac.type, hw->phy.type,
4186 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07004187
Auke Kok0c254d82008-02-11 09:25:56 -08004188 if (link_width <= IXGBE_PCI_LINK_WIDTH_4) {
4189 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004190 "this card is not sufficient for optimal "
4191 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004192 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004193 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004194 }
4195
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08004196 /* save off EEPROM version number */
4197 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
4198
Auke Kok9a799d72007-09-15 14:07:45 -07004199 /* reset the hardware with the new settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004200 hw->mac.ops.start_hw(hw);
4201
Auke Kok9a799d72007-09-15 14:07:45 -07004202 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004203
4204 strcpy(netdev->name, "eth%d");
4205 err = register_netdev(netdev);
4206 if (err)
4207 goto err_register;
4208
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004209#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03004210 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004211 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
4212 /* always use CB2 mode, difference is masked
4213 * in the CB driver */
4214 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
4215 ixgbe_setup_dca(adapter);
4216 }
4217#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004218
4219 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
4220 cards_found++;
4221 return 0;
4222
4223err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004224 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004225err_hw_init:
4226err_sw_init:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004227 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004228err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08004229 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4230 del_timer_sync(&adapter->sfp_timer);
4231 cancel_work_sync(&adapter->sfp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004232 iounmap(hw->hw_addr);
4233err_ioremap:
4234 free_netdev(netdev);
4235err_alloc_etherdev:
4236 pci_release_regions(pdev);
4237err_pci_reg:
4238err_dma:
4239 pci_disable_device(pdev);
4240 return err;
4241}
4242
4243/**
4244 * ixgbe_remove - Device Removal Routine
4245 * @pdev: PCI device information struct
4246 *
4247 * ixgbe_remove is called by the PCI subsystem to alert the driver
4248 * that it should release a PCI device. The could be caused by a
4249 * Hot-Plug event, or because the driver is going to be removed from
4250 * memory.
4251 **/
4252static void __devexit ixgbe_remove(struct pci_dev *pdev)
4253{
4254 struct net_device *netdev = pci_get_drvdata(pdev);
4255 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004256 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004257
4258 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004259 /* clear the module not found bit to make sure the worker won't
4260 * reschedule
4261 */
4262 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07004263 del_timer_sync(&adapter->watchdog_timer);
4264
Donald Skidmorec4900be2008-11-20 21:11:42 -08004265 del_timer_sync(&adapter->sfp_timer);
4266 cancel_work_sync(&adapter->watchdog_task);
4267 cancel_work_sync(&adapter->sfp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004268 flush_scheduled_work();
4269
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004270#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004271 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
4272 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
4273 dca_remove_requester(&pdev->dev);
4274 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
4275 }
4276
4277#endif
Donald Skidmorec4900be2008-11-20 21:11:42 -08004278 if (netdev->reg_state == NETREG_REGISTERED)
4279 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004280
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004281 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004282
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004283 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004284
4285 iounmap(adapter->hw.hw_addr);
4286 pci_release_regions(pdev);
4287
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004288 DPRINTK(PROBE, INFO, "complete\n");
4289 kfree(adapter->tx_ring);
4290 kfree(adapter->rx_ring);
4291
Auke Kok9a799d72007-09-15 14:07:45 -07004292 free_netdev(netdev);
4293
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004294 err = pci_disable_pcie_error_reporting(pdev);
4295 if (err)
4296 dev_err(&pdev->dev,
4297 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
4298
Auke Kok9a799d72007-09-15 14:07:45 -07004299 pci_disable_device(pdev);
4300}
4301
4302/**
4303 * ixgbe_io_error_detected - called when PCI error is detected
4304 * @pdev: Pointer to PCI device
4305 * @state: The current pci connection state
4306 *
4307 * This function is called after a PCI bus error affecting
4308 * this device has been detected.
4309 */
4310static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004311 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07004312{
4313 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004314 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004315
4316 netif_device_detach(netdev);
4317
4318 if (netif_running(netdev))
4319 ixgbe_down(adapter);
4320 pci_disable_device(pdev);
4321
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004322 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07004323 return PCI_ERS_RESULT_NEED_RESET;
4324}
4325
4326/**
4327 * ixgbe_io_slot_reset - called after the pci bus has been reset.
4328 * @pdev: Pointer to PCI device
4329 *
4330 * Restart the card from scratch, as if from a cold-boot.
4331 */
4332static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
4333{
4334 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004335 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004336 pci_ers_result_t result;
4337 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004338
4339 if (pci_enable_device(pdev)) {
4340 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004341 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004342 result = PCI_ERS_RESULT_DISCONNECT;
4343 } else {
4344 pci_set_master(pdev);
4345 pci_restore_state(pdev);
4346
4347 pci_enable_wake(pdev, PCI_D3hot, 0);
4348 pci_enable_wake(pdev, PCI_D3cold, 0);
4349
4350 ixgbe_reset(adapter);
4351
4352 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07004353 }
Auke Kok9a799d72007-09-15 14:07:45 -07004354
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004355 err = pci_cleanup_aer_uncorrect_error_status(pdev);
4356 if (err) {
4357 dev_err(&pdev->dev,
4358 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
4359 /* non-fatal, continue */
4360 }
Auke Kok9a799d72007-09-15 14:07:45 -07004361
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004362 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07004363}
4364
4365/**
4366 * ixgbe_io_resume - called when traffic can start flowing again.
4367 * @pdev: Pointer to PCI device
4368 *
4369 * This callback is called when the error recovery driver tells us that
4370 * its OK to resume normal operation.
4371 */
4372static void ixgbe_io_resume(struct pci_dev *pdev)
4373{
4374 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004375 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004376
4377 if (netif_running(netdev)) {
4378 if (ixgbe_up(adapter)) {
4379 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
4380 return;
4381 }
4382 }
4383
4384 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004385}
4386
4387static struct pci_error_handlers ixgbe_err_handler = {
4388 .error_detected = ixgbe_io_error_detected,
4389 .slot_reset = ixgbe_io_slot_reset,
4390 .resume = ixgbe_io_resume,
4391};
4392
4393static struct pci_driver ixgbe_driver = {
4394 .name = ixgbe_driver_name,
4395 .id_table = ixgbe_pci_tbl,
4396 .probe = ixgbe_probe,
4397 .remove = __devexit_p(ixgbe_remove),
4398#ifdef CONFIG_PM
4399 .suspend = ixgbe_suspend,
4400 .resume = ixgbe_resume,
4401#endif
4402 .shutdown = ixgbe_shutdown,
4403 .err_handler = &ixgbe_err_handler
4404};
4405
4406/**
4407 * ixgbe_init_module - Driver Registration Routine
4408 *
4409 * ixgbe_init_module is the first routine called when the driver is
4410 * loaded. All it does is register with the PCI subsystem.
4411 **/
4412static int __init ixgbe_init_module(void)
4413{
4414 int ret;
4415 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
4416 ixgbe_driver_string, ixgbe_driver_version);
4417
4418 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
4419
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004420#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004421 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004422#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004423
Auke Kok9a799d72007-09-15 14:07:45 -07004424 ret = pci_register_driver(&ixgbe_driver);
4425 return ret;
4426}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004427
Auke Kok9a799d72007-09-15 14:07:45 -07004428module_init(ixgbe_init_module);
4429
4430/**
4431 * ixgbe_exit_module - Driver Exit Cleanup Routine
4432 *
4433 * ixgbe_exit_module is called just before the driver is removed
4434 * from memory.
4435 **/
4436static void __exit ixgbe_exit_module(void)
4437{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004438#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004439 dca_unregister_notify(&dca_notifier);
4440#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004441 pci_unregister_driver(&ixgbe_driver);
4442}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004443
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004444#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004445static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004446 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004447{
4448 int ret_val;
4449
4450 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004451 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004452
4453 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4454}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004455#endif /* CONFIG_IXGBE_DCA */
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004456
Auke Kok9a799d72007-09-15 14:07:45 -07004457module_exit(ixgbe_exit_module);
4458
4459/* ixgbe_main.c */