blob: acef3c65cd2c4c2d3ba463c10f5f5cf0b3a725ff [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004 Copyright(c) 1999 - 2008 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
Jeff Kirsher51ac6442008-09-11 20:03:55 -070050#define DRV_VERSION "1.3.30-k2"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070051const char ixgbe_driver_version[] = DRV_VERSION;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070052static char ixgbe_copyright[] = "Copyright (c) 1999-2007 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[] = {
67 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070068 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070069 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070070 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070071 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
72 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070073 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070074 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070075 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
76 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080077 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
78 board_82598 },
79 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
80 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070081 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
82 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080083 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
84 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070085
86 /* required last entry */
87 {0, }
88};
89MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
90
Jeff Garzik5dd2d332008-10-16 05:09:31 -040091#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080092static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070093 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080094static struct notifier_block dca_notifier = {
95 .notifier_call = ixgbe_notify_dca,
96 .next = NULL,
97 .priority = 0
98};
99#endif
100
Auke Kok9a799d72007-09-15 14:07:45 -0700101MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
102MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
103MODULE_LICENSE("GPL");
104MODULE_VERSION(DRV_VERSION);
105
106#define DEFAULT_DEBUG_LEVEL_SHIFT 3
107
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800108static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
109{
110 u32 ctrl_ext;
111
112 /* Let firmware take over control of h/w */
113 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
114 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700115 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800116}
117
118static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
119{
120 u32 ctrl_ext;
121
122 /* Let firmware know the driver has taken over */
123 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
124 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700125 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800126}
Auke Kok9a799d72007-09-15 14:07:45 -0700127
Auke Kok9a799d72007-09-15 14:07:45 -0700128static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, u16 int_alloc_entry,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700129 u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700130{
131 u32 ivar, index;
132
133 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
134 index = (int_alloc_entry >> 2) & 0x1F;
135 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR(index));
136 ivar &= ~(0xFF << (8 * (int_alloc_entry & 0x3)));
137 ivar |= (msix_vector << (8 * (int_alloc_entry & 0x3)));
138 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR(index), ivar);
139}
140
141static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700142 struct ixgbe_tx_buffer
143 *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700144{
145 if (tx_buffer_info->dma) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700146 pci_unmap_page(adapter->pdev, tx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700147 tx_buffer_info->length, PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700148 tx_buffer_info->dma = 0;
149 }
150 if (tx_buffer_info->skb) {
151 dev_kfree_skb_any(tx_buffer_info->skb);
152 tx_buffer_info->skb = NULL;
153 }
154 /* tx_buffer_info must be completely set up in the transmit path */
155}
156
157static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700158 struct ixgbe_ring *tx_ring,
159 unsigned int eop)
Auke Kok9a799d72007-09-15 14:07:45 -0700160{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700161 struct ixgbe_hw *hw = &adapter->hw;
162 u32 head, tail;
163
Auke Kok9a799d72007-09-15 14:07:45 -0700164 /* Detect a transmit hang in hardware, this serializes the
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700165 * check with the clearing of time_stamp and movement of eop */
166 head = IXGBE_READ_REG(hw, tx_ring->head);
167 tail = IXGBE_READ_REG(hw, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -0700168 adapter->detect_tx_hung = false;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700169 if ((head != tail) &&
170 tx_ring->tx_buffer_info[eop].time_stamp &&
Auke Kok9a799d72007-09-15 14:07:45 -0700171 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
172 !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) {
173 /* detected Tx unit hang */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700174 union ixgbe_adv_tx_desc *tx_desc;
175 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
Auke Kok9a799d72007-09-15 14:07:45 -0700176 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700177 " Tx Queue <%d>\n"
178 " TDH, TDT <%x>, <%x>\n"
Auke Kok9a799d72007-09-15 14:07:45 -0700179 " next_to_use <%x>\n"
180 " next_to_clean <%x>\n"
181 "tx_buffer_info[next_to_clean]\n"
182 " time_stamp <%lx>\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700183 " jiffies <%lx>\n",
184 tx_ring->queue_index,
185 head, tail,
186 tx_ring->next_to_use, eop,
187 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
Auke Kok9a799d72007-09-15 14:07:45 -0700188 return true;
189 }
190
191 return false;
192}
193
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700194#define IXGBE_MAX_TXD_PWR 14
195#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800196
197/* Tx Descriptors needed, worst case */
198#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
199 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
200#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700201 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800202
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700203#define GET_TX_HEAD_FROM_RING(ring) (\
204 *(volatile u32 *) \
205 ((union ixgbe_adv_tx_desc *)(ring)->desc + (ring)->count))
206static void ixgbe_tx_timeout(struct net_device *netdev);
207
Auke Kok9a799d72007-09-15 14:07:45 -0700208/**
209 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
210 * @adapter: board private structure
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700211 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700212 **/
213static bool ixgbe_clean_tx_irq(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700214 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700215{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700216 union ixgbe_adv_tx_desc *tx_desc;
Auke Kok9a799d72007-09-15 14:07:45 -0700217 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700218 struct net_device *netdev = adapter->netdev;
219 struct sk_buff *skb;
220 unsigned int i;
221 u32 head, oldhead;
222 unsigned int count = 0;
223 unsigned int total_bytes = 0, total_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700224
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700225 rmb();
226 head = GET_TX_HEAD_FROM_RING(tx_ring);
227 head = le32_to_cpu(head);
Auke Kok9a799d72007-09-15 14:07:45 -0700228 i = tx_ring->next_to_clean;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700229 while (1) {
230 while (i != head) {
Auke Kok9a799d72007-09-15 14:07:45 -0700231 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
232 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700233 skb = tx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700234
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700235 if (skb) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800236 unsigned int segs, bytecount;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700237
238 /* gso_segs is currently only valid for tcp */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800239 segs = skb_shinfo(skb)->gso_segs ?: 1;
240 /* multiply data chunks by size of headers */
241 bytecount = ((segs - 1) * skb_headlen(skb)) +
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700242 skb->len;
243 total_packets += segs;
244 total_bytes += bytecount;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800245 }
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700246
Auke Kok9a799d72007-09-15 14:07:45 -0700247 ixgbe_unmap_and_free_tx_resource(adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700248 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700249
250 i++;
251 if (i == tx_ring->count)
252 i = 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700253
254 count++;
255 if (count == tx_ring->count)
256 goto done_cleaning;
Auke Kok9a799d72007-09-15 14:07:45 -0700257 }
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700258 oldhead = head;
259 rmb();
260 head = GET_TX_HEAD_FROM_RING(tx_ring);
261 head = le32_to_cpu(head);
262 if (head == oldhead)
263 goto done_cleaning;
264 } /* while (1) */
Auke Kok9a799d72007-09-15 14:07:45 -0700265
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700266done_cleaning:
Auke Kok9a799d72007-09-15 14:07:45 -0700267 tx_ring->next_to_clean = i;
268
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800269#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700270 if (unlikely(count && netif_carrier_ok(netdev) &&
271 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800272 /* Make sure that anybody stopping the queue after this
273 * sees the new next_to_clean.
274 */
275 smp_mb();
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800276 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
277 !test_bit(__IXGBE_DOWN, &adapter->state)) {
278 netif_wake_subqueue(netdev, tx_ring->queue_index);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700279 ++adapter->restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800280 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800281 }
Auke Kok9a799d72007-09-15 14:07:45 -0700282
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700283 if (adapter->detect_tx_hung) {
284 if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
285 /* schedule immediate reset if we believe we hung */
286 DPRINTK(PROBE, INFO,
287 "tx hang %d detected, resetting adapter\n",
288 adapter->tx_timeout_count + 1);
289 ixgbe_tx_timeout(adapter->netdev);
290 }
291 }
Auke Kok9a799d72007-09-15 14:07:45 -0700292
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700293 /* re-arm the interrupt */
294 if ((total_packets >= tx_ring->work_limit) ||
295 (count == tx_ring->count))
296 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, tx_ring->v_idx);
Auke Kok9a799d72007-09-15 14:07:45 -0700297
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700298 tx_ring->total_bytes += total_bytes;
299 tx_ring->total_packets += total_packets;
300 tx_ring->stats.bytes += total_bytes;
301 tx_ring->stats.packets += total_packets;
302 adapter->net_stats.tx_bytes += total_bytes;
303 adapter->net_stats.tx_packets += total_packets;
304 return (total_packets ? true : false);
Auke Kok9a799d72007-09-15 14:07:45 -0700305}
306
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400307#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800308static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700309 struct ixgbe_ring *rx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800310{
311 u32 rxctrl;
312 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700313 int q = rx_ring - adapter->rx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800314
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700315 if (rx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800316 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
317 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700318 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800319 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
320 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
321 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700322 rx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800323 }
324 put_cpu();
325}
326
327static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700328 struct ixgbe_ring *tx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800329{
330 u32 txctrl;
331 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700332 int q = tx_ring - adapter->tx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800333
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700334 if (tx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800335 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
336 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700337 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800338 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
339 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700340 tx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800341 }
342 put_cpu();
343}
344
345static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
346{
347 int i;
348
349 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
350 return;
351
352 for (i = 0; i < adapter->num_tx_queues; i++) {
353 adapter->tx_ring[i].cpu = -1;
354 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
355 }
356 for (i = 0; i < adapter->num_rx_queues; i++) {
357 adapter->rx_ring[i].cpu = -1;
358 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
359 }
360}
361
362static int __ixgbe_notify_dca(struct device *dev, void *data)
363{
364 struct net_device *netdev = dev_get_drvdata(dev);
365 struct ixgbe_adapter *adapter = netdev_priv(netdev);
366 unsigned long event = *(unsigned long *)data;
367
368 switch (event) {
369 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700370 /* if we're already enabled, don't do it again */
371 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
372 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800373 /* Always use CB2 mode, difference is masked
374 * in the CB driver. */
375 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
Denis V. Lunev652f0932008-03-27 14:39:17 +0300376 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700377 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800378 ixgbe_setup_dca(adapter);
379 break;
380 }
381 /* Fall Through since DCA is disabled. */
382 case DCA_PROVIDER_REMOVE:
383 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
384 dca_remove_requester(dev);
385 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
386 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
387 }
388 break;
389 }
390
Denis V. Lunev652f0932008-03-27 14:39:17 +0300391 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800392}
393
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400394#endif /* CONFIG_IXGBE_DCA */
Auke Kok9a799d72007-09-15 14:07:45 -0700395/**
396 * ixgbe_receive_skb - Send a completed packet up the stack
397 * @adapter: board private structure
398 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700399 * @status: hardware indication of status of receive
400 * @rx_ring: rx descriptor ring (for a specific queue) to setup
401 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -0700402 **/
403static void ixgbe_receive_skb(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700404 struct sk_buff *skb, u8 status,
405 struct ixgbe_ring *ring,
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700406 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -0700407{
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
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700411 if (adapter->netdev->features & NETIF_F_LRO &&
412 skb->ip_summed == CHECKSUM_UNNECESSARY) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800413 if (adapter->vlgrp && is_vlan && (tag != 0))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700414 lro_vlan_hwaccel_receive_skb(&ring->lro_mgr, skb,
415 adapter->vlgrp, tag,
416 rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700417 else
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700418 lro_receive_skb(&ring->lro_mgr, skb, rx_desc);
419 ring->lro_used = true;
420 } else {
421 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800422 if (adapter->vlgrp && is_vlan && (tag != 0))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700423 vlan_hwaccel_receive_skb(skb, adapter->vlgrp, tag);
424 else
425 netif_receive_skb(skb);
426 } else {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800427 if (adapter->vlgrp && is_vlan && (tag != 0))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700428 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
429 else
430 netif_rx(skb);
431 }
Auke Kok9a799d72007-09-15 14:07:45 -0700432 }
433}
434
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800435/**
436 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
437 * @adapter: address of board private structure
438 * @status_err: hardware indication of status of receive
439 * @skb: skb currently being received and modified
440 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700441static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700442 u32 status_err, struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700443{
444 skb->ip_summed = CHECKSUM_NONE;
445
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700446 /* Rx csum disabled */
447 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -0700448 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800449
450 /* if IP and error */
451 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
452 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700453 adapter->hw_csum_rx_error++;
454 return;
455 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800456
457 if (!(status_err & IXGBE_RXD_STAT_L4CS))
458 return;
459
460 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
461 adapter->hw_csum_rx_error++;
462 return;
463 }
464
Auke Kok9a799d72007-09-15 14:07:45 -0700465 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800466 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -0700467 adapter->hw_csum_rx_good++;
468}
469
470/**
471 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
472 * @adapter: address of board private structure
473 **/
474static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700475 struct ixgbe_ring *rx_ring,
476 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700477{
Auke Kok9a799d72007-09-15 14:07:45 -0700478 struct pci_dev *pdev = adapter->pdev;
479 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700480 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700481 unsigned int i;
Auke Kok9a799d72007-09-15 14:07:45 -0700482
483 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700484 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700485
486 while (cleaned_count--) {
487 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
488
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700489 if (!bi->page_dma &&
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700490 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700491 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700492 bi->page = alloc_page(GFP_ATOMIC);
493 if (!bi->page) {
494 adapter->alloc_rx_page_failed++;
495 goto no_buffers;
496 }
497 bi->page_offset = 0;
498 } else {
499 /* use a half page if we're re-using */
500 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700501 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700502
503 bi->page_dma = pci_map_page(pdev, bi->page,
504 bi->page_offset,
505 (PAGE_SIZE / 2),
506 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700507 }
508
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700509 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800510 struct sk_buff *skb;
511 skb = netdev_alloc_skb(adapter->netdev,
512 (rx_ring->rx_buf_len +
513 NET_IP_ALIGN));
Auke Kok9a799d72007-09-15 14:07:45 -0700514
515 if (!skb) {
516 adapter->alloc_rx_buff_failed++;
517 goto no_buffers;
518 }
519
520 /*
521 * Make buffer alignment 2 beyond a 16 byte boundary
522 * this will result in a 16 byte aligned IP header after
523 * the 14 byte MAC header is removed
524 */
525 skb_reserve(skb, NET_IP_ALIGN);
526
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700527 bi->skb = skb;
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800528 bi->dma = pci_map_single(pdev, skb->data,
529 rx_ring->rx_buf_len,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700530 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700531 }
532 /* Refresh the desc even if buffer_addrs didn't change because
533 * each write-back erases this info. */
534 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700535 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
536 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700537 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700538 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700539 }
540
541 i++;
542 if (i == rx_ring->count)
543 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700544 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700545 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700546
Auke Kok9a799d72007-09-15 14:07:45 -0700547no_buffers:
548 if (rx_ring->next_to_use != i) {
549 rx_ring->next_to_use = i;
550 if (i-- == 0)
551 i = (rx_ring->count - 1);
552
553 /*
554 * Force memory writes to complete before letting h/w
555 * know there are new descriptors to fetch. (Only
556 * applicable for weak-ordered memory model archs,
557 * such as IA-64).
558 */
559 wmb();
560 writel(i, adapter->hw.hw_addr + rx_ring->tail);
561 }
562}
563
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700564static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
565{
566 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
567}
568
569static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
570{
571 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
572}
573
Auke Kok9a799d72007-09-15 14:07:45 -0700574static bool ixgbe_clean_rx_irq(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700575 struct ixgbe_ring *rx_ring,
576 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700577{
Auke Kok9a799d72007-09-15 14:07:45 -0700578 struct pci_dev *pdev = adapter->pdev;
579 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
580 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
581 struct sk_buff *skb;
582 unsigned int i;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700583 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700584 u16 hdr_info;
585 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700586 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800587 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700588
589 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700590 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
591 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
592 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700593
594 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700595 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700596 if (*work_done >= work_to_do)
597 break;
598 (*work_done)++;
599
600 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700601 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
602 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700603 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700604 if (hdr_info & IXGBE_RXDADV_SPH)
605 adapter->rx_hdr_split++;
606 if (len > IXGBE_RX_HDR_SIZE)
607 len = IXGBE_RX_HDR_SIZE;
608 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700609 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700610 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700611 }
Auke Kok9a799d72007-09-15 14:07:45 -0700612
613 cleaned = true;
614 skb = rx_buffer_info->skb;
615 prefetch(skb->data - NET_IP_ALIGN);
616 rx_buffer_info->skb = NULL;
617
618 if (len && !skb_shinfo(skb)->nr_frags) {
619 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800620 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700621 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700622 skb_put(skb, len);
623 }
624
625 if (upper_len) {
626 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700627 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700628 rx_buffer_info->page_dma = 0;
629 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700630 rx_buffer_info->page,
631 rx_buffer_info->page_offset,
632 upper_len);
633
634 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
635 (page_count(rx_buffer_info->page) != 1))
636 rx_buffer_info->page = NULL;
637 else
638 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700639
640 skb->len += upper_len;
641 skb->data_len += upper_len;
642 skb->truesize += upper_len;
643 }
644
645 i++;
646 if (i == rx_ring->count)
647 i = 0;
648 next_buffer = &rx_ring->rx_buffer_info[i];
649
650 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
651 prefetch(next_rxd);
652
653 cleaned_count++;
654 if (staterr & IXGBE_RXD_STAT_EOP) {
655 rx_ring->stats.packets++;
656 rx_ring->stats.bytes += skb->len;
657 } else {
658 rx_buffer_info->skb = next_buffer->skb;
659 rx_buffer_info->dma = next_buffer->dma;
660 next_buffer->skb = skb;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700661 next_buffer->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700662 adapter->non_eop_descs++;
663 goto next_desc;
664 }
665
666 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
667 dev_kfree_skb_irq(skb);
668 goto next_desc;
669 }
670
671 ixgbe_rx_checksum(adapter, staterr, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800672
673 /* probably a little skewed due to removing CRC */
674 total_rx_bytes += skb->len;
675 total_rx_packets++;
676
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700677 skb->protocol = eth_type_trans(skb, adapter->netdev);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700678 ixgbe_receive_skb(adapter, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700679
680next_desc:
681 rx_desc->wb.upper.status_error = 0;
682
683 /* return some buffers to hardware, one at a time is too slow */
684 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
685 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
686 cleaned_count = 0;
687 }
688
689 /* use prefetched values */
690 rx_desc = next_rxd;
691 rx_buffer_info = next_buffer;
692
693 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700694 }
695
696 if (rx_ring->lro_used) {
697 lro_flush_all(&rx_ring->lro_mgr);
698 rx_ring->lro_used = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700699 }
700
701 rx_ring->next_to_clean = i;
702 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
703
704 if (cleaned_count)
705 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
706
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800707 rx_ring->total_packets += total_rx_packets;
708 rx_ring->total_bytes += total_rx_bytes;
709 adapter->net_stats.rx_bytes += total_rx_bytes;
710 adapter->net_stats.rx_packets += total_rx_packets;
711
Auke Kok9a799d72007-09-15 14:07:45 -0700712 return cleaned;
713}
714
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800715static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700716/**
717 * ixgbe_configure_msix - Configure MSI-X hardware
718 * @adapter: board private structure
719 *
720 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
721 * interrupts.
722 **/
723static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
724{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800725 struct ixgbe_q_vector *q_vector;
726 int i, j, q_vectors, v_idx, r_idx;
727 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700728
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800729 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
730
731 /* Populate the IVAR table and set the ITR values to the
732 * corresponding register.
733 */
734 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
735 q_vector = &adapter->q_vector[v_idx];
736 /* XXX for_each_bit(...) */
737 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700738 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800739
740 for (i = 0; i < q_vector->rxr_count; i++) {
741 j = adapter->rx_ring[r_idx].reg_idx;
742 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(j), v_idx);
743 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700744 adapter->num_rx_queues,
745 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800746 }
747 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700748 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800749
750 for (i = 0; i < q_vector->txr_count; i++) {
751 j = adapter->tx_ring[r_idx].reg_idx;
752 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(j), v_idx);
753 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700754 adapter->num_tx_queues,
755 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800756 }
757
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700758 /* if this is a tx only vector halve the interrupt rate */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800759 if (q_vector->txr_count && !q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700760 q_vector->eitr = (adapter->eitr_param >> 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800761 else
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700762 /* rx only */
763 q_vector->eitr = adapter->eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800764
765 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx),
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700766 EITR_INTS_PER_SEC_TO_REG(q_vector->eitr));
Auke Kok9a799d72007-09-15 14:07:45 -0700767 }
768
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800769 ixgbe_set_ivar(adapter, IXGBE_IVAR_OTHER_CAUSES_INDEX, v_idx);
770 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -0700771
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700772 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800773 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700774 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800775 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -0700776}
777
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800778enum latency_range {
779 lowest_latency = 0,
780 low_latency = 1,
781 bulk_latency = 2,
782 latency_invalid = 255
783};
784
785/**
786 * ixgbe_update_itr - update the dynamic ITR value based on statistics
787 * @adapter: pointer to adapter
788 * @eitr: eitr setting (ints per sec) to give last timeslice
789 * @itr_setting: current throttle rate in ints/second
790 * @packets: the number of packets during this measurement interval
791 * @bytes: the number of bytes during this measurement interval
792 *
793 * Stores a new ITR value based on packets and byte
794 * counts during the last interrupt. The advantage of per interrupt
795 * computation is faster updates and more accurate ITR for the current
796 * traffic pattern. Constants in this function were computed
797 * based on theoretical maximum wire speed and thresholds were set based
798 * on testing data as well as attempting to minimize response time
799 * while increasing bulk throughput.
800 * this functionality is controlled by the InterruptThrottleRate module
801 * parameter (see ixgbe_param.c)
802 **/
803static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700804 u32 eitr, u8 itr_setting,
805 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800806{
807 unsigned int retval = itr_setting;
808 u32 timepassed_us;
809 u64 bytes_perint;
810
811 if (packets == 0)
812 goto update_itr_done;
813
814
815 /* simple throttlerate management
816 * 0-20MB/s lowest (100000 ints/s)
817 * 20-100MB/s low (20000 ints/s)
818 * 100-1249MB/s bulk (8000 ints/s)
819 */
820 /* what was last interrupt timeslice? */
821 timepassed_us = 1000000/eitr;
822 bytes_perint = bytes / timepassed_us; /* bytes/usec */
823
824 switch (itr_setting) {
825 case lowest_latency:
826 if (bytes_perint > adapter->eitr_low)
827 retval = low_latency;
828 break;
829 case low_latency:
830 if (bytes_perint > adapter->eitr_high)
831 retval = bulk_latency;
832 else if (bytes_perint <= adapter->eitr_low)
833 retval = lowest_latency;
834 break;
835 case bulk_latency:
836 if (bytes_perint <= adapter->eitr_high)
837 retval = low_latency;
838 break;
839 }
840
841update_itr_done:
842 return retval;
843}
844
845static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
846{
847 struct ixgbe_adapter *adapter = q_vector->adapter;
848 struct ixgbe_hw *hw = &adapter->hw;
849 u32 new_itr;
850 u8 current_itr, ret_itr;
851 int i, r_idx, v_idx = ((void *)q_vector - (void *)(adapter->q_vector)) /
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700852 sizeof(struct ixgbe_q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800853 struct ixgbe_ring *rx_ring, *tx_ring;
854
855 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
856 for (i = 0; i < q_vector->txr_count; i++) {
857 tx_ring = &(adapter->tx_ring[r_idx]);
858 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700859 q_vector->tx_itr,
860 tx_ring->total_packets,
861 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800862 /* if the result for this queue would decrease interrupt
863 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700864 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700865 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800866 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700867 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800868 }
869
870 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
871 for (i = 0; i < q_vector->rxr_count; i++) {
872 rx_ring = &(adapter->rx_ring[r_idx]);
873 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700874 q_vector->rx_itr,
875 rx_ring->total_packets,
876 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800877 /* if the result for this queue would decrease interrupt
878 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700879 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700880 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800881 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700882 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800883 }
884
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700885 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800886
887 switch (current_itr) {
888 /* counts and packets in update_itr are dependent on these numbers */
889 case lowest_latency:
890 new_itr = 100000;
891 break;
892 case low_latency:
893 new_itr = 20000; /* aka hwitr = ~200 */
894 break;
895 case bulk_latency:
896 default:
897 new_itr = 8000;
898 break;
899 }
900
901 if (new_itr != q_vector->eitr) {
902 u32 itr_reg;
903 /* do an exponential smoothing */
904 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
905 q_vector->eitr = new_itr;
906 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
907 /* must write high and low 16 bits to reset counter */
908 DPRINTK(TX_ERR, DEBUG, "writing eitr(%d): %08X\n", v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700909 itr_reg);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800910 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg | (itr_reg)<<16);
911 }
912
913 return;
914}
915
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700916static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
917{
918 struct ixgbe_hw *hw = &adapter->hw;
919
920 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
921 (eicr & IXGBE_EICR_GPI_SDP1)) {
922 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
923 /* write to clear the interrupt */
924 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
925 }
926}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -0700927
928static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
929{
930 struct ixgbe_hw *hw = &adapter->hw;
931
932 adapter->lsc_int++;
933 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
934 adapter->link_check_timeout = jiffies;
935 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
936 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
937 schedule_work(&adapter->watchdog_task);
938 }
939}
940
Auke Kok9a799d72007-09-15 14:07:45 -0700941static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
942{
943 struct net_device *netdev = data;
944 struct ixgbe_adapter *adapter = netdev_priv(netdev);
945 struct ixgbe_hw *hw = &adapter->hw;
946 u32 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
947
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -0700948 if (eicr & IXGBE_EICR_LSC)
949 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -0800950
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700951 ixgbe_check_fan_failure(adapter, eicr);
952
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -0800953 if (!test_bit(__IXGBE_DOWN, &adapter->state))
954 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -0700955
956 return IRQ_HANDLED;
957}
958
959static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
960{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800961 struct ixgbe_q_vector *q_vector = data;
962 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700963 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800964 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -0700965
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800966 if (!q_vector->txr_count)
967 return IRQ_HANDLED;
968
969 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
970 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700971 tx_ring = &(adapter->tx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400972#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800973 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700974 ixgbe_update_tx_dca(adapter, tx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800975#endif
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700976 tx_ring->total_bytes = 0;
977 tx_ring->total_packets = 0;
978 ixgbe_clean_tx_irq(adapter, tx_ring);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800979 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700980 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800981 }
982
Auke Kok9a799d72007-09-15 14:07:45 -0700983 return IRQ_HANDLED;
984}
985
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800986/**
987 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
988 * @irq: unused
989 * @data: pointer to our q_vector struct for this interrupt vector
990 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700991static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
992{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800993 struct ixgbe_q_vector *q_vector = data;
994 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700995 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800996 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700997 int i;
Auke Kok9a799d72007-09-15 14:07:45 -0700998
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800999 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001000 for (i = 0; i < q_vector->rxr_count; i++) {
1001 rx_ring = &(adapter->rx_ring[r_idx]);
1002 rx_ring->total_bytes = 0;
1003 rx_ring->total_packets = 0;
1004 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1005 r_idx + 1);
1006 }
1007
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001008 if (!q_vector->rxr_count)
1009 return IRQ_HANDLED;
1010
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001011 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001012 rx_ring = &(adapter->rx_ring[r_idx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001013 /* disable interrupts on this vector only */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001014 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rx_ring->v_idx);
Neil Horman908a7a12008-12-22 20:43:12 -08001015 netif_rx_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001016
Auke Kok9a799d72007-09-15 14:07:45 -07001017 return IRQ_HANDLED;
1018}
1019
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001020static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1021{
1022 ixgbe_msix_clean_rx(irq, data);
1023 ixgbe_msix_clean_tx(irq, data);
1024
1025 return IRQ_HANDLED;
1026}
1027
1028/**
1029 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1030 * @napi: napi struct with our devices info in it
1031 * @budget: amount of work driver is allowed to do this pass, in packets
1032 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001033 * This function is optimized for cleaning one queue only on a single
1034 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001035 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001036static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1037{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001038 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001039 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001040 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001041 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001042 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001043 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001044
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001045 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001046 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001047#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001048 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001049 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001050#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001051
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001052 ixgbe_clean_rx_irq(adapter, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001053
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001054 /* If all Rx work done, exit the polling mode */
1055 if (work_done < budget) {
Neil Horman908a7a12008-12-22 20:43:12 -08001056 netif_rx_complete(napi);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001057 if (adapter->itr_setting & 3)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001058 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001059 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001060 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rx_ring->v_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07001061 }
1062
1063 return work_done;
1064}
1065
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001066/**
1067 * ixgbe_clean_rxonly_many - msix (aka one shot) rx clean routine
1068 * @napi: napi struct with our devices info in it
1069 * @budget: amount of work driver is allowed to do this pass, in packets
1070 *
1071 * This function will clean more than one rx queue associated with a
1072 * q_vector.
1073 **/
1074static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget)
1075{
1076 struct ixgbe_q_vector *q_vector =
1077 container_of(napi, struct ixgbe_q_vector, napi);
1078 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001079 struct ixgbe_ring *rx_ring = NULL;
1080 int work_done = 0, i;
1081 long r_idx;
1082 u16 enable_mask = 0;
1083
1084 /* attempt to distribute budget to each queue fairly, but don't allow
1085 * the budget to go below 1 because we'll exit polling */
1086 budget /= (q_vector->rxr_count ?: 1);
1087 budget = max(budget, 1);
1088 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1089 for (i = 0; i < q_vector->rxr_count; i++) {
1090 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001091#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001092 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1093 ixgbe_update_rx_dca(adapter, rx_ring);
1094#endif
1095 ixgbe_clean_rx_irq(adapter, rx_ring, &work_done, budget);
1096 enable_mask |= rx_ring->v_idx;
1097 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1098 r_idx + 1);
1099 }
1100
1101 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1102 rx_ring = &(adapter->rx_ring[r_idx]);
1103 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001104 if (work_done < budget) {
Neil Horman908a7a12008-12-22 20:43:12 -08001105 netif_rx_complete(napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001106 if (adapter->itr_setting & 3)
1107 ixgbe_set_itr_msix(q_vector);
1108 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1109 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, enable_mask);
1110 return 0;
1111 }
1112
1113 return work_done;
1114}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001115static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001116 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001117{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001118 a->q_vector[v_idx].adapter = a;
1119 set_bit(r_idx, a->q_vector[v_idx].rxr_idx);
1120 a->q_vector[v_idx].rxr_count++;
1121 a->rx_ring[r_idx].v_idx = 1 << v_idx;
1122}
Auke Kok9a799d72007-09-15 14:07:45 -07001123
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001124static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001125 int r_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001126{
1127 a->q_vector[v_idx].adapter = a;
1128 set_bit(r_idx, a->q_vector[v_idx].txr_idx);
1129 a->q_vector[v_idx].txr_count++;
1130 a->tx_ring[r_idx].v_idx = 1 << v_idx;
1131}
Auke Kok9a799d72007-09-15 14:07:45 -07001132
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001133/**
1134 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1135 * @adapter: board private structure to initialize
1136 * @vectors: allotted vector count for descriptor rings
1137 *
1138 * This function maps descriptor rings to the queue-specific vectors
1139 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1140 * one vector per ring/queue, but on a constrained vector budget, we
1141 * group the rings as "efficiently" as possible. You would add new
1142 * mapping configurations in here.
1143 **/
1144static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001145 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001146{
1147 int v_start = 0;
1148 int rxr_idx = 0, txr_idx = 0;
1149 int rxr_remaining = adapter->num_rx_queues;
1150 int txr_remaining = adapter->num_tx_queues;
1151 int i, j;
1152 int rqpv, tqpv;
1153 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001154
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001155 /* No mapping required if MSI-X is disabled. */
1156 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001157 goto out;
1158
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001159 /*
1160 * The ideal configuration...
1161 * We have enough vectors to map one per queue.
1162 */
1163 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1164 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1165 map_vector_to_rxq(adapter, v_start, rxr_idx);
1166
1167 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1168 map_vector_to_txq(adapter, v_start, txr_idx);
1169
1170 goto out;
1171 }
1172
1173 /*
1174 * If we don't have enough vectors for a 1-to-1
1175 * mapping, we'll have to group them so there are
1176 * multiple queues per vector.
1177 */
1178 /* Re-adjusting *qpv takes care of the remainder. */
1179 for (i = v_start; i < vectors; i++) {
1180 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1181 for (j = 0; j < rqpv; j++) {
1182 map_vector_to_rxq(adapter, i, rxr_idx);
1183 rxr_idx++;
1184 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001185 }
Auke Kok9a799d72007-09-15 14:07:45 -07001186 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001187 for (i = v_start; i < vectors; i++) {
1188 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1189 for (j = 0; j < tqpv; j++) {
1190 map_vector_to_txq(adapter, i, txr_idx);
1191 txr_idx++;
1192 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001193 }
Auke Kok9a799d72007-09-15 14:07:45 -07001194 }
1195
Auke Kok9a799d72007-09-15 14:07:45 -07001196out:
Auke Kok9a799d72007-09-15 14:07:45 -07001197 return err;
1198}
1199
1200/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001201 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1202 * @adapter: board private structure
1203 *
1204 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1205 * interrupts from the kernel.
1206 **/
1207static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1208{
1209 struct net_device *netdev = adapter->netdev;
1210 irqreturn_t (*handler)(int, void *);
1211 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001212 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001213
1214 /* Decrement for Other and TCP Timer vectors */
1215 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1216
1217 /* Map the Tx/Rx rings to the vectors we were allotted. */
1218 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1219 if (err)
1220 goto out;
1221
1222#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001223 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1224 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001225 for (vector = 0; vector < q_vectors; vector++) {
1226 handler = SET_HANDLER(&adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001227
1228 if(handler == &ixgbe_msix_clean_rx) {
1229 sprintf(adapter->name[vector], "%s-%s-%d",
1230 netdev->name, "rx", ri++);
1231 }
1232 else if(handler == &ixgbe_msix_clean_tx) {
1233 sprintf(adapter->name[vector], "%s-%s-%d",
1234 netdev->name, "tx", ti++);
1235 }
1236 else
1237 sprintf(adapter->name[vector], "%s-%s-%d",
1238 netdev->name, "TxRx", vector);
1239
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001240 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001241 handler, 0, adapter->name[vector],
1242 &(adapter->q_vector[vector]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001243 if (err) {
1244 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001245 "request_irq failed for MSIX interrupt "
1246 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001247 goto free_queue_irqs;
1248 }
1249 }
1250
1251 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1252 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001253 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001254 if (err) {
1255 DPRINTK(PROBE, ERR,
1256 "request_irq for msix_lsc failed: %d\n", err);
1257 goto free_queue_irqs;
1258 }
1259
1260 return 0;
1261
1262free_queue_irqs:
1263 for (i = vector - 1; i >= 0; i--)
1264 free_irq(adapter->msix_entries[--vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001265 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001266 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1267 pci_disable_msix(adapter->pdev);
1268 kfree(adapter->msix_entries);
1269 adapter->msix_entries = NULL;
1270out:
1271 return err;
1272}
1273
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001274static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1275{
1276 struct ixgbe_hw *hw = &adapter->hw;
1277 struct ixgbe_q_vector *q_vector = adapter->q_vector;
1278 u8 current_itr;
1279 u32 new_itr = q_vector->eitr;
1280 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1281 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1282
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001283 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001284 q_vector->tx_itr,
1285 tx_ring->total_packets,
1286 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001287 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001288 q_vector->rx_itr,
1289 rx_ring->total_packets,
1290 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001291
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001292 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001293
1294 switch (current_itr) {
1295 /* counts and packets in update_itr are dependent on these numbers */
1296 case lowest_latency:
1297 new_itr = 100000;
1298 break;
1299 case low_latency:
1300 new_itr = 20000; /* aka hwitr = ~200 */
1301 break;
1302 case bulk_latency:
1303 new_itr = 8000;
1304 break;
1305 default:
1306 break;
1307 }
1308
1309 if (new_itr != q_vector->eitr) {
1310 u32 itr_reg;
1311 /* do an exponential smoothing */
1312 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
1313 q_vector->eitr = new_itr;
1314 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
1315 /* must write high and low 16 bits to reset counter */
1316 IXGBE_WRITE_REG(hw, IXGBE_EITR(0), itr_reg | (itr_reg)<<16);
1317 }
1318
1319 return;
1320}
1321
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001322/**
1323 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1324 * @adapter: board private structure
1325 **/
1326static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1327{
1328 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1329 IXGBE_WRITE_FLUSH(&adapter->hw);
1330 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1331 int i;
1332 for (i = 0; i < adapter->num_msix_vectors; i++)
1333 synchronize_irq(adapter->msix_entries[i].vector);
1334 } else {
1335 synchronize_irq(adapter->pdev->irq);
1336 }
1337}
1338
1339/**
1340 * ixgbe_irq_enable - Enable default interrupt generation settings
1341 * @adapter: board private structure
1342 **/
1343static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1344{
1345 u32 mask;
1346 mask = IXGBE_EIMS_ENABLE_MASK;
David S. Miller6ab33d52008-11-20 16:44:00 -08001347 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1348 mask |= IXGBE_EIMS_GPI_SDP1;
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001349 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1350 IXGBE_WRITE_FLUSH(&adapter->hw);
1351}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001352
1353/**
1354 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001355 * @irq: interrupt number
1356 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001357 **/
1358static irqreturn_t ixgbe_intr(int irq, void *data)
1359{
1360 struct net_device *netdev = data;
1361 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1362 struct ixgbe_hw *hw = &adapter->hw;
1363 u32 eicr;
1364
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001365 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1366 * therefore no explict interrupt disable is necessary */
1367 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001368 if (!eicr) {
1369 /* shared interrupt alert!
1370 * make sure interrupts are enabled because the read will
1371 * have disabled interrupts due to EIAM */
1372 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001373 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001374 }
Auke Kok9a799d72007-09-15 14:07:45 -07001375
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001376 if (eicr & IXGBE_EICR_LSC)
1377 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001378
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001379 ixgbe_check_fan_failure(adapter, eicr);
1380
Neil Horman908a7a12008-12-22 20:43:12 -08001381 if (netif_rx_schedule_prep(&adapter->q_vector[0].napi)) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001382 adapter->tx_ring[0].total_packets = 0;
1383 adapter->tx_ring[0].total_bytes = 0;
1384 adapter->rx_ring[0].total_packets = 0;
1385 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001386 /* would disable interrupts here but EIAM disabled it */
Neil Horman908a7a12008-12-22 20:43:12 -08001387 __netif_rx_schedule(&adapter->q_vector[0].napi);
Auke Kok9a799d72007-09-15 14:07:45 -07001388 }
1389
1390 return IRQ_HANDLED;
1391}
1392
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001393static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1394{
1395 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1396
1397 for (i = 0; i < q_vectors; i++) {
1398 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
1399 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1400 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1401 q_vector->rxr_count = 0;
1402 q_vector->txr_count = 0;
1403 }
1404}
1405
Auke Kok9a799d72007-09-15 14:07:45 -07001406/**
1407 * ixgbe_request_irq - initialize interrupts
1408 * @adapter: board private structure
1409 *
1410 * Attempts to configure interrupts using the best available
1411 * capabilities of the hardware and kernel.
1412 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001413static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001414{
1415 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001416 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001417
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001418 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1419 err = ixgbe_request_msix_irqs(adapter);
1420 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1421 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001422 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001423 } else {
1424 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001425 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001426 }
1427
Auke Kok9a799d72007-09-15 14:07:45 -07001428 if (err)
1429 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1430
Auke Kok9a799d72007-09-15 14:07:45 -07001431 return err;
1432}
1433
1434static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1435{
1436 struct net_device *netdev = adapter->netdev;
1437
1438 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001439 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001440
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001441 q_vectors = adapter->num_msix_vectors;
1442
1443 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001444 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001445
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001446 i--;
1447 for (; i >= 0; i--) {
1448 free_irq(adapter->msix_entries[i].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001449 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001450 }
1451
1452 ixgbe_reset_q_vectors(adapter);
1453 } else {
1454 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001455 }
1456}
1457
1458/**
Auke Kok9a799d72007-09-15 14:07:45 -07001459 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1460 *
1461 **/
1462static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1463{
Auke Kok9a799d72007-09-15 14:07:45 -07001464 struct ixgbe_hw *hw = &adapter->hw;
1465
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001466 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001467 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001468
1469 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(0), 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001470 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(0), 0);
1471
1472 map_vector_to_rxq(adapter, 0, 0);
1473 map_vector_to_txq(adapter, 0, 0);
1474
1475 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001476}
1477
1478/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001479 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001480 * @adapter: board private structure
1481 *
1482 * Configure the Tx unit of the MAC after a reset.
1483 **/
1484static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1485{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001486 u64 tdba, tdwba;
Auke Kok9a799d72007-09-15 14:07:45 -07001487 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001488 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001489
1490 /* Setup the HW Tx Head and Tail descriptor pointers */
1491 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001492 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1493 j = ring->reg_idx;
1494 tdba = ring->dma;
1495 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001496 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001497 (tdba & DMA_32BIT_MASK));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001498 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001499 tdwba = ring->dma +
1500 (ring->count * sizeof(union ixgbe_adv_tx_desc));
1501 tdwba |= IXGBE_TDWBAL_HEAD_WB_ENABLE;
1502 IXGBE_WRITE_REG(hw, IXGBE_TDWBAL(j), tdwba & DMA_32BIT_MASK);
1503 IXGBE_WRITE_REG(hw, IXGBE_TDWBAH(j), (tdwba >> 32));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001504 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1505 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1506 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1507 adapter->tx_ring[i].head = IXGBE_TDH(j);
1508 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1509 /* Disable Tx Head Writeback RO bit, since this hoses
1510 * bookkeeping if things aren't delivered in order.
1511 */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001512 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001513 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001514 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001515 }
Auke Kok9a799d72007-09-15 14:07:45 -07001516}
1517
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001518#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07001519
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001520static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1521{
1522 struct ixgbe_ring *rx_ring;
1523 u32 srrctl;
1524 int queue0;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001525 unsigned long mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001526
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001527 /* program one srrctl register per VMDq index */
1528 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
1529 long shift, len;
1530 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1531 len = sizeof(adapter->ring_feature[RING_F_VMDQ].mask) * 8;
1532 shift = find_first_bit(&mask, len);
1533 queue0 = index & mask;
1534 index = (index & mask) >> shift;
1535 /* program one srrctl per RSS queue since RDRXCTL.MVMEN is enabled */
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001536 } else {
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001537 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1538 queue0 = index & mask;
1539 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001540 }
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001541
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001542 rx_ring = &adapter->rx_ring[queue0];
1543
1544 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1545
1546 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1547 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1548
1549 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1550 srrctl |= IXGBE_RXBUFFER_2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1551 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1552 srrctl |= ((IXGBE_RX_HDR_SIZE <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001553 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1554 IXGBE_SRRCTL_BSIZEHDR_MASK);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001555 } else {
1556 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1557
1558 if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1559 srrctl |= IXGBE_RXBUFFER_2048 >>
1560 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1561 else
1562 srrctl |= rx_ring->rx_buf_len >>
1563 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1564 }
1565 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1566}
1567
Auke Kok9a799d72007-09-15 14:07:45 -07001568/**
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001569 * ixgbe_get_skb_hdr - helper function for LRO header processing
1570 * @skb: pointer to sk_buff to be added to LRO packet
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001571 * @iphdr: pointer to ip header structure
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001572 * @tcph: pointer to tcp header structure
1573 * @hdr_flags: pointer to header flags
1574 * @priv: private data
1575 **/
1576static int ixgbe_get_skb_hdr(struct sk_buff *skb, void **iphdr, void **tcph,
1577 u64 *hdr_flags, void *priv)
1578{
1579 union ixgbe_adv_rx_desc *rx_desc = priv;
1580
1581 /* Verify that this is a valid IPv4 TCP packet */
Jesse Brandeburge9990a92008-08-26 04:27:24 -07001582 if (!((ixgbe_get_pkt_info(rx_desc) & IXGBE_RXDADV_PKTTYPE_IPV4) &&
1583 (ixgbe_get_pkt_info(rx_desc) & IXGBE_RXDADV_PKTTYPE_TCP)))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001584 return -1;
1585
1586 /* Set network headers */
1587 skb_reset_network_header(skb);
1588 skb_set_transport_header(skb, ip_hdrlen(skb));
1589 *iphdr = ip_hdr(skb);
1590 *tcph = tcp_hdr(skb);
1591 *hdr_flags = LRO_IPV4 | LRO_TCP;
1592 return 0;
1593}
1594
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001595#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001596 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001597
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001598/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001599 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001600 * @adapter: board private structure
1601 *
1602 * Configure the Rx unit of the MAC after a reset.
1603 **/
1604static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1605{
1606 u64 rdba;
1607 struct ixgbe_hw *hw = &adapter->hw;
1608 struct net_device *netdev = adapter->netdev;
1609 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001610 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001611 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001612 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1613 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1614 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001615 u32 fctrl, hlreg0;
Auke Kok9a799d72007-09-15 14:07:45 -07001616 u32 pages;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001617 u32 reta = 0, mrqc;
1618 u32 rdrxctl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001619 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07001620
1621 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001622 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07001623
1624 /* Set the RX buffer length according to the mode */
1625 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001626 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001627 } else {
1628 if (netdev->mtu <= ETH_DATA_LEN)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001629 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001630 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001631 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07001632 }
1633
1634 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1635 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001636 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
Auke Kok9a799d72007-09-15 14:07:45 -07001637 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1638
1639 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1640 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1641 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1642 else
1643 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1644 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1645
1646 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1647
Auke Kok9a799d72007-09-15 14:07:45 -07001648 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1649 /* disable receives while setting up the descriptors */
1650 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1651 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1652
1653 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1654 * the Base and Length of the Rx Descriptor Ring */
1655 for (i = 0; i < adapter->num_rx_queues; i++) {
1656 rdba = adapter->rx_ring[i].dma;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001657 j = adapter->rx_ring[i].reg_idx;
1658 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_32BIT_MASK));
1659 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
1660 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
1661 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
1662 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
1663 adapter->rx_ring[i].head = IXGBE_RDH(j);
1664 adapter->rx_ring[i].tail = IXGBE_RDT(j);
1665 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
Jesse Brandeburge9990a92008-08-26 04:27:24 -07001666 /* Intitial LRO Settings */
1667 adapter->rx_ring[i].lro_mgr.max_aggr = IXGBE_MAX_LRO_AGGREGATE;
1668 adapter->rx_ring[i].lro_mgr.max_desc = IXGBE_MAX_LRO_DESCRIPTORS;
1669 adapter->rx_ring[i].lro_mgr.get_skb_header = ixgbe_get_skb_hdr;
1670 adapter->rx_ring[i].lro_mgr.features = LRO_F_EXTRACT_VLAN_ID;
1671 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1672 adapter->rx_ring[i].lro_mgr.features |= LRO_F_NAPI;
1673 adapter->rx_ring[i].lro_mgr.dev = adapter->netdev;
1674 adapter->rx_ring[i].lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1675 adapter->rx_ring[i].lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001676
1677 ixgbe_configure_srrctl(adapter, j);
Auke Kok9a799d72007-09-15 14:07:45 -07001678 }
1679
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001680 /*
1681 * For VMDq support of different descriptor types or
1682 * buffer sizes through the use of multiple SRRCTL
1683 * registers, RDRXCTL.MVMEN must be set to 1
1684 *
1685 * also, the manual doesn't mention it clearly but DCA hints
1686 * will only use queue 0's tags unless this bit is set. Side
1687 * effects of setting this bit are only that SRRCTL must be
1688 * fully programmed [0..15]
1689 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08001690 if (adapter->flags &
1691 (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_VMDQ_ENABLED)) {
1692 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1693 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
1694 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
1695 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001696
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001697 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07001698 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001699 for (i = 0, j = 0; i < 128; i++, j++) {
1700 if (j == adapter->ring_feature[RING_F_RSS].indices)
1701 j = 0;
1702 /* reta = 4-byte sliding window of
1703 * 0x00..(indices-1)(indices-1)00..etc. */
1704 reta = (reta << 8) | (j * 0x11);
1705 if ((i & 3) == 3)
1706 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07001707 }
1708
1709 /* Fill out hash function seeds */
1710 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001711 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07001712
1713 mrqc = IXGBE_MRQC_RSSEN
1714 /* Perform hash on these packet types */
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001715 | IXGBE_MRQC_RSS_FIELD_IPV4
1716 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1717 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1718 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
1719 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
1720 | IXGBE_MRQC_RSS_FIELD_IPV6
1721 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1722 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
1723 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07001724 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Auke Kok9a799d72007-09-15 14:07:45 -07001725 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001726
1727 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1728
1729 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
1730 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
1731 /* Disable indicating checksum in descriptor, enables
1732 * RSS hash */
1733 rxcsum |= IXGBE_RXCSUM_PCSD;
1734 }
1735 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
1736 /* Enable IPv4 payload checksum for UDP fragments
1737 * if PCSD is not set */
1738 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1739 }
1740
1741 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
Auke Kok9a799d72007-09-15 14:07:45 -07001742}
1743
1744static void ixgbe_vlan_rx_register(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001745 struct vlan_group *grp)
Auke Kok9a799d72007-09-15 14:07:45 -07001746{
1747 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1748 u32 ctrl;
1749
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001750 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1751 ixgbe_irq_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001752 adapter->vlgrp = grp;
1753
Alexander Duyck2f90b862008-11-20 20:52:10 -08001754 /*
1755 * For a DCB driver, always enable VLAN tag stripping so we can
1756 * still receive traffic from a DCB-enabled host even if we're
1757 * not in DCB mode.
1758 */
1759 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1760 ctrl |= IXGBE_VLNCTRL_VME;
1761 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1762 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1763
Auke Kok9a799d72007-09-15 14:07:45 -07001764 if (grp) {
1765 /* enable VLAN tag insert/strip */
1766 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
Patrick McHardy746b9f02008-07-16 20:15:45 -07001767 ctrl |= IXGBE_VLNCTRL_VME;
Auke Kok9a799d72007-09-15 14:07:45 -07001768 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1769 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1770 }
1771
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001772 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1773 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001774}
1775
1776static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1777{
1778 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001779 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001780
1781 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001782 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07001783}
1784
1785static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1786{
1787 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001788 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001789
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001790 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1791 ixgbe_irq_disable(adapter);
1792
Auke Kok9a799d72007-09-15 14:07:45 -07001793 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001794
1795 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1796 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001797
1798 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001799 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07001800}
1801
1802static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
1803{
1804 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1805
1806 if (adapter->vlgrp) {
1807 u16 vid;
1808 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1809 if (!vlan_group_get_device(adapter->vlgrp, vid))
1810 continue;
1811 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
1812 }
1813 }
1814}
1815
Christopher Leech2c5645c2008-08-26 04:27:02 -07001816static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
1817{
1818 struct dev_mc_list *mc_ptr;
1819 u8 *addr = *mc_addr_ptr;
1820 *vmdq = 0;
1821
1822 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
1823 if (mc_ptr->next)
1824 *mc_addr_ptr = mc_ptr->next->dmi_addr;
1825 else
1826 *mc_addr_ptr = NULL;
1827
1828 return addr;
1829}
1830
Auke Kok9a799d72007-09-15 14:07:45 -07001831/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07001832 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07001833 * @netdev: network interface device structure
1834 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07001835 * The set_rx_method entry point is called whenever the unicast/multicast
1836 * address list or the network interface flags are updated. This routine is
1837 * responsible for configuring the hardware for proper unicast, multicast and
1838 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07001839 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07001840static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001841{
1842 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1843 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07001844 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001845 u8 *addr_list = NULL;
1846 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001847
1848 /* Check for Promiscuous and All Multicast modes */
1849
1850 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07001851 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07001852
1853 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07001854 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001855 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07001856 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07001857 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07001858 if (netdev->flags & IFF_ALLMULTI) {
1859 fctrl |= IXGBE_FCTRL_MPE;
1860 fctrl &= ~IXGBE_FCTRL_UPE;
1861 } else {
1862 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1863 }
Alexander Duyck3d016252008-08-26 18:30:04 -07001864 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001865 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001866 }
1867
1868 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07001869 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001870
Christopher Leech2c5645c2008-08-26 04:27:02 -07001871 /* reprogram secondary unicast list */
1872 addr_count = netdev->uc_count;
1873 if (addr_count)
1874 addr_list = netdev->uc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001875 hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count,
1876 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07001877
Christopher Leech2c5645c2008-08-26 04:27:02 -07001878 /* reprogram multicast list */
1879 addr_count = netdev->mc_count;
1880 if (addr_count)
1881 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001882 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
1883 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07001884}
1885
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001886static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
1887{
1888 int q_idx;
1889 struct ixgbe_q_vector *q_vector;
1890 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1891
1892 /* legacy and MSI only use one vector */
1893 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1894 q_vectors = 1;
1895
1896 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001897 struct napi_struct *napi;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001898 q_vector = &adapter->q_vector[q_idx];
1899 if (!q_vector->rxr_count)
1900 continue;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001901 napi = &q_vector->napi;
1902 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) &&
1903 (q_vector->rxr_count > 1))
1904 napi->poll = &ixgbe_clean_rxonly_many;
1905
1906 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001907 }
1908}
1909
1910static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
1911{
1912 int q_idx;
1913 struct ixgbe_q_vector *q_vector;
1914 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1915
1916 /* legacy and MSI only use one vector */
1917 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1918 q_vectors = 1;
1919
1920 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1921 q_vector = &adapter->q_vector[q_idx];
1922 if (!q_vector->rxr_count)
1923 continue;
1924 napi_disable(&q_vector->napi);
1925 }
1926}
1927
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08001928#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08001929/*
1930 * ixgbe_configure_dcb - Configure DCB hardware
1931 * @adapter: ixgbe adapter struct
1932 *
1933 * This is called by the driver on open to configure the DCB hardware.
1934 * This is also called by the gennetlink interface when reconfiguring
1935 * the DCB state.
1936 */
1937static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
1938{
1939 struct ixgbe_hw *hw = &adapter->hw;
1940 u32 txdctl, vlnctrl;
1941 int i, j;
1942
1943 ixgbe_dcb_check_config(&adapter->dcb_cfg);
1944 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
1945 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
1946
1947 /* reconfigure the hardware */
1948 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
1949
1950 for (i = 0; i < adapter->num_tx_queues; i++) {
1951 j = adapter->tx_ring[i].reg_idx;
1952 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
1953 /* PThresh workaround for Tx hang with DFP enabled. */
1954 txdctl |= 32;
1955 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
1956 }
1957 /* Enable VLAN tag insert/strip */
1958 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1959 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
1960 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
1961 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1962 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
1963}
1964
1965#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001966static void ixgbe_configure(struct ixgbe_adapter *adapter)
1967{
1968 struct net_device *netdev = adapter->netdev;
1969 int i;
1970
Christopher Leech2c5645c2008-08-26 04:27:02 -07001971 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001972
1973 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08001974#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08001975 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
1976 netif_set_gso_max_size(netdev, 32768);
1977 ixgbe_configure_dcb(adapter);
1978 } else {
1979 netif_set_gso_max_size(netdev, 65536);
1980 }
1981#else
1982 netif_set_gso_max_size(netdev, 65536);
1983#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001984
1985 ixgbe_configure_tx(adapter);
1986 ixgbe_configure_rx(adapter);
1987 for (i = 0; i < adapter->num_rx_queues; i++)
1988 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001989 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07001990}
1991
1992static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
1993{
1994 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07001995 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001996 int i, j = 0;
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
2077 /* bring the link up in the watchdog, this could race with our first
2078 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002079 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2080 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002081 mod_timer(&adapter->watchdog_timer, jiffies);
2082 return 0;
2083}
2084
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002085void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2086{
2087 WARN_ON(in_interrupt());
2088 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2089 msleep(1);
2090 ixgbe_down(adapter);
2091 ixgbe_up(adapter);
2092 clear_bit(__IXGBE_RESETTING, &adapter->state);
2093}
2094
Auke Kok9a799d72007-09-15 14:07:45 -07002095int ixgbe_up(struct ixgbe_adapter *adapter)
2096{
2097 /* hardware has been reset, we need to reload some things */
2098 ixgbe_configure(adapter);
2099
2100 return ixgbe_up_complete(adapter);
2101}
2102
2103void ixgbe_reset(struct ixgbe_adapter *adapter)
2104{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002105 struct ixgbe_hw *hw = &adapter->hw;
2106 if (hw->mac.ops.init_hw(hw))
2107 dev_err(&adapter->pdev->dev, "Hardware Error\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002108
2109 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002110 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002111
2112}
2113
Auke Kok9a799d72007-09-15 14:07:45 -07002114/**
2115 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2116 * @adapter: board private structure
2117 * @rx_ring: ring to free buffers from
2118 **/
2119static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002120 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002121{
2122 struct pci_dev *pdev = adapter->pdev;
2123 unsigned long size;
2124 unsigned int i;
2125
2126 /* Free all the Rx ring sk_buffs */
2127
2128 for (i = 0; i < rx_ring->count; i++) {
2129 struct ixgbe_rx_buffer *rx_buffer_info;
2130
2131 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2132 if (rx_buffer_info->dma) {
2133 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002134 rx_ring->rx_buf_len,
2135 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002136 rx_buffer_info->dma = 0;
2137 }
2138 if (rx_buffer_info->skb) {
2139 dev_kfree_skb(rx_buffer_info->skb);
2140 rx_buffer_info->skb = NULL;
2141 }
2142 if (!rx_buffer_info->page)
2143 continue;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002144 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2145 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002146 rx_buffer_info->page_dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002147 put_page(rx_buffer_info->page);
2148 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002149 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002150 }
2151
2152 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2153 memset(rx_ring->rx_buffer_info, 0, size);
2154
2155 /* Zero out the descriptor ring */
2156 memset(rx_ring->desc, 0, rx_ring->size);
2157
2158 rx_ring->next_to_clean = 0;
2159 rx_ring->next_to_use = 0;
2160
2161 writel(0, adapter->hw.hw_addr + rx_ring->head);
2162 writel(0, adapter->hw.hw_addr + rx_ring->tail);
2163}
2164
2165/**
2166 * ixgbe_clean_tx_ring - Free Tx Buffers
2167 * @adapter: board private structure
2168 * @tx_ring: ring to be cleaned
2169 **/
2170static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002171 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002172{
2173 struct ixgbe_tx_buffer *tx_buffer_info;
2174 unsigned long size;
2175 unsigned int i;
2176
2177 /* Free all the Tx ring sk_buffs */
2178
2179 for (i = 0; i < tx_ring->count; i++) {
2180 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2181 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2182 }
2183
2184 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2185 memset(tx_ring->tx_buffer_info, 0, size);
2186
2187 /* Zero out the descriptor ring */
2188 memset(tx_ring->desc, 0, tx_ring->size);
2189
2190 tx_ring->next_to_use = 0;
2191 tx_ring->next_to_clean = 0;
2192
2193 writel(0, adapter->hw.hw_addr + tx_ring->head);
2194 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2195}
2196
2197/**
Auke Kok9a799d72007-09-15 14:07:45 -07002198 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2199 * @adapter: board private structure
2200 **/
2201static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2202{
2203 int i;
2204
2205 for (i = 0; i < adapter->num_rx_queues; i++)
2206 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2207}
2208
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002209/**
2210 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2211 * @adapter: board private structure
2212 **/
2213static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2214{
2215 int i;
2216
2217 for (i = 0; i < adapter->num_tx_queues; i++)
2218 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2219}
2220
Auke Kok9a799d72007-09-15 14:07:45 -07002221void ixgbe_down(struct ixgbe_adapter *adapter)
2222{
2223 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002224 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002225 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002226 u32 txdctl;
2227 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002228
2229 /* signal that we are down to the interrupt handler */
2230 set_bit(__IXGBE_DOWN, &adapter->state);
2231
2232 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002233 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2234 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002235
2236 netif_tx_disable(netdev);
2237
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002238 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002239 msleep(10);
2240
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002241 netif_tx_stop_all_queues(netdev);
2242
Auke Kok9a799d72007-09-15 14:07:45 -07002243 ixgbe_irq_disable(adapter);
2244
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002245 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002246
Auke Kok9a799d72007-09-15 14:07:45 -07002247 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002248 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002249
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002250 /* disable transmits in the hardware now that interrupts are off */
2251 for (i = 0; i < adapter->num_tx_queues; i++) {
2252 j = adapter->tx_ring[i].reg_idx;
2253 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2254 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2255 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2256 }
2257
Auke Kok9a799d72007-09-15 14:07:45 -07002258 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002259
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002260#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002261 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2262 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
2263 dca_remove_requester(&adapter->pdev->dev);
2264 }
2265
2266#endif
Paul Larson6f4a0e42008-06-24 17:00:56 -07002267 if (!pci_channel_offline(adapter->pdev))
2268 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002269 ixgbe_clean_all_tx_rings(adapter);
2270 ixgbe_clean_all_rx_rings(adapter);
2271
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002272#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002273 /* since we reset the hardware DCA settings were cleared */
2274 if (dca_add_requester(&adapter->pdev->dev) == 0) {
2275 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
2276 /* always use CB2 mode, difference is masked
2277 * in the CB driver */
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002278 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002279 ixgbe_setup_dca(adapter);
2280 }
2281#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002282}
2283
Auke Kok9a799d72007-09-15 14:07:45 -07002284/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002285 * ixgbe_poll - NAPI Rx polling callback
2286 * @napi: structure for representing this polling device
2287 * @budget: how many packets driver is allowed to clean
2288 *
2289 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002290 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002291static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002292{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002293 struct ixgbe_q_vector *q_vector = container_of(napi,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002294 struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002295 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -07002296 int tx_cleaned, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002297
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002298#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002299 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2300 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2301 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2302 }
2303#endif
2304
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002305 tx_cleaned = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002306 ixgbe_clean_rx_irq(adapter, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002307
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002308 if (tx_cleaned)
2309 work_done = budget;
2310
David S. Miller53e52c72008-01-07 21:06:12 -08002311 /* If budget not fully consumed, exit the polling mode */
2312 if (work_done < budget) {
Neil Horman908a7a12008-12-22 20:43:12 -08002313 netif_rx_complete(napi);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002314 if (adapter->itr_setting & 3)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002315 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002316 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2317 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002318 }
Auke Kok9a799d72007-09-15 14:07:45 -07002319 return work_done;
2320}
2321
2322/**
2323 * ixgbe_tx_timeout - Respond to a Tx Hang
2324 * @netdev: network interface device structure
2325 **/
2326static void ixgbe_tx_timeout(struct net_device *netdev)
2327{
2328 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2329
2330 /* Do the reset outside of interrupt context */
2331 schedule_work(&adapter->reset_task);
2332}
2333
2334static void ixgbe_reset_task(struct work_struct *work)
2335{
2336 struct ixgbe_adapter *adapter;
2337 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2338
Alexander Duyck2f90b862008-11-20 20:52:10 -08002339 /* If we're already down or resetting, just bail */
2340 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2341 test_bit(__IXGBE_RESETTING, &adapter->state))
2342 return;
2343
Auke Kok9a799d72007-09-15 14:07:45 -07002344 adapter->tx_timeout_count++;
2345
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002346 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002347}
2348
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002349static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2350{
2351 int nrq = 1, ntq = 1;
2352 int feature_mask = 0, rss_i, rss_m;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002353 int dcb_i, dcb_m;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002354
2355 /* Number of supported queues */
2356 switch (adapter->hw.mac.type) {
2357 case ixgbe_mac_82598EB:
Alexander Duyck2f90b862008-11-20 20:52:10 -08002358 dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2359 dcb_m = 0;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002360 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2361 rss_m = 0;
2362 feature_mask |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002363 feature_mask |= IXGBE_FLAG_DCB_ENABLED;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002364
2365 switch (adapter->flags & feature_mask) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002366 case (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_DCB_ENABLED):
2367 dcb_m = 0x7 << 3;
2368 rss_i = min(8, rss_i);
2369 rss_m = 0x7;
2370 nrq = dcb_i * rss_i;
2371 ntq = min(MAX_TX_QUEUES, dcb_i * rss_i);
2372 break;
2373 case (IXGBE_FLAG_DCB_ENABLED):
2374 dcb_m = 0x7 << 3;
2375 nrq = dcb_i;
2376 ntq = dcb_i;
2377 break;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002378 case (IXGBE_FLAG_RSS_ENABLED):
2379 rss_m = 0xF;
2380 nrq = rss_i;
2381 ntq = rss_i;
2382 break;
2383 case 0:
2384 default:
Alexander Duyck2f90b862008-11-20 20:52:10 -08002385 dcb_i = 0;
2386 dcb_m = 0;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002387 rss_i = 0;
2388 rss_m = 0;
2389 nrq = 1;
2390 ntq = 1;
2391 break;
2392 }
2393
Alexander Duyck2f90b862008-11-20 20:52:10 -08002394 /* Sanity check, we should never have zero queues */
2395 nrq = (nrq ?:1);
2396 ntq = (ntq ?:1);
2397
2398 adapter->ring_feature[RING_F_DCB].indices = dcb_i;
2399 adapter->ring_feature[RING_F_DCB].mask = dcb_m;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002400 adapter->ring_feature[RING_F_RSS].indices = rss_i;
2401 adapter->ring_feature[RING_F_RSS].mask = rss_m;
2402 break;
2403 default:
2404 nrq = 1;
2405 ntq = 1;
2406 break;
2407 }
2408
2409 adapter->num_rx_queues = nrq;
2410 adapter->num_tx_queues = ntq;
2411}
2412
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002413static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002414 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002415{
2416 int err, vector_threshold;
2417
2418 /* We'll want at least 3 (vector_threshold):
2419 * 1) TxQ[0] Cleanup
2420 * 2) RxQ[0] Cleanup
2421 * 3) Other (Link Status Change, etc.)
2422 * 4) TCP Timer (optional)
2423 */
2424 vector_threshold = MIN_MSIX_COUNT;
2425
2426 /* The more we get, the more we will assign to Tx/Rx Cleanup
2427 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2428 * Right now, we simply care about how many we'll get; we'll
2429 * set them up later while requesting irq's.
2430 */
2431 while (vectors >= vector_threshold) {
2432 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002433 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002434 if (!err) /* Success in acquiring all requested vectors. */
2435 break;
2436 else if (err < 0)
2437 vectors = 0; /* Nasty failure, quit now */
2438 else /* err == number of vectors we should try again with */
2439 vectors = err;
2440 }
2441
2442 if (vectors < vector_threshold) {
2443 /* Can't allocate enough MSI-X interrupts? Oh well.
2444 * This just means we'll go with either a single MSI
2445 * vector or fall back to legacy interrupts.
2446 */
2447 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2448 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2449 kfree(adapter->msix_entries);
2450 adapter->msix_entries = NULL;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002451 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002452 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002453 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002454 } else {
2455 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
2456 adapter->num_msix_vectors = vectors;
2457 }
2458}
2459
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002460/**
2461 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2462 * @adapter: board private structure to initialize
2463 *
2464 * Once we know the feature-set enabled for the device, we'll cache
2465 * the register offset the descriptor ring is assigned to.
2466 **/
Al Virofeea6a52008-11-27 15:34:07 -08002467static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002468{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002469 int feature_mask = 0, rss_i;
2470 int i, txr_idx, rxr_idx;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002471 int dcb_i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002472
2473 /* Number of supported queues */
2474 switch (adapter->hw.mac.type) {
2475 case ixgbe_mac_82598EB:
Alexander Duyck2f90b862008-11-20 20:52:10 -08002476 dcb_i = adapter->ring_feature[RING_F_DCB].indices;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002477 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2478 txr_idx = 0;
2479 rxr_idx = 0;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002480 feature_mask |= IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002481 feature_mask |= IXGBE_FLAG_RSS_ENABLED;
2482 switch (adapter->flags & feature_mask) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002483 case (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_DCB_ENABLED):
2484 for (i = 0; i < dcb_i; i++) {
2485 int j;
2486 /* Rx first */
2487 for (j = 0; j < adapter->num_rx_queues; j++) {
2488 adapter->rx_ring[rxr_idx].reg_idx =
2489 i << 3 | j;
2490 rxr_idx++;
2491 }
2492 /* Tx now */
2493 for (j = 0; j < adapter->num_tx_queues; j++) {
2494 adapter->tx_ring[txr_idx].reg_idx =
2495 i << 2 | (j >> 1);
2496 if (j & 1)
2497 txr_idx++;
2498 }
2499 }
2500 case (IXGBE_FLAG_DCB_ENABLED):
2501 /* the number of queues is assumed to be symmetric */
2502 for (i = 0; i < dcb_i; i++) {
2503 adapter->rx_ring[i].reg_idx = i << 3;
2504 adapter->tx_ring[i].reg_idx = i << 2;
2505 }
2506 break;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002507 case (IXGBE_FLAG_RSS_ENABLED):
2508 for (i = 0; i < adapter->num_rx_queues; i++)
2509 adapter->rx_ring[i].reg_idx = i;
2510 for (i = 0; i < adapter->num_tx_queues; i++)
2511 adapter->tx_ring[i].reg_idx = i;
2512 break;
2513 case 0:
2514 default:
2515 break;
2516 }
2517 break;
2518 default:
2519 break;
2520 }
2521}
2522
Auke Kok9a799d72007-09-15 14:07:45 -07002523/**
2524 * ixgbe_alloc_queues - Allocate memory for all rings
2525 * @adapter: board private structure to initialize
2526 *
2527 * We allocate one ring per queue at run-time since we don't know the
Wang Chena4d2f342008-12-03 22:05:58 -08002528 * number of queues at compile-time.
Auke Kok9a799d72007-09-15 14:07:45 -07002529 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002530static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002531{
2532 int i;
2533
2534 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002535 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07002536 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002537 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07002538
2539 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002540 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002541 if (!adapter->rx_ring)
2542 goto err_rx_ring_allocation;
2543
2544 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002545 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002546 adapter->tx_ring[i].queue_index = i;
2547 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002548
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002549 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002550 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002551 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07002552 }
2553
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002554 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002555
2556 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002557
2558err_rx_ring_allocation:
2559 kfree(adapter->tx_ring);
2560err_tx_ring_allocation:
2561 return -ENOMEM;
2562}
2563
2564/**
2565 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
2566 * @adapter: board private structure to initialize
2567 *
2568 * Attempt to configure the interrupts using the best available
2569 * capabilities of the hardware and the kernel.
2570 **/
Al Virofeea6a52008-11-27 15:34:07 -08002571static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002572{
2573 int err = 0;
2574 int vector, v_budget;
2575
2576 /*
2577 * It's easy to be greedy for MSI-X vectors, but it really
2578 * doesn't do us much good if we have a lot more vectors
2579 * than CPU's. So let's be conservative and only ask for
2580 * (roughly) twice the number of vectors as there are CPU's.
2581 */
2582 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002583 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002584
2585 /*
2586 * At the same time, hardware can only support a maximum of
2587 * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq,
2588 * we can easily reach upwards of 64 Rx descriptor queues and
2589 * 32 Tx queues. Thus, we cap it off in those rare cases where
2590 * the cpu count also exceeds our vector limit.
2591 */
2592 v_budget = min(v_budget, MAX_MSIX_COUNT);
2593
2594 /* A failure in MSI-X entry allocation isn't fatal, but it does
2595 * mean we disable MSI-X capabilities of the adapter. */
2596 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002597 sizeof(struct msix_entry), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002598 if (!adapter->msix_entries) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002599 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002600 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2601 ixgbe_set_num_queues(adapter);
2602 kfree(adapter->tx_ring);
2603 kfree(adapter->rx_ring);
2604 err = ixgbe_alloc_queues(adapter);
2605 if (err) {
2606 DPRINTK(PROBE, ERR, "Unable to allocate memory "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002607 "for queues\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002608 goto out;
2609 }
2610
2611 goto try_msi;
2612 }
2613
2614 for (vector = 0; vector < v_budget; vector++)
2615 adapter->msix_entries[vector].entry = vector;
2616
2617 ixgbe_acquire_msix_vectors(adapter, v_budget);
2618
2619 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2620 goto out;
2621
2622try_msi:
2623 err = pci_enable_msi(adapter->pdev);
2624 if (!err) {
2625 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
2626 } else {
2627 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002628 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002629 /* reset err */
2630 err = 0;
2631 }
2632
2633out:
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08002634 /* Notify the stack of the (possibly) reduced Tx Queue count. */
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002635 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002636
2637 return err;
2638}
2639
Alexander Duyck2f90b862008-11-20 20:52:10 -08002640void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002641{
2642 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2643 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2644 pci_disable_msix(adapter->pdev);
2645 kfree(adapter->msix_entries);
2646 adapter->msix_entries = NULL;
2647 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2648 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
2649 pci_disable_msi(adapter->pdev);
2650 }
2651 return;
2652}
2653
2654/**
2655 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
2656 * @adapter: board private structure to initialize
2657 *
2658 * We determine which interrupt scheme to use based on...
2659 * - Kernel support (MSI, MSI-X)
2660 * - which can be user-defined (via MODULE_PARAM)
2661 * - Hardware queue count (num_*_queues)
2662 * - defined by miscellaneous hardware support/features (RSS, etc.)
2663 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002664int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002665{
2666 int err;
2667
2668 /* Number of supported queues */
2669 ixgbe_set_num_queues(adapter);
2670
2671 err = ixgbe_alloc_queues(adapter);
2672 if (err) {
2673 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
2674 goto err_alloc_queues;
2675 }
2676
2677 err = ixgbe_set_interrupt_capability(adapter);
2678 if (err) {
2679 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
2680 goto err_set_interrupt;
2681 }
2682
2683 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002684 "Tx Queue count = %u\n",
2685 (adapter->num_rx_queues > 1) ? "Enabled" :
2686 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002687
2688 set_bit(__IXGBE_DOWN, &adapter->state);
2689
2690 return 0;
2691
2692err_set_interrupt:
2693 kfree(adapter->tx_ring);
2694 kfree(adapter->rx_ring);
2695err_alloc_queues:
2696 return err;
Auke Kok9a799d72007-09-15 14:07:45 -07002697}
2698
2699/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08002700 * ixgbe_sfp_timer - worker thread to find a missing module
2701 * @data: pointer to our adapter struct
2702 **/
2703static void ixgbe_sfp_timer(unsigned long data)
2704{
2705 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
2706
2707 /* Do the sfp_timer outside of interrupt context due to the
2708 * delays that sfp+ detection requires
2709 */
2710 schedule_work(&adapter->sfp_task);
2711}
2712
2713/**
2714 * ixgbe_sfp_task - worker thread to find a missing module
2715 * @work: pointer to work_struct containing our data
2716 **/
2717static void ixgbe_sfp_task(struct work_struct *work)
2718{
2719 struct ixgbe_adapter *adapter = container_of(work,
2720 struct ixgbe_adapter,
2721 sfp_task);
2722 struct ixgbe_hw *hw = &adapter->hw;
2723
2724 if ((hw->phy.type == ixgbe_phy_nl) &&
2725 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
2726 s32 ret = hw->phy.ops.identify_sfp(hw);
2727 if (ret)
2728 goto reschedule;
2729 ret = hw->phy.ops.reset(hw);
2730 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2731 DPRINTK(PROBE, ERR, "failed to initialize because an "
2732 "unsupported SFP+ module type was detected.\n"
2733 "Reload the driver after installing a "
2734 "supported module.\n");
2735 unregister_netdev(adapter->netdev);
2736 } else {
2737 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
2738 hw->phy.sfp_type);
2739 }
2740 /* don't need this routine any more */
2741 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
2742 }
2743 return;
2744reschedule:
2745 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
2746 mod_timer(&adapter->sfp_timer,
2747 round_jiffies(jiffies + (2 * HZ)));
2748}
2749
2750/**
Auke Kok9a799d72007-09-15 14:07:45 -07002751 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
2752 * @adapter: board private structure to initialize
2753 *
2754 * ixgbe_sw_init initializes the Adapter private data structure.
2755 * Fields are initialized based on PCI device information and
2756 * OS network device settings (MTU size).
2757 **/
2758static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
2759{
2760 struct ixgbe_hw *hw = &adapter->hw;
2761 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002762 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002763#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002764 int j;
2765 struct tc_configuration *tc;
2766#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002767
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002768 /* PCI config space info */
2769
2770 hw->vendor_id = pdev->vendor;
2771 hw->device_id = pdev->device;
2772 hw->revision_id = pdev->revision;
2773 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2774 hw->subsystem_device_id = pdev->subsystem_device;
2775
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002776 /* Set capability flags */
2777 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
2778 adapter->ring_feature[RING_F_RSS].indices = rss;
2779 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002780 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
2781
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002782#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002783 /* Configure DCB traffic classes */
2784 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
2785 tc = &adapter->dcb_cfg.tc_config[j];
2786 tc->path[DCB_TX_CONFIG].bwg_id = 0;
2787 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
2788 tc->path[DCB_RX_CONFIG].bwg_id = 0;
2789 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
2790 tc->dcb_pfc = pfc_disabled;
2791 }
2792 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
2793 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
2794 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
2795 adapter->dcb_cfg.round_robin_enable = false;
2796 adapter->dcb_set_bitmap = 0x00;
2797 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
2798 adapter->ring_feature[RING_F_DCB].indices);
2799
2800#endif
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002801 if (hw->mac.ops.get_media_type &&
2802 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper))
2803 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Auke Kok9a799d72007-09-15 14:07:45 -07002804
2805 /* default flow control settings */
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07002806 hw->fc.original_type = ixgbe_fc_none;
2807 hw->fc.type = ixgbe_fc_none;
2808 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
2809 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
2810 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
2811 hw->fc.send_xon = true;
Auke Kok9a799d72007-09-15 14:07:45 -07002812
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002813 /* select 10G link by default */
Auke Kok9a799d72007-09-15 14:07:45 -07002814 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_10G_LINK_NO_AN;
Auke Kok9a799d72007-09-15 14:07:45 -07002815
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002816 /* enable itr by default in dynamic mode */
2817 adapter->itr_setting = 1;
2818 adapter->eitr_param = 20000;
2819
2820 /* set defaults for eitr in MegaBytes */
2821 adapter->eitr_low = 10;
2822 adapter->eitr_high = 20;
2823
2824 /* set default ring sizes */
2825 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
2826 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
2827
Auke Kok9a799d72007-09-15 14:07:45 -07002828 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002829 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002830 dev_err(&pdev->dev, "EEPROM initialization failed\n");
2831 return -EIO;
2832 }
2833
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002834 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07002835 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
2836
Auke Kok9a799d72007-09-15 14:07:45 -07002837 set_bit(__IXGBE_DOWN, &adapter->state);
2838
2839 return 0;
2840}
2841
2842/**
2843 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
2844 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002845 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07002846 *
2847 * Return 0 on success, negative on failure
2848 **/
2849int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002850 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002851{
2852 struct pci_dev *pdev = adapter->pdev;
2853 int size;
2854
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002855 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2856 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002857 if (!tx_ring->tx_buffer_info)
2858 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002859 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07002860
2861 /* round up to nearest 4K */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002862 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc) +
2863 sizeof(u32);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002864 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07002865
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002866 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
2867 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002868 if (!tx_ring->desc)
2869 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07002870
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002871 tx_ring->next_to_use = 0;
2872 tx_ring->next_to_clean = 0;
2873 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07002874 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002875
2876err:
2877 vfree(tx_ring->tx_buffer_info);
2878 tx_ring->tx_buffer_info = NULL;
2879 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
2880 "descriptor ring\n");
2881 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07002882}
2883
2884/**
Alexander Duyck69888672008-09-11 20:05:39 -07002885 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
2886 * @adapter: board private structure
2887 *
2888 * If this function returns with an error, then it's possible one or
2889 * more of the rings is populated (while the rest are not). It is the
2890 * callers duty to clean those orphaned rings.
2891 *
2892 * Return 0 on success, negative on failure
2893 **/
2894static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
2895{
2896 int i, err = 0;
2897
2898 for (i = 0; i < adapter->num_tx_queues; i++) {
2899 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
2900 if (!err)
2901 continue;
2902 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
2903 break;
2904 }
2905
2906 return err;
2907}
2908
2909/**
Auke Kok9a799d72007-09-15 14:07:45 -07002910 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
2911 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002912 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07002913 *
2914 * Returns 0 on success, negative on failure
2915 **/
2916int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002917 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002918{
2919 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002920 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002921
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002922 size = sizeof(struct net_lro_desc) * IXGBE_MAX_LRO_DESCRIPTORS;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002923 rx_ring->lro_mgr.lro_arr = vmalloc(size);
2924 if (!rx_ring->lro_mgr.lro_arr)
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002925 return -ENOMEM;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002926 memset(rx_ring->lro_mgr.lro_arr, 0, size);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002927
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002928 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2929 rx_ring->rx_buffer_info = vmalloc(size);
2930 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07002931 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002932 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002933 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07002934 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002935 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07002936
Auke Kok9a799d72007-09-15 14:07:45 -07002937 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002938 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
2939 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07002940
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002941 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07002942
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002943 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07002944 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002945 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002946 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002947 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07002948 }
2949
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002950 rx_ring->next_to_clean = 0;
2951 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002952
2953 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002954
2955alloc_failed:
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002956 vfree(rx_ring->lro_mgr.lro_arr);
2957 rx_ring->lro_mgr.lro_arr = NULL;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002958 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07002959}
2960
2961/**
Alexander Duyck69888672008-09-11 20:05:39 -07002962 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
2963 * @adapter: board private structure
2964 *
2965 * If this function returns with an error, then it's possible one or
2966 * more of the rings is populated (while the rest are not). It is the
2967 * callers duty to clean those orphaned rings.
2968 *
2969 * Return 0 on success, negative on failure
2970 **/
2971
2972static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
2973{
2974 int i, err = 0;
2975
2976 for (i = 0; i < adapter->num_rx_queues; i++) {
2977 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
2978 if (!err)
2979 continue;
2980 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
2981 break;
2982 }
2983
2984 return err;
2985}
2986
2987/**
Auke Kok9a799d72007-09-15 14:07:45 -07002988 * ixgbe_free_tx_resources - Free Tx Resources per Queue
2989 * @adapter: board private structure
2990 * @tx_ring: Tx descriptor ring for a specific queue
2991 *
2992 * Free all transmit software resources
2993 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07002994void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
2995 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002996{
2997 struct pci_dev *pdev = adapter->pdev;
2998
2999 ixgbe_clean_tx_ring(adapter, tx_ring);
3000
3001 vfree(tx_ring->tx_buffer_info);
3002 tx_ring->tx_buffer_info = NULL;
3003
3004 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
3005
3006 tx_ring->desc = NULL;
3007}
3008
3009/**
3010 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
3011 * @adapter: board private structure
3012 *
3013 * Free all transmit software resources
3014 **/
3015static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
3016{
3017 int i;
3018
3019 for (i = 0; i < adapter->num_tx_queues; i++)
3020 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
3021}
3022
3023/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003024 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07003025 * @adapter: board private structure
3026 * @rx_ring: ring to clean the resources from
3027 *
3028 * Free all receive software resources
3029 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003030void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
3031 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003032{
3033 struct pci_dev *pdev = adapter->pdev;
3034
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003035 vfree(rx_ring->lro_mgr.lro_arr);
3036 rx_ring->lro_mgr.lro_arr = NULL;
3037
Auke Kok9a799d72007-09-15 14:07:45 -07003038 ixgbe_clean_rx_ring(adapter, rx_ring);
3039
3040 vfree(rx_ring->rx_buffer_info);
3041 rx_ring->rx_buffer_info = NULL;
3042
3043 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
3044
3045 rx_ring->desc = NULL;
3046}
3047
3048/**
3049 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
3050 * @adapter: board private structure
3051 *
3052 * Free all receive software resources
3053 **/
3054static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
3055{
3056 int i;
3057
3058 for (i = 0; i < adapter->num_rx_queues; i++)
3059 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
3060}
3061
3062/**
Auke Kok9a799d72007-09-15 14:07:45 -07003063 * ixgbe_change_mtu - Change the Maximum Transfer Unit
3064 * @netdev: network interface device structure
3065 * @new_mtu: new value for maximum frame size
3066 *
3067 * Returns 0 on success, negative on failure
3068 **/
3069static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
3070{
3071 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3072 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3073
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07003074 /* MTU < 68 is an error and causes problems on some kernels */
3075 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07003076 return -EINVAL;
3077
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003078 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003079 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003080 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07003081 netdev->mtu = new_mtu;
3082
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003083 if (netif_running(netdev))
3084 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003085
3086 return 0;
3087}
3088
3089/**
3090 * ixgbe_open - Called when a network interface is made active
3091 * @netdev: network interface device structure
3092 *
3093 * Returns 0 on success, negative value on failure
3094 *
3095 * The open entry point is called when a network interface is made
3096 * active by the system (IFF_UP). At this point all resources needed
3097 * for transmit and receive operations are allocated, the interrupt
3098 * handler is registered with the OS, the watchdog timer is started,
3099 * and the stack is notified that the interface is ready.
3100 **/
3101static int ixgbe_open(struct net_device *netdev)
3102{
3103 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3104 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003105
Auke Kok4bebfaa2008-02-11 09:26:01 -08003106 /* disallow open during test */
3107 if (test_bit(__IXGBE_TESTING, &adapter->state))
3108 return -EBUSY;
3109
Auke Kok9a799d72007-09-15 14:07:45 -07003110 /* allocate transmit descriptors */
3111 err = ixgbe_setup_all_tx_resources(adapter);
3112 if (err)
3113 goto err_setup_tx;
3114
Auke Kok9a799d72007-09-15 14:07:45 -07003115 /* allocate receive descriptors */
3116 err = ixgbe_setup_all_rx_resources(adapter);
3117 if (err)
3118 goto err_setup_rx;
3119
3120 ixgbe_configure(adapter);
3121
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003122 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003123 if (err)
3124 goto err_req_irq;
3125
Auke Kok9a799d72007-09-15 14:07:45 -07003126 err = ixgbe_up_complete(adapter);
3127 if (err)
3128 goto err_up;
3129
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003130 netif_tx_start_all_queues(netdev);
3131
Auke Kok9a799d72007-09-15 14:07:45 -07003132 return 0;
3133
3134err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003135 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003136 ixgbe_free_irq(adapter);
3137err_req_irq:
3138 ixgbe_free_all_rx_resources(adapter);
3139err_setup_rx:
3140 ixgbe_free_all_tx_resources(adapter);
3141err_setup_tx:
3142 ixgbe_reset(adapter);
3143
3144 return err;
3145}
3146
3147/**
3148 * ixgbe_close - Disables a network interface
3149 * @netdev: network interface device structure
3150 *
3151 * Returns 0, this is not allowed to fail
3152 *
3153 * The close entry point is called when an interface is de-activated
3154 * by the OS. The hardware is still under the drivers control, but
3155 * needs to be disabled. A global MAC reset is issued to stop the
3156 * hardware, and all transmit and receive resources are freed.
3157 **/
3158static int ixgbe_close(struct net_device *netdev)
3159{
3160 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003161
3162 ixgbe_down(adapter);
3163 ixgbe_free_irq(adapter);
3164
3165 ixgbe_free_all_tx_resources(adapter);
3166 ixgbe_free_all_rx_resources(adapter);
3167
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003168 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003169
3170 return 0;
3171}
3172
3173/**
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003174 * ixgbe_napi_add_all - prep napi structs for use
3175 * @adapter: private struct
3176 * helper function to napi_add each possible q_vector->napi
3177 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08003178void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003179{
3180 int q_idx, q_vectors;
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003181 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003182 int (*poll)(struct napi_struct *, int);
3183
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003184 /* check if we already have our netdev->napi_list populated */
3185 if (&netdev->napi_list != netdev->napi_list.next)
3186 return;
3187
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003188 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3189 poll = &ixgbe_clean_rxonly;
3190 /* Only enable as many vectors as we have rx queues. */
3191 q_vectors = adapter->num_rx_queues;
3192 } else {
3193 poll = &ixgbe_poll;
3194 /* only one q_vector for legacy modes */
3195 q_vectors = 1;
3196 }
3197
3198 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3199 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3200 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
3201 }
3202}
3203
Alexander Duyck2f90b862008-11-20 20:52:10 -08003204void ixgbe_napi_del_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003205{
3206 int q_idx;
3207 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3208
3209 /* legacy and MSI only use one vector */
3210 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3211 q_vectors = 1;
3212
3213 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3214 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3215 if (!q_vector->rxr_count)
3216 continue;
3217 netif_napi_del(&q_vector->napi);
3218 }
3219}
3220
3221#ifdef CONFIG_PM
3222static int ixgbe_resume(struct pci_dev *pdev)
3223{
3224 struct net_device *netdev = pci_get_drvdata(pdev);
3225 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3226 u32 err;
3227
3228 pci_set_power_state(pdev, PCI_D0);
3229 pci_restore_state(pdev);
3230 err = pci_enable_device(pdev);
3231 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07003232 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003233 "suspend\n");
3234 return err;
3235 }
3236 pci_set_master(pdev);
3237
3238 pci_enable_wake(pdev, PCI_D3hot, 0);
3239 pci_enable_wake(pdev, PCI_D3cold, 0);
3240
3241 err = ixgbe_init_interrupt_scheme(adapter);
3242 if (err) {
3243 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
3244 "device\n");
3245 return err;
3246 }
3247
3248 ixgbe_napi_add_all(adapter);
3249 ixgbe_reset(adapter);
3250
3251 if (netif_running(netdev)) {
3252 err = ixgbe_open(adapter->netdev);
3253 if (err)
3254 return err;
3255 }
3256
3257 netif_device_attach(netdev);
3258
3259 return 0;
3260}
3261
3262#endif /* CONFIG_PM */
3263static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
3264{
3265 struct net_device *netdev = pci_get_drvdata(pdev);
3266 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3267#ifdef CONFIG_PM
3268 int retval = 0;
3269#endif
3270
3271 netif_device_detach(netdev);
3272
3273 if (netif_running(netdev)) {
3274 ixgbe_down(adapter);
3275 ixgbe_free_irq(adapter);
3276 ixgbe_free_all_tx_resources(adapter);
3277 ixgbe_free_all_rx_resources(adapter);
3278 }
3279 ixgbe_reset_interrupt_capability(adapter);
3280 ixgbe_napi_del_all(adapter);
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003281 INIT_LIST_HEAD(&netdev->napi_list);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003282 kfree(adapter->tx_ring);
3283 kfree(adapter->rx_ring);
3284
3285#ifdef CONFIG_PM
3286 retval = pci_save_state(pdev);
3287 if (retval)
3288 return retval;
3289#endif
3290
3291 pci_enable_wake(pdev, PCI_D3hot, 0);
3292 pci_enable_wake(pdev, PCI_D3cold, 0);
3293
3294 ixgbe_release_hw_control(adapter);
3295
3296 pci_disable_device(pdev);
3297
3298 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3299
3300 return 0;
3301}
3302
3303static void ixgbe_shutdown(struct pci_dev *pdev)
3304{
3305 ixgbe_suspend(pdev, PMSG_SUSPEND);
3306}
3307
3308/**
Auke Kok9a799d72007-09-15 14:07:45 -07003309 * ixgbe_update_stats - Update the board statistics counters.
3310 * @adapter: board private structure
3311 **/
3312void ixgbe_update_stats(struct ixgbe_adapter *adapter)
3313{
3314 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003315 u64 total_mpc = 0;
3316 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003317
3318 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003319 for (i = 0; i < 8; i++) {
3320 /* for packet buffers not used, the register should read 0 */
3321 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
3322 missed_rx += mpc;
3323 adapter->stats.mpc[i] += mpc;
3324 total_mpc += adapter->stats.mpc[i];
3325 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08003326 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
3327 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
3328 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
3329 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
3330 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3331 IXGBE_PXONRXC(i));
3332 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
3333 IXGBE_PXONTXC(i));
3334 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3335 IXGBE_PXOFFRXC(i));
3336 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
3337 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003338 }
3339 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
3340 /* work around hardware counting issue */
3341 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07003342
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003343 /* 82598 hardware only has a 32 bit counter in the high register */
Auke Kok9a799d72007-09-15 14:07:45 -07003344 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003345 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
3346 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
Auke Kok9a799d72007-09-15 14:07:45 -07003347 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
3348 adapter->stats.bprc += bprc;
3349 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
3350 adapter->stats.mprc -= bprc;
3351 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
3352 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
3353 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
3354 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
3355 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
3356 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
3357 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003358 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
3359 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Auke Kok9a799d72007-09-15 14:07:45 -07003360 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003361 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
3362 adapter->stats.lxontxc += lxon;
3363 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
3364 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07003365 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3366 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003367 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
3368 /*
3369 * 82598 errata - tx of flow control packets is included in tx counters
3370 */
3371 xon_off_tot = lxon + lxoff;
3372 adapter->stats.gptc -= xon_off_tot;
3373 adapter->stats.mptc -= xon_off_tot;
3374 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07003375 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3376 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
3377 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07003378 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
3379 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003380 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003381 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3382 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3383 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3384 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3385 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003386 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3387
3388 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07003389 adapter->net_stats.multicast = adapter->stats.mprc;
3390
3391 /* Rx Errors */
3392 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003393 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07003394 adapter->net_stats.rx_dropped = 0;
3395 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3396 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003397 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07003398}
3399
3400/**
3401 * ixgbe_watchdog - Timer Call-back
3402 * @data: pointer to adapter cast into an unsigned long
3403 **/
3404static void ixgbe_watchdog(unsigned long data)
3405{
3406 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003407 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003408
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003409 /* Do the watchdog outside of interrupt context due to the lovely
3410 * delays that some of the newer hardware requires */
3411 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
3412 /* Cause software interrupt to ensure rx rings are cleaned */
3413 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3414 u32 eics =
3415 (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1;
3416 IXGBE_WRITE_REG(hw, IXGBE_EICS, eics);
3417 } else {
3418 /* For legacy and MSI interrupts don't set any bits that
3419 * are enabled for EIAM, because this operation would
3420 * set *both* EIMS and EICS for any bit in EIAM */
3421 IXGBE_WRITE_REG(hw, IXGBE_EICS,
3422 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
3423 }
3424 /* Reset the timer */
3425 mod_timer(&adapter->watchdog_timer,
3426 round_jiffies(jiffies + 2 * HZ));
3427 }
3428
3429 schedule_work(&adapter->watchdog_task);
3430}
3431
3432/**
Alexander Duyck69888672008-09-11 20:05:39 -07003433 * ixgbe_watchdog_task - worker thread to bring link up
3434 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003435 **/
3436static void ixgbe_watchdog_task(struct work_struct *work)
3437{
3438 struct ixgbe_adapter *adapter = container_of(work,
3439 struct ixgbe_adapter,
3440 watchdog_task);
3441 struct net_device *netdev = adapter->netdev;
3442 struct ixgbe_hw *hw = &adapter->hw;
3443 u32 link_speed = adapter->link_speed;
3444 bool link_up = adapter->link_up;
3445
3446 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
3447
3448 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3449 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
3450 if (link_up ||
3451 time_after(jiffies, (adapter->link_check_timeout +
3452 IXGBE_TRY_LINK_TIMEOUT))) {
3453 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
3454 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
3455 }
3456 adapter->link_up = link_up;
3457 adapter->link_speed = link_speed;
3458 }
Auke Kok9a799d72007-09-15 14:07:45 -07003459
3460 if (link_up) {
3461 if (!netif_carrier_ok(netdev)) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003462 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3463 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
Auke Kok9a799d72007-09-15 14:07:45 -07003464#define FLOW_RX (frctl & IXGBE_FCTRL_RFCE)
3465#define FLOW_TX (rmcs & IXGBE_RMCS_TFCE_802_3X)
Jeff Kirshera46e5342008-11-27 00:22:21 -08003466 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
3467 "Flow Control: %s\n",
3468 netdev->name,
3469 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
3470 "10 Gbps" :
3471 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
3472 "1 Gbps" : "unknown speed")),
3473 ((FLOW_RX && FLOW_TX) ? "RX/TX" :
3474 (FLOW_RX ? "RX" :
3475 (FLOW_TX ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07003476
3477 netif_carrier_on(netdev);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003478 netif_tx_wake_all_queues(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003479 } else {
3480 /* Force detection of hung controller */
3481 adapter->detect_tx_hung = true;
3482 }
3483 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003484 adapter->link_up = false;
3485 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003486 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08003487 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
3488 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07003489 netif_carrier_off(netdev);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003490 netif_tx_stop_all_queues(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003491 }
3492 }
3493
3494 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003495 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07003496}
3497
Auke Kok9a799d72007-09-15 14:07:45 -07003498static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003499 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
3500 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07003501{
3502 struct ixgbe_adv_tx_context_desc *context_desc;
3503 unsigned int i;
3504 int err;
3505 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003506 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
3507 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07003508
3509 if (skb_is_gso(skb)) {
3510 if (skb_header_cloned(skb)) {
3511 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3512 if (err)
3513 return err;
3514 }
3515 l4len = tcp_hdrlen(skb);
3516 *hdr_len += l4len;
3517
Al Viro8327d002007-12-10 18:54:12 +00003518 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003519 struct iphdr *iph = ip_hdr(skb);
3520 iph->tot_len = 0;
3521 iph->check = 0;
3522 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003523 iph->daddr, 0,
3524 IPPROTO_TCP,
3525 0);
Auke Kok9a799d72007-09-15 14:07:45 -07003526 adapter->hw_tso_ctxt++;
3527 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3528 ipv6_hdr(skb)->payload_len = 0;
3529 tcp_hdr(skb)->check =
3530 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003531 &ipv6_hdr(skb)->daddr,
3532 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07003533 adapter->hw_tso6_ctxt++;
3534 }
3535
3536 i = tx_ring->next_to_use;
3537
3538 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3539 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3540
3541 /* VLAN MACLEN IPLEN */
3542 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3543 vlan_macip_lens |=
3544 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3545 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003546 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003547 *hdr_len += skb_network_offset(skb);
3548 vlan_macip_lens |=
3549 (skb_transport_header(skb) - skb_network_header(skb));
3550 *hdr_len +=
3551 (skb_transport_header(skb) - skb_network_header(skb));
3552 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3553 context_desc->seqnum_seed = 0;
3554
3555 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003556 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003557 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07003558
Al Viro8327d002007-12-10 18:54:12 +00003559 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07003560 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3561 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3562 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3563
3564 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003565 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07003566 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
3567 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003568 /* use index 1 for TSO */
3569 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003570 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
3571
3572 tx_buffer_info->time_stamp = jiffies;
3573 tx_buffer_info->next_to_watch = i;
3574
3575 i++;
3576 if (i == tx_ring->count)
3577 i = 0;
3578 tx_ring->next_to_use = i;
3579
3580 return true;
3581 }
3582 return false;
3583}
3584
3585static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003586 struct ixgbe_ring *tx_ring,
3587 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07003588{
3589 struct ixgbe_adv_tx_context_desc *context_desc;
3590 unsigned int i;
3591 struct ixgbe_tx_buffer *tx_buffer_info;
3592 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3593
3594 if (skb->ip_summed == CHECKSUM_PARTIAL ||
3595 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
3596 i = tx_ring->next_to_use;
3597 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3598 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3599
3600 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3601 vlan_macip_lens |=
3602 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3603 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003604 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003605 if (skb->ip_summed == CHECKSUM_PARTIAL)
3606 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003607 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07003608
3609 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3610 context_desc->seqnum_seed = 0;
3611
3612 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003613 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07003614
3615 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08003616 switch (skb->protocol) {
3617 case __constant_htons(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07003618 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08003619 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3620 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003621 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08003622 break;
Auke Kok41825d72008-02-12 15:20:33 -08003623 case __constant_htons(ETH_P_IPV6):
3624 /* XXX what about other V6 headers?? */
3625 if (ipv6_hdr(skb)->nexthdr == 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;
Auke Kok41825d72008-02-12 15:20:33 -08003629 default:
3630 if (unlikely(net_ratelimit())) {
3631 DPRINTK(PROBE, WARNING,
3632 "partial checksum but proto=%x!\n",
3633 skb->protocol);
3634 }
3635 break;
3636 }
Auke Kok9a799d72007-09-15 14:07:45 -07003637 }
3638
3639 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003640 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07003641 context_desc->mss_l4len_idx = 0;
3642
3643 tx_buffer_info->time_stamp = jiffies;
3644 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003645
Auke Kok9a799d72007-09-15 14:07:45 -07003646 adapter->hw_csum_tx_good++;
3647 i++;
3648 if (i == tx_ring->count)
3649 i = 0;
3650 tx_ring->next_to_use = i;
3651
3652 return true;
3653 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003654
Auke Kok9a799d72007-09-15 14:07:45 -07003655 return false;
3656}
3657
3658static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003659 struct ixgbe_ring *tx_ring,
3660 struct sk_buff *skb, unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07003661{
3662 struct ixgbe_tx_buffer *tx_buffer_info;
3663 unsigned int len = skb->len;
3664 unsigned int offset = 0, size, count = 0, i;
3665 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3666 unsigned int f;
3667
3668 len -= skb->data_len;
3669
3670 i = tx_ring->next_to_use;
3671
3672 while (len) {
3673 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3674 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3675
3676 tx_buffer_info->length = size;
3677 tx_buffer_info->dma = pci_map_single(adapter->pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003678 skb->data + offset,
3679 size, PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003680 tx_buffer_info->time_stamp = jiffies;
3681 tx_buffer_info->next_to_watch = i;
3682
3683 len -= size;
3684 offset += size;
3685 count++;
3686 i++;
3687 if (i == tx_ring->count)
3688 i = 0;
3689 }
3690
3691 for (f = 0; f < nr_frags; f++) {
3692 struct skb_frag_struct *frag;
3693
3694 frag = &skb_shinfo(skb)->frags[f];
3695 len = frag->size;
3696 offset = frag->page_offset;
3697
3698 while (len) {
3699 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3700 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3701
3702 tx_buffer_info->length = size;
3703 tx_buffer_info->dma = pci_map_page(adapter->pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003704 frag->page,
3705 offset,
3706 size,
3707 PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003708 tx_buffer_info->time_stamp = jiffies;
3709 tx_buffer_info->next_to_watch = i;
3710
3711 len -= size;
3712 offset += size;
3713 count++;
3714 i++;
3715 if (i == tx_ring->count)
3716 i = 0;
3717 }
3718 }
3719 if (i == 0)
3720 i = tx_ring->count - 1;
3721 else
3722 i = i - 1;
3723 tx_ring->tx_buffer_info[i].skb = skb;
3724 tx_ring->tx_buffer_info[first].next_to_watch = i;
3725
3726 return count;
3727}
3728
3729static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003730 struct ixgbe_ring *tx_ring,
3731 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07003732{
3733 union ixgbe_adv_tx_desc *tx_desc = NULL;
3734 struct ixgbe_tx_buffer *tx_buffer_info;
3735 u32 olinfo_status = 0, cmd_type_len = 0;
3736 unsigned int i;
3737 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
3738
3739 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
3740
3741 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
3742
3743 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3744 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
3745
3746 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
3747 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
3748
3749 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003750 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003751
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003752 /* use index 1 context for tso */
3753 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003754 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
3755 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003756 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003757
3758 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
3759 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003760 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003761
3762 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
3763
3764 i = tx_ring->next_to_use;
3765 while (count--) {
3766 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3767 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
3768 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
3769 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003770 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07003771 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07003772 i++;
3773 if (i == tx_ring->count)
3774 i = 0;
3775 }
3776
3777 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
3778
3779 /*
3780 * Force memory writes to complete before letting h/w
3781 * know there are new descriptors to fetch. (Only
3782 * applicable for weak-ordered memory model archs,
3783 * such as IA-64).
3784 */
3785 wmb();
3786
3787 tx_ring->next_to_use = i;
3788 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3789}
3790
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003791static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003792 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003793{
3794 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3795
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003796 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003797 /* Herbert's original patch had:
3798 * smp_mb__after_netif_stop_queue();
3799 * but since that doesn't exist yet, just open code it. */
3800 smp_mb();
3801
3802 /* We need to check again in a case another CPU has just
3803 * made room available. */
3804 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
3805 return -EBUSY;
3806
3807 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07003808 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003809 ++adapter->restart_queue;
3810 return 0;
3811}
3812
3813static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003814 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003815{
3816 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
3817 return 0;
3818 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
3819}
3820
Auke Kok9a799d72007-09-15 14:07:45 -07003821static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3822{
3823 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3824 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07003825 unsigned int first;
3826 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003827 u8 hdr_len = 0;
3828 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07003829 int count = 0;
3830 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003831
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003832 r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003833 tx_ring = &adapter->tx_ring[r_idx];
Auke Kok9a799d72007-09-15 14:07:45 -07003834
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003835 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3836 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003837 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3838 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
3839 tx_flags |= (skb->queue_mapping << 13);
3840 }
3841 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3842 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3843 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3844 tx_flags |= (skb->queue_mapping << 13);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003845 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3846 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07003847 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003848 /* three things can cause us to need a context descriptor */
3849 if (skb_is_gso(skb) ||
3850 (skb->ip_summed == CHECKSUM_PARTIAL) ||
3851 (tx_flags & IXGBE_TX_FLAGS_VLAN))
Auke Kok9a799d72007-09-15 14:07:45 -07003852 count++;
3853
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003854 count += TXD_USE_COUNT(skb_headlen(skb));
3855 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07003856 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
3857
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003858 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003859 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07003860 return NETDEV_TX_BUSY;
3861 }
Auke Kok9a799d72007-09-15 14:07:45 -07003862
Al Viro8327d002007-12-10 18:54:12 +00003863 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07003864 tx_flags |= IXGBE_TX_FLAGS_IPV4;
3865 first = tx_ring->next_to_use;
3866 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
3867 if (tso < 0) {
3868 dev_kfree_skb_any(skb);
3869 return NETDEV_TX_OK;
3870 }
3871
3872 if (tso)
3873 tx_flags |= IXGBE_TX_FLAGS_TSO;
3874 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003875 (skb->ip_summed == CHECKSUM_PARTIAL))
Auke Kok9a799d72007-09-15 14:07:45 -07003876 tx_flags |= IXGBE_TX_FLAGS_CSUM;
3877
3878 ixgbe_tx_queue(adapter, tx_ring, tx_flags,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003879 ixgbe_tx_map(adapter, tx_ring, skb, first),
3880 skb->len, hdr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07003881
3882 netdev->trans_start = jiffies;
3883
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003884 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07003885
3886 return NETDEV_TX_OK;
3887}
3888
3889/**
3890 * ixgbe_get_stats - Get System Network Statistics
3891 * @netdev: network interface device structure
3892 *
3893 * Returns the address of the device statistics structure.
3894 * The statistics are actually updated from the timer callback.
3895 **/
3896static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
3897{
3898 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3899
3900 /* only return the current stats */
3901 return &adapter->net_stats;
3902}
3903
3904/**
3905 * ixgbe_set_mac - Change the Ethernet Address of the NIC
3906 * @netdev: network interface device structure
3907 * @p: pointer to an address structure
3908 *
3909 * Returns 0 on success, negative on failure
3910 **/
3911static int ixgbe_set_mac(struct net_device *netdev, void *p)
3912{
3913 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003914 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003915 struct sockaddr *addr = p;
3916
3917 if (!is_valid_ether_addr(addr->sa_data))
3918 return -EADDRNOTAVAIL;
3919
3920 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003921 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07003922
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003923 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003924
3925 return 0;
3926}
3927
3928#ifdef CONFIG_NET_POLL_CONTROLLER
3929/*
3930 * Polling 'interrupt' - used by things like netconsole to send skbs
3931 * without having to re-enable interrupts. It's not called while
3932 * the interrupt routine is executing.
3933 */
3934static void ixgbe_netpoll(struct net_device *netdev)
3935{
3936 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3937
3938 disable_irq(adapter->pdev->irq);
3939 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
3940 ixgbe_intr(adapter->pdev->irq, netdev);
3941 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
3942 enable_irq(adapter->pdev->irq);
3943}
3944#endif
3945
3946/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003947 * ixgbe_link_config - set up initial link with default speed and duplex
3948 * @hw: pointer to private hardware struct
3949 *
3950 * Returns 0 on success, negative on failure
3951 **/
3952static int ixgbe_link_config(struct ixgbe_hw *hw)
3953{
3954 u32 autoneg = IXGBE_LINK_SPEED_10GB_FULL;
3955
3956 /* must always autoneg for both 1G and 10G link */
3957 hw->mac.autoneg = true;
3958
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003959 if ((hw->mac.type == ixgbe_mac_82598EB) &&
3960 (hw->phy.media_type == ixgbe_media_type_copper))
3961 autoneg = IXGBE_LINK_SPEED_82598_AUTONEG;
3962
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003963 return hw->mac.ops.setup_link_speed(hw, autoneg, true, true);
3964}
3965
Stephen Hemminger0edc3522008-11-19 22:24:29 -08003966static const struct net_device_ops ixgbe_netdev_ops = {
3967 .ndo_open = ixgbe_open,
3968 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08003969 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08003970 .ndo_get_stats = ixgbe_get_stats,
3971 .ndo_set_multicast_list = ixgbe_set_rx_mode,
3972 .ndo_validate_addr = eth_validate_addr,
3973 .ndo_set_mac_address = ixgbe_set_mac,
3974 .ndo_change_mtu = ixgbe_change_mtu,
3975 .ndo_tx_timeout = ixgbe_tx_timeout,
3976 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
3977 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
3978 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
3979#ifdef CONFIG_NET_POLL_CONTROLLER
3980 .ndo_poll_controller = ixgbe_netpoll,
3981#endif
3982};
3983
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003984/**
Auke Kok9a799d72007-09-15 14:07:45 -07003985 * ixgbe_probe - Device Initialization Routine
3986 * @pdev: PCI device information struct
3987 * @ent: entry in ixgbe_pci_tbl
3988 *
3989 * Returns 0 on success, negative on failure
3990 *
3991 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
3992 * The OS initialization, configuring of the adapter private structure,
3993 * and a hardware reset occur.
3994 **/
3995static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003996 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07003997{
3998 struct net_device *netdev;
3999 struct ixgbe_adapter *adapter = NULL;
4000 struct ixgbe_hw *hw;
4001 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07004002 static int cards_found;
4003 int i, err, pci_using_dac;
4004 u16 link_status, link_speed, link_width;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004005 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07004006
4007 err = pci_enable_device(pdev);
4008 if (err)
4009 return err;
4010
4011 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4012 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
4013 pci_using_dac = 1;
4014 } else {
4015 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4016 if (err) {
4017 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
4018 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004019 dev_err(&pdev->dev, "No usable DMA "
4020 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004021 goto err_dma;
4022 }
4023 }
4024 pci_using_dac = 0;
4025 }
4026
4027 err = pci_request_regions(pdev, ixgbe_driver_name);
4028 if (err) {
4029 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
4030 goto err_pci_reg;
4031 }
4032
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004033 err = pci_enable_pcie_error_reporting(pdev);
4034 if (err) {
4035 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
4036 "0x%x\n", err);
4037 /* non-fatal, continue */
4038 }
4039
Auke Kok9a799d72007-09-15 14:07:45 -07004040 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07004041 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004042
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004043 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07004044 if (!netdev) {
4045 err = -ENOMEM;
4046 goto err_alloc_etherdev;
4047 }
4048
Auke Kok9a799d72007-09-15 14:07:45 -07004049 SET_NETDEV_DEV(netdev, &pdev->dev);
4050
4051 pci_set_drvdata(pdev, netdev);
4052 adapter = netdev_priv(netdev);
4053
4054 adapter->netdev = netdev;
4055 adapter->pdev = pdev;
4056 hw = &adapter->hw;
4057 hw->back = adapter;
4058 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
4059
Jeff Kirsher05857982008-09-11 19:57:00 -07004060 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
4061 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07004062 if (!hw->hw_addr) {
4063 err = -EIO;
4064 goto err_ioremap;
4065 }
4066
4067 for (i = 1; i <= 5; i++) {
4068 if (pci_resource_len(pdev, i) == 0)
4069 continue;
4070 }
4071
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004072 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07004073 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004074 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07004075 strcpy(netdev->name, pci_name(pdev));
4076
Auke Kok9a799d72007-09-15 14:07:45 -07004077 adapter->bd_number = cards_found;
4078
Auke Kok9a799d72007-09-15 14:07:45 -07004079 /* Setup hw api */
4080 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004081 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07004082
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004083 /* EEPROM */
4084 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
4085 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
4086 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
4087 if (!(eec & (1 << 8)))
4088 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
4089
4090 /* PHY */
4091 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08004092 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
4093
4094 /* set up this timer and work struct before calling get_invariants
4095 * which might start the timer
4096 */
4097 init_timer(&adapter->sfp_timer);
4098 adapter->sfp_timer.function = &ixgbe_sfp_timer;
4099 adapter->sfp_timer.data = (unsigned long) adapter;
4100
4101 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004102
Auke Kok9a799d72007-09-15 14:07:45 -07004103 err = ii->get_invariants(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004104 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
4105 /* start a kernel thread to watch for a module to arrive */
4106 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4107 mod_timer(&adapter->sfp_timer,
4108 round_jiffies(jiffies + (2 * HZ)));
4109 err = 0;
4110 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4111 DPRINTK(PROBE, ERR, "failed to load because an "
4112 "unsupported SFP+ module type was detected.\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004113 goto err_hw_init;
Donald Skidmorec4900be2008-11-20 21:11:42 -08004114 } else if (err) {
4115 goto err_hw_init;
4116 }
Auke Kok9a799d72007-09-15 14:07:45 -07004117
4118 /* setup the private structure */
4119 err = ixgbe_sw_init(adapter);
4120 if (err)
4121 goto err_sw_init;
4122
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004123 /* reset_hw fills in the perm_addr as well */
4124 err = hw->mac.ops.reset_hw(hw);
4125 if (err) {
4126 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
4127 goto err_sw_init;
4128 }
4129
Auke Kok9a799d72007-09-15 14:07:45 -07004130 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004131 NETIF_F_IP_CSUM |
4132 NETIF_F_HW_VLAN_TX |
4133 NETIF_F_HW_VLAN_RX |
4134 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004135
Jesse Brandeburge9990a92008-08-26 04:27:24 -07004136 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07004137 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07004138 netdev->features |= NETIF_F_TSO6;
Jesse Brandeburge9990a92008-08-26 04:27:24 -07004139 netdev->features |= NETIF_F_LRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004140
4141 netdev->vlan_features |= NETIF_F_TSO;
4142 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07004143 netdev->vlan_features |= NETIF_F_IP_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004144 netdev->vlan_features |= NETIF_F_SG;
4145
Alexander Duyck2f90b862008-11-20 20:52:10 -08004146 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4147 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4148
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004149#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004150 netdev->dcbnl_ops = &dcbnl_ops;
4151#endif
4152
Auke Kok9a799d72007-09-15 14:07:45 -07004153 if (pci_using_dac)
4154 netdev->features |= NETIF_F_HIGHDMA;
4155
Auke Kok9a799d72007-09-15 14:07:45 -07004156 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004157 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07004158 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
4159 err = -EIO;
4160 goto err_eeprom;
4161 }
4162
4163 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
4164 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
4165
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004166 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
4167 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004168 err = -EIO;
4169 goto err_eeprom;
4170 }
4171
4172 init_timer(&adapter->watchdog_timer);
4173 adapter->watchdog_timer.function = &ixgbe_watchdog;
4174 adapter->watchdog_timer.data = (unsigned long)adapter;
4175
4176 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004177 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004178
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004179 err = ixgbe_init_interrupt_scheme(adapter);
4180 if (err)
4181 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07004182
4183 /* print bus type/speed/width info */
4184 pci_read_config_word(pdev, IXGBE_PCI_LINK_STATUS, &link_status);
4185 link_speed = link_status & IXGBE_PCI_LINK_SPEED;
4186 link_width = link_status & IXGBE_PCI_LINK_WIDTH;
Johannes Berg7c510e42008-10-27 17:47:26 -07004187 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004188 ((link_speed == IXGBE_PCI_LINK_SPEED_5000) ? "5.0Gb/s" :
4189 (link_speed == IXGBE_PCI_LINK_SPEED_2500) ? "2.5Gb/s" :
4190 "Unknown"),
4191 ((link_width == IXGBE_PCI_LINK_WIDTH_8) ? "Width x8" :
4192 (link_width == IXGBE_PCI_LINK_WIDTH_4) ? "Width x4" :
4193 (link_width == IXGBE_PCI_LINK_WIDTH_2) ? "Width x2" :
4194 (link_width == IXGBE_PCI_LINK_WIDTH_1) ? "Width x1" :
4195 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07004196 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004197 ixgbe_read_pba_num_generic(hw, &part_num);
Auke Kok9a799d72007-09-15 14:07:45 -07004198 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004199 hw->mac.type, hw->phy.type,
4200 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07004201
Auke Kok0c254d82008-02-11 09:25:56 -08004202 if (link_width <= IXGBE_PCI_LINK_WIDTH_4) {
4203 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004204 "this card is not sufficient for optimal "
4205 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004206 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004207 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004208 }
4209
Auke Kok9a799d72007-09-15 14:07:45 -07004210 /* reset the hardware with the new settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004211 hw->mac.ops.start_hw(hw);
4212
4213 /* link_config depends on start_hw being called at least once */
4214 err = ixgbe_link_config(hw);
4215 if (err) {
4216 dev_err(&pdev->dev, "setup_link_speed FAILED %d\n", err);
4217 goto err_register;
4218 }
Auke Kok9a799d72007-09-15 14:07:45 -07004219
4220 netif_carrier_off(netdev);
Alexander Duyck2f90b862008-11-20 20:52:10 -08004221 netif_tx_stop_all_queues(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004222
4223 strcpy(netdev->name, "eth%d");
4224 err = register_netdev(netdev);
4225 if (err)
4226 goto err_register;
4227
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004228#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03004229 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004230 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
4231 /* always use CB2 mode, difference is masked
4232 * in the CB driver */
4233 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
4234 ixgbe_setup_dca(adapter);
4235 }
4236#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004237
4238 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
4239 cards_found++;
4240 return 0;
4241
4242err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004243 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004244err_hw_init:
4245err_sw_init:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004246 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004247err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08004248 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4249 del_timer_sync(&adapter->sfp_timer);
4250 cancel_work_sync(&adapter->sfp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004251 iounmap(hw->hw_addr);
4252err_ioremap:
4253 free_netdev(netdev);
4254err_alloc_etherdev:
4255 pci_release_regions(pdev);
4256err_pci_reg:
4257err_dma:
4258 pci_disable_device(pdev);
4259 return err;
4260}
4261
4262/**
4263 * ixgbe_remove - Device Removal Routine
4264 * @pdev: PCI device information struct
4265 *
4266 * ixgbe_remove is called by the PCI subsystem to alert the driver
4267 * that it should release a PCI device. The could be caused by a
4268 * Hot-Plug event, or because the driver is going to be removed from
4269 * memory.
4270 **/
4271static void __devexit ixgbe_remove(struct pci_dev *pdev)
4272{
4273 struct net_device *netdev = pci_get_drvdata(pdev);
4274 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004275 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004276
4277 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004278 /* clear the module not found bit to make sure the worker won't
4279 * reschedule
4280 */
4281 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07004282 del_timer_sync(&adapter->watchdog_timer);
4283
Donald Skidmorec4900be2008-11-20 21:11:42 -08004284 del_timer_sync(&adapter->sfp_timer);
4285 cancel_work_sync(&adapter->watchdog_task);
4286 cancel_work_sync(&adapter->sfp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004287 flush_scheduled_work();
4288
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004289#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004290 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
4291 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
4292 dca_remove_requester(&pdev->dev);
4293 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
4294 }
4295
4296#endif
Donald Skidmorec4900be2008-11-20 21:11:42 -08004297 if (netdev->reg_state == NETREG_REGISTERED)
4298 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004299
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004300 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004301
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004302 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004303
4304 iounmap(adapter->hw.hw_addr);
4305 pci_release_regions(pdev);
4306
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004307 DPRINTK(PROBE, INFO, "complete\n");
4308 kfree(adapter->tx_ring);
4309 kfree(adapter->rx_ring);
4310
Auke Kok9a799d72007-09-15 14:07:45 -07004311 free_netdev(netdev);
4312
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004313 err = pci_disable_pcie_error_reporting(pdev);
4314 if (err)
4315 dev_err(&pdev->dev,
4316 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
4317
Auke Kok9a799d72007-09-15 14:07:45 -07004318 pci_disable_device(pdev);
4319}
4320
4321/**
4322 * ixgbe_io_error_detected - called when PCI error is detected
4323 * @pdev: Pointer to PCI device
4324 * @state: The current pci connection state
4325 *
4326 * This function is called after a PCI bus error affecting
4327 * this device has been detected.
4328 */
4329static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004330 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07004331{
4332 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004333 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004334
4335 netif_device_detach(netdev);
4336
4337 if (netif_running(netdev))
4338 ixgbe_down(adapter);
4339 pci_disable_device(pdev);
4340
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004341 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07004342 return PCI_ERS_RESULT_NEED_RESET;
4343}
4344
4345/**
4346 * ixgbe_io_slot_reset - called after the pci bus has been reset.
4347 * @pdev: Pointer to PCI device
4348 *
4349 * Restart the card from scratch, as if from a cold-boot.
4350 */
4351static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
4352{
4353 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004354 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004355 pci_ers_result_t result;
4356 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004357
4358 if (pci_enable_device(pdev)) {
4359 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004360 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004361 result = PCI_ERS_RESULT_DISCONNECT;
4362 } else {
4363 pci_set_master(pdev);
4364 pci_restore_state(pdev);
4365
4366 pci_enable_wake(pdev, PCI_D3hot, 0);
4367 pci_enable_wake(pdev, PCI_D3cold, 0);
4368
4369 ixgbe_reset(adapter);
4370
4371 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07004372 }
Auke Kok9a799d72007-09-15 14:07:45 -07004373
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004374 err = pci_cleanup_aer_uncorrect_error_status(pdev);
4375 if (err) {
4376 dev_err(&pdev->dev,
4377 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
4378 /* non-fatal, continue */
4379 }
Auke Kok9a799d72007-09-15 14:07:45 -07004380
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004381 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07004382}
4383
4384/**
4385 * ixgbe_io_resume - called when traffic can start flowing again.
4386 * @pdev: Pointer to PCI device
4387 *
4388 * This callback is called when the error recovery driver tells us that
4389 * its OK to resume normal operation.
4390 */
4391static void ixgbe_io_resume(struct pci_dev *pdev)
4392{
4393 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004394 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004395
4396 if (netif_running(netdev)) {
4397 if (ixgbe_up(adapter)) {
4398 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
4399 return;
4400 }
4401 }
4402
4403 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004404}
4405
4406static struct pci_error_handlers ixgbe_err_handler = {
4407 .error_detected = ixgbe_io_error_detected,
4408 .slot_reset = ixgbe_io_slot_reset,
4409 .resume = ixgbe_io_resume,
4410};
4411
4412static struct pci_driver ixgbe_driver = {
4413 .name = ixgbe_driver_name,
4414 .id_table = ixgbe_pci_tbl,
4415 .probe = ixgbe_probe,
4416 .remove = __devexit_p(ixgbe_remove),
4417#ifdef CONFIG_PM
4418 .suspend = ixgbe_suspend,
4419 .resume = ixgbe_resume,
4420#endif
4421 .shutdown = ixgbe_shutdown,
4422 .err_handler = &ixgbe_err_handler
4423};
4424
4425/**
4426 * ixgbe_init_module - Driver Registration Routine
4427 *
4428 * ixgbe_init_module is the first routine called when the driver is
4429 * loaded. All it does is register with the PCI subsystem.
4430 **/
4431static int __init ixgbe_init_module(void)
4432{
4433 int ret;
4434 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
4435 ixgbe_driver_string, ixgbe_driver_version);
4436
4437 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
4438
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004439#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004440 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004441#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004442
Auke Kok9a799d72007-09-15 14:07:45 -07004443 ret = pci_register_driver(&ixgbe_driver);
4444 return ret;
4445}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004446
Auke Kok9a799d72007-09-15 14:07:45 -07004447module_init(ixgbe_init_module);
4448
4449/**
4450 * ixgbe_exit_module - Driver Exit Cleanup Routine
4451 *
4452 * ixgbe_exit_module is called just before the driver is removed
4453 * from memory.
4454 **/
4455static void __exit ixgbe_exit_module(void)
4456{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004457#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004458 dca_unregister_notify(&dca_notifier);
4459#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004460 pci_unregister_driver(&ixgbe_driver);
4461}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004462
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004463#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004464static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004465 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004466{
4467 int ret_val;
4468
4469 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004470 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004471
4472 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4473}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004474#endif /* CONFIG_IXGBE_DCA */
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004475
Auke Kok9a799d72007-09-15 14:07:45 -07004476module_exit(ixgbe_exit_module);
4477
4478/* ixgbe_main.c */