blob: 7489094bbbc80507c249cab4fb301f610c8873a4 [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;
Don Skidmore15005a32009-01-19 16:54:13 -0800321 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
322 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
323 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800324 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700325 rx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800326 }
327 put_cpu();
328}
329
330static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700331 struct ixgbe_ring *tx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800332{
333 u32 txctrl;
334 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700335 int q = tx_ring - adapter->tx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800336
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700337 if (tx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800338 txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q));
339 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700340 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800341 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
342 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700343 tx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800344 }
345 put_cpu();
346}
347
348static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
349{
350 int i;
351
352 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
353 return;
354
355 for (i = 0; i < adapter->num_tx_queues; i++) {
356 adapter->tx_ring[i].cpu = -1;
357 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
358 }
359 for (i = 0; i < adapter->num_rx_queues; i++) {
360 adapter->rx_ring[i].cpu = -1;
361 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
362 }
363}
364
365static int __ixgbe_notify_dca(struct device *dev, void *data)
366{
367 struct net_device *netdev = dev_get_drvdata(dev);
368 struct ixgbe_adapter *adapter = netdev_priv(netdev);
369 unsigned long event = *(unsigned long *)data;
370
371 switch (event) {
372 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700373 /* if we're already enabled, don't do it again */
374 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
375 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800376 /* Always use CB2 mode, difference is masked
377 * in the CB driver. */
378 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
Denis V. Lunev652f0932008-03-27 14:39:17 +0300379 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700380 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800381 ixgbe_setup_dca(adapter);
382 break;
383 }
384 /* Fall Through since DCA is disabled. */
385 case DCA_PROVIDER_REMOVE:
386 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
387 dca_remove_requester(dev);
388 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
389 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
390 }
391 break;
392 }
393
Denis V. Lunev652f0932008-03-27 14:39:17 +0300394 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800395}
396
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400397#endif /* CONFIG_IXGBE_DCA */
Auke Kok9a799d72007-09-15 14:07:45 -0700398/**
399 * ixgbe_receive_skb - Send a completed packet up the stack
400 * @adapter: board private structure
401 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700402 * @status: hardware indication of status of receive
403 * @rx_ring: rx descriptor ring (for a specific queue) to setup
404 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -0700405 **/
406static void ixgbe_receive_skb(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700407 struct sk_buff *skb, u8 status,
408 struct ixgbe_ring *ring,
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700409 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -0700410{
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700411 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
412 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -0700413
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700414 if (adapter->netdev->features & NETIF_F_LRO &&
415 skb->ip_summed == CHECKSUM_UNNECESSARY) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800416 if (adapter->vlgrp && is_vlan && (tag != 0))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700417 lro_vlan_hwaccel_receive_skb(&ring->lro_mgr, skb,
418 adapter->vlgrp, tag,
419 rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700420 else
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700421 lro_receive_skb(&ring->lro_mgr, skb, rx_desc);
422 ring->lro_used = true;
423 } else {
424 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800425 if (adapter->vlgrp && is_vlan && (tag != 0))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700426 vlan_hwaccel_receive_skb(skb, adapter->vlgrp, tag);
427 else
428 netif_receive_skb(skb);
429 } else {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800430 if (adapter->vlgrp && is_vlan && (tag != 0))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700431 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
432 else
433 netif_rx(skb);
434 }
Auke Kok9a799d72007-09-15 14:07:45 -0700435 }
436}
437
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800438/**
439 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
440 * @adapter: address of board private structure
441 * @status_err: hardware indication of status of receive
442 * @skb: skb currently being received and modified
443 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700444static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700445 u32 status_err, struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700446{
447 skb->ip_summed = CHECKSUM_NONE;
448
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700449 /* Rx csum disabled */
450 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -0700451 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800452
453 /* if IP and error */
454 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
455 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700456 adapter->hw_csum_rx_error++;
457 return;
458 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800459
460 if (!(status_err & IXGBE_RXD_STAT_L4CS))
461 return;
462
463 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
464 adapter->hw_csum_rx_error++;
465 return;
466 }
467
Auke Kok9a799d72007-09-15 14:07:45 -0700468 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800469 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -0700470 adapter->hw_csum_rx_good++;
471}
472
473/**
474 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
475 * @adapter: address of board private structure
476 **/
477static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700478 struct ixgbe_ring *rx_ring,
479 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700480{
Auke Kok9a799d72007-09-15 14:07:45 -0700481 struct pci_dev *pdev = adapter->pdev;
482 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700483 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700484 unsigned int i;
Auke Kok9a799d72007-09-15 14:07:45 -0700485
486 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700487 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700488
489 while (cleaned_count--) {
490 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
491
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700492 if (!bi->page_dma &&
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700493 (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700494 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700495 bi->page = alloc_page(GFP_ATOMIC);
496 if (!bi->page) {
497 adapter->alloc_rx_page_failed++;
498 goto no_buffers;
499 }
500 bi->page_offset = 0;
501 } else {
502 /* use a half page if we're re-using */
503 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700504 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700505
506 bi->page_dma = pci_map_page(pdev, bi->page,
507 bi->page_offset,
508 (PAGE_SIZE / 2),
509 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700510 }
511
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700512 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800513 struct sk_buff *skb;
514 skb = netdev_alloc_skb(adapter->netdev,
515 (rx_ring->rx_buf_len +
516 NET_IP_ALIGN));
Auke Kok9a799d72007-09-15 14:07:45 -0700517
518 if (!skb) {
519 adapter->alloc_rx_buff_failed++;
520 goto no_buffers;
521 }
522
523 /*
524 * Make buffer alignment 2 beyond a 16 byte boundary
525 * this will result in a 16 byte aligned IP header after
526 * the 14 byte MAC header is removed
527 */
528 skb_reserve(skb, NET_IP_ALIGN);
529
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700530 bi->skb = skb;
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800531 bi->dma = pci_map_single(pdev, skb->data,
532 rx_ring->rx_buf_len,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700533 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700534 }
535 /* Refresh the desc even if buffer_addrs didn't change because
536 * each write-back erases this info. */
537 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700538 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
539 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700540 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700541 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700542 }
543
544 i++;
545 if (i == rx_ring->count)
546 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700547 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700548 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700549
Auke Kok9a799d72007-09-15 14:07:45 -0700550no_buffers:
551 if (rx_ring->next_to_use != i) {
552 rx_ring->next_to_use = i;
553 if (i-- == 0)
554 i = (rx_ring->count - 1);
555
556 /*
557 * Force memory writes to complete before letting h/w
558 * know there are new descriptors to fetch. (Only
559 * applicable for weak-ordered memory model archs,
560 * such as IA-64).
561 */
562 wmb();
563 writel(i, adapter->hw.hw_addr + rx_ring->tail);
564 }
565}
566
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700567static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
568{
569 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
570}
571
572static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
573{
574 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
575}
576
Auke Kok9a799d72007-09-15 14:07:45 -0700577static bool ixgbe_clean_rx_irq(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700578 struct ixgbe_ring *rx_ring,
579 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700580{
Auke Kok9a799d72007-09-15 14:07:45 -0700581 struct pci_dev *pdev = adapter->pdev;
582 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
583 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
584 struct sk_buff *skb;
585 unsigned int i;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700586 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700587 u16 hdr_info;
588 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700589 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800590 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700591
592 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700593 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
594 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
595 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700596
597 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700598 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700599 if (*work_done >= work_to_do)
600 break;
601 (*work_done)++;
602
603 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700604 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
605 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700606 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700607 if (hdr_info & IXGBE_RXDADV_SPH)
608 adapter->rx_hdr_split++;
609 if (len > IXGBE_RX_HDR_SIZE)
610 len = IXGBE_RX_HDR_SIZE;
611 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700612 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700613 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700614 }
Auke Kok9a799d72007-09-15 14:07:45 -0700615
616 cleaned = true;
617 skb = rx_buffer_info->skb;
618 prefetch(skb->data - NET_IP_ALIGN);
619 rx_buffer_info->skb = NULL;
620
621 if (len && !skb_shinfo(skb)->nr_frags) {
622 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800623 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700624 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700625 skb_put(skb, len);
626 }
627
628 if (upper_len) {
629 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700630 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700631 rx_buffer_info->page_dma = 0;
632 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700633 rx_buffer_info->page,
634 rx_buffer_info->page_offset,
635 upper_len);
636
637 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
638 (page_count(rx_buffer_info->page) != 1))
639 rx_buffer_info->page = NULL;
640 else
641 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700642
643 skb->len += upper_len;
644 skb->data_len += upper_len;
645 skb->truesize += upper_len;
646 }
647
648 i++;
649 if (i == rx_ring->count)
650 i = 0;
651 next_buffer = &rx_ring->rx_buffer_info[i];
652
653 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
654 prefetch(next_rxd);
655
656 cleaned_count++;
657 if (staterr & IXGBE_RXD_STAT_EOP) {
658 rx_ring->stats.packets++;
659 rx_ring->stats.bytes += skb->len;
660 } else {
661 rx_buffer_info->skb = next_buffer->skb;
662 rx_buffer_info->dma = next_buffer->dma;
663 next_buffer->skb = skb;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700664 next_buffer->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700665 adapter->non_eop_descs++;
666 goto next_desc;
667 }
668
669 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
670 dev_kfree_skb_irq(skb);
671 goto next_desc;
672 }
673
674 ixgbe_rx_checksum(adapter, staterr, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800675
676 /* probably a little skewed due to removing CRC */
677 total_rx_bytes += skb->len;
678 total_rx_packets++;
679
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700680 skb->protocol = eth_type_trans(skb, adapter->netdev);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700681 ixgbe_receive_skb(adapter, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700682
683next_desc:
684 rx_desc->wb.upper.status_error = 0;
685
686 /* return some buffers to hardware, one at a time is too slow */
687 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
688 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
689 cleaned_count = 0;
690 }
691
692 /* use prefetched values */
693 rx_desc = next_rxd;
694 rx_buffer_info = next_buffer;
695
696 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700697 }
698
699 if (rx_ring->lro_used) {
700 lro_flush_all(&rx_ring->lro_mgr);
701 rx_ring->lro_used = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700702 }
703
704 rx_ring->next_to_clean = i;
705 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
706
707 if (cleaned_count)
708 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
709
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800710 rx_ring->total_packets += total_rx_packets;
711 rx_ring->total_bytes += total_rx_bytes;
712 adapter->net_stats.rx_bytes += total_rx_bytes;
713 adapter->net_stats.rx_packets += total_rx_packets;
714
Auke Kok9a799d72007-09-15 14:07:45 -0700715 return cleaned;
716}
717
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800718static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700719/**
720 * ixgbe_configure_msix - Configure MSI-X hardware
721 * @adapter: board private structure
722 *
723 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
724 * interrupts.
725 **/
726static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
727{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800728 struct ixgbe_q_vector *q_vector;
729 int i, j, q_vectors, v_idx, r_idx;
730 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700731
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800732 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
733
734 /* Populate the IVAR table and set the ITR values to the
735 * corresponding register.
736 */
737 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
738 q_vector = &adapter->q_vector[v_idx];
739 /* XXX for_each_bit(...) */
740 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700741 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800742
743 for (i = 0; i < q_vector->rxr_count; i++) {
744 j = adapter->rx_ring[r_idx].reg_idx;
745 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(j), v_idx);
746 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700747 adapter->num_rx_queues,
748 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800749 }
750 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700751 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800752
753 for (i = 0; i < q_vector->txr_count; i++) {
754 j = adapter->tx_ring[r_idx].reg_idx;
755 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(j), v_idx);
756 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700757 adapter->num_tx_queues,
758 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800759 }
760
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700761 /* if this is a tx only vector halve the interrupt rate */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800762 if (q_vector->txr_count && !q_vector->rxr_count)
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700763 q_vector->eitr = (adapter->eitr_param >> 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800764 else
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700765 /* rx only */
766 q_vector->eitr = adapter->eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800767
768 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx),
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700769 EITR_INTS_PER_SEC_TO_REG(q_vector->eitr));
Auke Kok9a799d72007-09-15 14:07:45 -0700770 }
771
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800772 ixgbe_set_ivar(adapter, IXGBE_IVAR_OTHER_CAUSES_INDEX, v_idx);
773 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -0700774
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700775 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800776 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -0700777 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800778 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -0700779}
780
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800781enum latency_range {
782 lowest_latency = 0,
783 low_latency = 1,
784 bulk_latency = 2,
785 latency_invalid = 255
786};
787
788/**
789 * ixgbe_update_itr - update the dynamic ITR value based on statistics
790 * @adapter: pointer to adapter
791 * @eitr: eitr setting (ints per sec) to give last timeslice
792 * @itr_setting: current throttle rate in ints/second
793 * @packets: the number of packets during this measurement interval
794 * @bytes: the number of bytes during this measurement interval
795 *
796 * Stores a new ITR value based on packets and byte
797 * counts during the last interrupt. The advantage of per interrupt
798 * computation is faster updates and more accurate ITR for the current
799 * traffic pattern. Constants in this function were computed
800 * based on theoretical maximum wire speed and thresholds were set based
801 * on testing data as well as attempting to minimize response time
802 * while increasing bulk throughput.
803 * this functionality is controlled by the InterruptThrottleRate module
804 * parameter (see ixgbe_param.c)
805 **/
806static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700807 u32 eitr, u8 itr_setting,
808 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800809{
810 unsigned int retval = itr_setting;
811 u32 timepassed_us;
812 u64 bytes_perint;
813
814 if (packets == 0)
815 goto update_itr_done;
816
817
818 /* simple throttlerate management
819 * 0-20MB/s lowest (100000 ints/s)
820 * 20-100MB/s low (20000 ints/s)
821 * 100-1249MB/s bulk (8000 ints/s)
822 */
823 /* what was last interrupt timeslice? */
824 timepassed_us = 1000000/eitr;
825 bytes_perint = bytes / timepassed_us; /* bytes/usec */
826
827 switch (itr_setting) {
828 case lowest_latency:
829 if (bytes_perint > adapter->eitr_low)
830 retval = low_latency;
831 break;
832 case low_latency:
833 if (bytes_perint > adapter->eitr_high)
834 retval = bulk_latency;
835 else if (bytes_perint <= adapter->eitr_low)
836 retval = lowest_latency;
837 break;
838 case bulk_latency:
839 if (bytes_perint <= adapter->eitr_high)
840 retval = low_latency;
841 break;
842 }
843
844update_itr_done:
845 return retval;
846}
847
848static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
849{
850 struct ixgbe_adapter *adapter = q_vector->adapter;
851 struct ixgbe_hw *hw = &adapter->hw;
852 u32 new_itr;
853 u8 current_itr, ret_itr;
854 int i, r_idx, v_idx = ((void *)q_vector - (void *)(adapter->q_vector)) /
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700855 sizeof(struct ixgbe_q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800856 struct ixgbe_ring *rx_ring, *tx_ring;
857
858 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
859 for (i = 0; i < q_vector->txr_count; i++) {
860 tx_ring = &(adapter->tx_ring[r_idx]);
861 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700862 q_vector->tx_itr,
863 tx_ring->total_packets,
864 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800865 /* if the result for this queue would decrease interrupt
866 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700867 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700868 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800869 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700870 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800871 }
872
873 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
874 for (i = 0; i < q_vector->rxr_count; i++) {
875 rx_ring = &(adapter->rx_ring[r_idx]);
876 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700877 q_vector->rx_itr,
878 rx_ring->total_packets,
879 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800880 /* if the result for this queue would decrease interrupt
881 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700882 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700883 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800884 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700885 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800886 }
887
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -0700888 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800889
890 switch (current_itr) {
891 /* counts and packets in update_itr are dependent on these numbers */
892 case lowest_latency:
893 new_itr = 100000;
894 break;
895 case low_latency:
896 new_itr = 20000; /* aka hwitr = ~200 */
897 break;
898 case bulk_latency:
899 default:
900 new_itr = 8000;
901 break;
902 }
903
904 if (new_itr != q_vector->eitr) {
905 u32 itr_reg;
906 /* do an exponential smoothing */
907 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
908 q_vector->eitr = new_itr;
909 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
910 /* must write high and low 16 bits to reset counter */
911 DPRINTK(TX_ERR, DEBUG, "writing eitr(%d): %08X\n", v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700912 itr_reg);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800913 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg | (itr_reg)<<16);
914 }
915
916 return;
917}
918
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700919static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
920{
921 struct ixgbe_hw *hw = &adapter->hw;
922
923 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
924 (eicr & IXGBE_EICR_GPI_SDP1)) {
925 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
926 /* write to clear the interrupt */
927 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
928 }
929}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -0700930
931static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
932{
933 struct ixgbe_hw *hw = &adapter->hw;
934
935 adapter->lsc_int++;
936 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
937 adapter->link_check_timeout = jiffies;
938 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
939 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
940 schedule_work(&adapter->watchdog_task);
941 }
942}
943
Auke Kok9a799d72007-09-15 14:07:45 -0700944static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
945{
946 struct net_device *netdev = data;
947 struct ixgbe_adapter *adapter = netdev_priv(netdev);
948 struct ixgbe_hw *hw = &adapter->hw;
949 u32 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
950
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -0700951 if (eicr & IXGBE_EICR_LSC)
952 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -0800953
Jesse Brandeburg0befdb32008-10-31 00:46:40 -0700954 ixgbe_check_fan_failure(adapter, eicr);
955
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -0800956 if (!test_bit(__IXGBE_DOWN, &adapter->state))
957 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -0700958
959 return IRQ_HANDLED;
960}
961
962static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
963{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800964 struct ixgbe_q_vector *q_vector = data;
965 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700966 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800967 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -0700968
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800969 if (!q_vector->txr_count)
970 return IRQ_HANDLED;
971
972 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
973 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700974 tx_ring = &(adapter->tx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400975#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800976 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700977 ixgbe_update_tx_dca(adapter, tx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800978#endif
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700979 tx_ring->total_bytes = 0;
980 tx_ring->total_packets = 0;
981 ixgbe_clean_tx_irq(adapter, tx_ring);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800982 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700983 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800984 }
985
Auke Kok9a799d72007-09-15 14:07:45 -0700986 return IRQ_HANDLED;
987}
988
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800989/**
990 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
991 * @irq: unused
992 * @data: pointer to our q_vector struct for this interrupt vector
993 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700994static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
995{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800996 struct ixgbe_q_vector *q_vector = data;
997 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700998 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800999 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001000 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001001
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001002 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001003 for (i = 0; i < q_vector->rxr_count; i++) {
1004 rx_ring = &(adapter->rx_ring[r_idx]);
1005 rx_ring->total_bytes = 0;
1006 rx_ring->total_packets = 0;
1007 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1008 r_idx + 1);
1009 }
1010
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001011 if (!q_vector->rxr_count)
1012 return IRQ_HANDLED;
1013
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001014 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001015 rx_ring = &(adapter->rx_ring[r_idx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001016 /* disable interrupts on this vector only */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001017 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rx_ring->v_idx);
Ben Hutchings288379f2009-01-19 16:43:59 -08001018 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001019
Auke Kok9a799d72007-09-15 14:07:45 -07001020 return IRQ_HANDLED;
1021}
1022
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001023static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1024{
1025 ixgbe_msix_clean_rx(irq, data);
1026 ixgbe_msix_clean_tx(irq, data);
1027
1028 return IRQ_HANDLED;
1029}
1030
1031/**
1032 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1033 * @napi: napi struct with our devices info in it
1034 * @budget: amount of work driver is allowed to do this pass, in packets
1035 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001036 * This function is optimized for cleaning one queue only on a single
1037 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001038 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001039static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1040{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001041 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001042 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001043 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001044 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001045 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001046 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001047
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001048 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001049 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001050#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001051 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001052 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001053#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001054
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001055 ixgbe_clean_rx_irq(adapter, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001056
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001057 /* If all Rx work done, exit the polling mode */
1058 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001059 napi_complete(napi);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001060 if (adapter->itr_setting & 3)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001061 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001062 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001063 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rx_ring->v_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07001064 }
1065
1066 return work_done;
1067}
1068
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001069/**
1070 * ixgbe_clean_rxonly_many - msix (aka one shot) rx clean routine
1071 * @napi: napi struct with our devices info in it
1072 * @budget: amount of work driver is allowed to do this pass, in packets
1073 *
1074 * This function will clean more than one rx queue associated with a
1075 * q_vector.
1076 **/
1077static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget)
1078{
1079 struct ixgbe_q_vector *q_vector =
1080 container_of(napi, struct ixgbe_q_vector, napi);
1081 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001082 struct ixgbe_ring *rx_ring = NULL;
1083 int work_done = 0, i;
1084 long r_idx;
1085 u16 enable_mask = 0;
1086
1087 /* attempt to distribute budget to each queue fairly, but don't allow
1088 * the budget to go below 1 because we'll exit polling */
1089 budget /= (q_vector->rxr_count ?: 1);
1090 budget = max(budget, 1);
1091 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1092 for (i = 0; i < q_vector->rxr_count; i++) {
1093 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001094#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001095 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1096 ixgbe_update_rx_dca(adapter, rx_ring);
1097#endif
1098 ixgbe_clean_rx_irq(adapter, rx_ring, &work_done, budget);
1099 enable_mask |= rx_ring->v_idx;
1100 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1101 r_idx + 1);
1102 }
1103
1104 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1105 rx_ring = &(adapter->rx_ring[r_idx]);
1106 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001107 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001108 napi_complete(napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001109 if (adapter->itr_setting & 3)
1110 ixgbe_set_itr_msix(q_vector);
1111 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1112 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, enable_mask);
1113 return 0;
1114 }
1115
1116 return work_done;
1117}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001118static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001119 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001120{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001121 a->q_vector[v_idx].adapter = a;
1122 set_bit(r_idx, a->q_vector[v_idx].rxr_idx);
1123 a->q_vector[v_idx].rxr_count++;
1124 a->rx_ring[r_idx].v_idx = 1 << v_idx;
1125}
Auke Kok9a799d72007-09-15 14:07:45 -07001126
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001127static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001128 int r_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001129{
1130 a->q_vector[v_idx].adapter = a;
1131 set_bit(r_idx, a->q_vector[v_idx].txr_idx);
1132 a->q_vector[v_idx].txr_count++;
1133 a->tx_ring[r_idx].v_idx = 1 << v_idx;
1134}
Auke Kok9a799d72007-09-15 14:07:45 -07001135
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001136/**
1137 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1138 * @adapter: board private structure to initialize
1139 * @vectors: allotted vector count for descriptor rings
1140 *
1141 * This function maps descriptor rings to the queue-specific vectors
1142 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1143 * one vector per ring/queue, but on a constrained vector budget, we
1144 * group the rings as "efficiently" as possible. You would add new
1145 * mapping configurations in here.
1146 **/
1147static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001148 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001149{
1150 int v_start = 0;
1151 int rxr_idx = 0, txr_idx = 0;
1152 int rxr_remaining = adapter->num_rx_queues;
1153 int txr_remaining = adapter->num_tx_queues;
1154 int i, j;
1155 int rqpv, tqpv;
1156 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001157
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001158 /* No mapping required if MSI-X is disabled. */
1159 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001160 goto out;
1161
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001162 /*
1163 * The ideal configuration...
1164 * We have enough vectors to map one per queue.
1165 */
1166 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1167 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1168 map_vector_to_rxq(adapter, v_start, rxr_idx);
1169
1170 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1171 map_vector_to_txq(adapter, v_start, txr_idx);
1172
1173 goto out;
1174 }
1175
1176 /*
1177 * If we don't have enough vectors for a 1-to-1
1178 * mapping, we'll have to group them so there are
1179 * multiple queues per vector.
1180 */
1181 /* Re-adjusting *qpv takes care of the remainder. */
1182 for (i = v_start; i < vectors; i++) {
1183 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1184 for (j = 0; j < rqpv; j++) {
1185 map_vector_to_rxq(adapter, i, rxr_idx);
1186 rxr_idx++;
1187 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001188 }
Auke Kok9a799d72007-09-15 14:07:45 -07001189 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001190 for (i = v_start; i < vectors; i++) {
1191 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1192 for (j = 0; j < tqpv; j++) {
1193 map_vector_to_txq(adapter, i, txr_idx);
1194 txr_idx++;
1195 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001196 }
Auke Kok9a799d72007-09-15 14:07:45 -07001197 }
1198
Auke Kok9a799d72007-09-15 14:07:45 -07001199out:
Auke Kok9a799d72007-09-15 14:07:45 -07001200 return err;
1201}
1202
1203/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001204 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1205 * @adapter: board private structure
1206 *
1207 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1208 * interrupts from the kernel.
1209 **/
1210static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1211{
1212 struct net_device *netdev = adapter->netdev;
1213 irqreturn_t (*handler)(int, void *);
1214 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001215 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001216
1217 /* Decrement for Other and TCP Timer vectors */
1218 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1219
1220 /* Map the Tx/Rx rings to the vectors we were allotted. */
1221 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1222 if (err)
1223 goto out;
1224
1225#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001226 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1227 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001228 for (vector = 0; vector < q_vectors; vector++) {
1229 handler = SET_HANDLER(&adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001230
1231 if(handler == &ixgbe_msix_clean_rx) {
1232 sprintf(adapter->name[vector], "%s-%s-%d",
1233 netdev->name, "rx", ri++);
1234 }
1235 else if(handler == &ixgbe_msix_clean_tx) {
1236 sprintf(adapter->name[vector], "%s-%s-%d",
1237 netdev->name, "tx", ti++);
1238 }
1239 else
1240 sprintf(adapter->name[vector], "%s-%s-%d",
1241 netdev->name, "TxRx", vector);
1242
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001243 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001244 handler, 0, adapter->name[vector],
1245 &(adapter->q_vector[vector]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001246 if (err) {
1247 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001248 "request_irq failed for MSIX interrupt "
1249 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001250 goto free_queue_irqs;
1251 }
1252 }
1253
1254 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1255 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001256 &ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001257 if (err) {
1258 DPRINTK(PROBE, ERR,
1259 "request_irq for msix_lsc failed: %d\n", err);
1260 goto free_queue_irqs;
1261 }
1262
1263 return 0;
1264
1265free_queue_irqs:
1266 for (i = vector - 1; i >= 0; i--)
1267 free_irq(adapter->msix_entries[--vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001268 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001269 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1270 pci_disable_msix(adapter->pdev);
1271 kfree(adapter->msix_entries);
1272 adapter->msix_entries = NULL;
1273out:
1274 return err;
1275}
1276
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001277static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1278{
1279 struct ixgbe_hw *hw = &adapter->hw;
1280 struct ixgbe_q_vector *q_vector = adapter->q_vector;
1281 u8 current_itr;
1282 u32 new_itr = q_vector->eitr;
1283 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1284 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1285
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001286 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001287 q_vector->tx_itr,
1288 tx_ring->total_packets,
1289 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001290 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001291 q_vector->rx_itr,
1292 rx_ring->total_packets,
1293 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001294
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001295 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001296
1297 switch (current_itr) {
1298 /* counts and packets in update_itr are dependent on these numbers */
1299 case lowest_latency:
1300 new_itr = 100000;
1301 break;
1302 case low_latency:
1303 new_itr = 20000; /* aka hwitr = ~200 */
1304 break;
1305 case bulk_latency:
1306 new_itr = 8000;
1307 break;
1308 default:
1309 break;
1310 }
1311
1312 if (new_itr != q_vector->eitr) {
1313 u32 itr_reg;
1314 /* do an exponential smoothing */
1315 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
1316 q_vector->eitr = new_itr;
1317 itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr);
1318 /* must write high and low 16 bits to reset counter */
1319 IXGBE_WRITE_REG(hw, IXGBE_EITR(0), itr_reg | (itr_reg)<<16);
1320 }
1321
1322 return;
1323}
1324
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001325/**
1326 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1327 * @adapter: board private structure
1328 **/
1329static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1330{
1331 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1332 IXGBE_WRITE_FLUSH(&adapter->hw);
1333 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1334 int i;
1335 for (i = 0; i < adapter->num_msix_vectors; i++)
1336 synchronize_irq(adapter->msix_entries[i].vector);
1337 } else {
1338 synchronize_irq(adapter->pdev->irq);
1339 }
1340}
1341
1342/**
1343 * ixgbe_irq_enable - Enable default interrupt generation settings
1344 * @adapter: board private structure
1345 **/
1346static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1347{
1348 u32 mask;
1349 mask = IXGBE_EIMS_ENABLE_MASK;
David S. Miller6ab33d52008-11-20 16:44:00 -08001350 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1351 mask |= IXGBE_EIMS_GPI_SDP1;
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001352 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1353 IXGBE_WRITE_FLUSH(&adapter->hw);
1354}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001355
1356/**
1357 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001358 * @irq: interrupt number
1359 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001360 **/
1361static irqreturn_t ixgbe_intr(int irq, void *data)
1362{
1363 struct net_device *netdev = data;
1364 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1365 struct ixgbe_hw *hw = &adapter->hw;
1366 u32 eicr;
1367
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001368 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1369 * therefore no explict interrupt disable is necessary */
1370 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001371 if (!eicr) {
1372 /* shared interrupt alert!
1373 * make sure interrupts are enabled because the read will
1374 * have disabled interrupts due to EIAM */
1375 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001376 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001377 }
Auke Kok9a799d72007-09-15 14:07:45 -07001378
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001379 if (eicr & IXGBE_EICR_LSC)
1380 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001381
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001382 ixgbe_check_fan_failure(adapter, eicr);
1383
Ben Hutchings288379f2009-01-19 16:43:59 -08001384 if (napi_schedule_prep(&adapter->q_vector[0].napi)) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001385 adapter->tx_ring[0].total_packets = 0;
1386 adapter->tx_ring[0].total_bytes = 0;
1387 adapter->rx_ring[0].total_packets = 0;
1388 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001389 /* would disable interrupts here but EIAM disabled it */
Ben Hutchings288379f2009-01-19 16:43:59 -08001390 __napi_schedule(&adapter->q_vector[0].napi);
Auke Kok9a799d72007-09-15 14:07:45 -07001391 }
1392
1393 return IRQ_HANDLED;
1394}
1395
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001396static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1397{
1398 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1399
1400 for (i = 0; i < q_vectors; i++) {
1401 struct ixgbe_q_vector *q_vector = &adapter->q_vector[i];
1402 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1403 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1404 q_vector->rxr_count = 0;
1405 q_vector->txr_count = 0;
1406 }
1407}
1408
Auke Kok9a799d72007-09-15 14:07:45 -07001409/**
1410 * ixgbe_request_irq - initialize interrupts
1411 * @adapter: board private structure
1412 *
1413 * Attempts to configure interrupts using the best available
1414 * capabilities of the hardware and kernel.
1415 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001416static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001417{
1418 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001419 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001420
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001421 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1422 err = ixgbe_request_msix_irqs(adapter);
1423 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1424 err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001425 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001426 } else {
1427 err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001428 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001429 }
1430
Auke Kok9a799d72007-09-15 14:07:45 -07001431 if (err)
1432 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1433
Auke Kok9a799d72007-09-15 14:07:45 -07001434 return err;
1435}
1436
1437static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1438{
1439 struct net_device *netdev = adapter->netdev;
1440
1441 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001442 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001443
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001444 q_vectors = adapter->num_msix_vectors;
1445
1446 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001447 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001448
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001449 i--;
1450 for (; i >= 0; i--) {
1451 free_irq(adapter->msix_entries[i].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001452 &(adapter->q_vector[i]));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001453 }
1454
1455 ixgbe_reset_q_vectors(adapter);
1456 } else {
1457 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001458 }
1459}
1460
1461/**
Auke Kok9a799d72007-09-15 14:07:45 -07001462 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1463 *
1464 **/
1465static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1466{
Auke Kok9a799d72007-09-15 14:07:45 -07001467 struct ixgbe_hw *hw = &adapter->hw;
1468
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001469 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001470 EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001471
1472 ixgbe_set_ivar(adapter, IXGBE_IVAR_RX_QUEUE(0), 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001473 ixgbe_set_ivar(adapter, IXGBE_IVAR_TX_QUEUE(0), 0);
1474
1475 map_vector_to_rxq(adapter, 0, 0);
1476 map_vector_to_txq(adapter, 0, 0);
1477
1478 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001479}
1480
1481/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001482 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001483 * @adapter: board private structure
1484 *
1485 * Configure the Tx unit of the MAC after a reset.
1486 **/
1487static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1488{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001489 u64 tdba, tdwba;
Auke Kok9a799d72007-09-15 14:07:45 -07001490 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001491 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001492
1493 /* Setup the HW Tx Head and Tail descriptor pointers */
1494 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001495 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1496 j = ring->reg_idx;
1497 tdba = ring->dma;
1498 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001499 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001500 (tdba & DMA_32BIT_MASK));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001501 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001502 tdwba = ring->dma +
1503 (ring->count * sizeof(union ixgbe_adv_tx_desc));
1504 tdwba |= IXGBE_TDWBAL_HEAD_WB_ENABLE;
1505 IXGBE_WRITE_REG(hw, IXGBE_TDWBAL(j), tdwba & DMA_32BIT_MASK);
1506 IXGBE_WRITE_REG(hw, IXGBE_TDWBAH(j), (tdwba >> 32));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001507 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1508 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1509 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1510 adapter->tx_ring[i].head = IXGBE_TDH(j);
1511 adapter->tx_ring[i].tail = IXGBE_TDT(j);
1512 /* Disable Tx Head Writeback RO bit, since this hoses
1513 * bookkeeping if things aren't delivered in order.
1514 */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001515 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001516 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001517 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001518 }
Auke Kok9a799d72007-09-15 14:07:45 -07001519}
1520
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001521#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07001522
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001523static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index)
1524{
1525 struct ixgbe_ring *rx_ring;
1526 u32 srrctl;
1527 int queue0;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001528 unsigned long mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001529
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001530 /* program one srrctl register per VMDq index */
1531 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
1532 long shift, len;
1533 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1534 len = sizeof(adapter->ring_feature[RING_F_VMDQ].mask) * 8;
1535 shift = find_first_bit(&mask, len);
1536 queue0 = index & mask;
1537 index = (index & mask) >> shift;
1538 /* program one srrctl per RSS queue since RDRXCTL.MVMEN is enabled */
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001539 } else {
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001540 mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask;
1541 queue0 = index & mask;
1542 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001543 }
Alexander Duyck3be1adf2008-08-30 00:29:10 -07001544
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001545 rx_ring = &adapter->rx_ring[queue0];
1546
1547 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
1548
1549 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
1550 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
1551
1552 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
1553 srrctl |= IXGBE_RXBUFFER_2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1554 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
1555 srrctl |= ((IXGBE_RX_HDR_SIZE <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001556 IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
1557 IXGBE_SRRCTL_BSIZEHDR_MASK);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001558 } else {
1559 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
1560
1561 if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE)
1562 srrctl |= IXGBE_RXBUFFER_2048 >>
1563 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1564 else
1565 srrctl |= rx_ring->rx_buf_len >>
1566 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
1567 }
1568 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
1569}
1570
Auke Kok9a799d72007-09-15 14:07:45 -07001571/**
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001572 * ixgbe_get_skb_hdr - helper function for LRO header processing
1573 * @skb: pointer to sk_buff to be added to LRO packet
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001574 * @iphdr: pointer to ip header structure
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001575 * @tcph: pointer to tcp header structure
1576 * @hdr_flags: pointer to header flags
1577 * @priv: private data
1578 **/
1579static int ixgbe_get_skb_hdr(struct sk_buff *skb, void **iphdr, void **tcph,
1580 u64 *hdr_flags, void *priv)
1581{
1582 union ixgbe_adv_rx_desc *rx_desc = priv;
1583
1584 /* Verify that this is a valid IPv4 TCP packet */
Jesse Brandeburge9990a92008-08-26 04:27:24 -07001585 if (!((ixgbe_get_pkt_info(rx_desc) & IXGBE_RXDADV_PKTTYPE_IPV4) &&
1586 (ixgbe_get_pkt_info(rx_desc) & IXGBE_RXDADV_PKTTYPE_TCP)))
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001587 return -1;
1588
1589 /* Set network headers */
1590 skb_reset_network_header(skb);
1591 skb_set_transport_header(skb, ip_hdrlen(skb));
1592 *iphdr = ip_hdr(skb);
1593 *tcph = tcp_hdr(skb);
1594 *hdr_flags = LRO_IPV4 | LRO_TCP;
1595 return 0;
1596}
1597
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001598#define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001599 (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001600
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001601/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001602 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001603 * @adapter: board private structure
1604 *
1605 * Configure the Rx unit of the MAC after a reset.
1606 **/
1607static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
1608{
1609 u64 rdba;
1610 struct ixgbe_hw *hw = &adapter->hw;
1611 struct net_device *netdev = adapter->netdev;
1612 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001613 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07001614 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001615 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
1616 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
1617 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07001618 u32 fctrl, hlreg0;
Auke Kok9a799d72007-09-15 14:07:45 -07001619 u32 pages;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001620 u32 reta = 0, mrqc;
1621 u32 rdrxctl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001622 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07001623
1624 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001625 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07001626
1627 /* Set the RX buffer length according to the mode */
1628 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001629 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001630 } else {
1631 if (netdev->mtu <= ETH_DATA_LEN)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001632 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07001633 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001634 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07001635 }
1636
1637 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
1638 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001639 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
Auke Kok9a799d72007-09-15 14:07:45 -07001640 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
1641
1642 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1643 if (adapter->netdev->mtu <= ETH_DATA_LEN)
1644 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
1645 else
1646 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
1647 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1648
1649 pages = PAGE_USE_COUNT(adapter->netdev->mtu);
1650
Auke Kok9a799d72007-09-15 14:07:45 -07001651 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1652 /* disable receives while setting up the descriptors */
1653 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
1654 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
1655
1656 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1657 * the Base and Length of the Rx Descriptor Ring */
1658 for (i = 0; i < adapter->num_rx_queues; i++) {
1659 rdba = adapter->rx_ring[i].dma;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001660 j = adapter->rx_ring[i].reg_idx;
1661 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_32BIT_MASK));
1662 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
1663 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
1664 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
1665 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
1666 adapter->rx_ring[i].head = IXGBE_RDH(j);
1667 adapter->rx_ring[i].tail = IXGBE_RDT(j);
1668 adapter->rx_ring[i].rx_buf_len = rx_buf_len;
Jesse Brandeburge9990a92008-08-26 04:27:24 -07001669 /* Intitial LRO Settings */
1670 adapter->rx_ring[i].lro_mgr.max_aggr = IXGBE_MAX_LRO_AGGREGATE;
1671 adapter->rx_ring[i].lro_mgr.max_desc = IXGBE_MAX_LRO_DESCRIPTORS;
1672 adapter->rx_ring[i].lro_mgr.get_skb_header = ixgbe_get_skb_hdr;
1673 adapter->rx_ring[i].lro_mgr.features = LRO_F_EXTRACT_VLAN_ID;
1674 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1675 adapter->rx_ring[i].lro_mgr.features |= LRO_F_NAPI;
1676 adapter->rx_ring[i].lro_mgr.dev = adapter->netdev;
1677 adapter->rx_ring[i].lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1678 adapter->rx_ring[i].lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001679
1680 ixgbe_configure_srrctl(adapter, j);
Auke Kok9a799d72007-09-15 14:07:45 -07001681 }
1682
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07001683 /*
1684 * For VMDq support of different descriptor types or
1685 * buffer sizes through the use of multiple SRRCTL
1686 * registers, RDRXCTL.MVMEN must be set to 1
1687 *
1688 * also, the manual doesn't mention it clearly but DCA hints
1689 * will only use queue 0's tags unless this bit is set. Side
1690 * effects of setting this bit are only that SRRCTL must be
1691 * fully programmed [0..15]
1692 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08001693 if (adapter->flags &
1694 (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_VMDQ_ENABLED)) {
1695 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
1696 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
1697 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
1698 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001699
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001700 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07001701 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001702 for (i = 0, j = 0; i < 128; i++, j++) {
1703 if (j == adapter->ring_feature[RING_F_RSS].indices)
1704 j = 0;
1705 /* reta = 4-byte sliding window of
1706 * 0x00..(indices-1)(indices-1)00..etc. */
1707 reta = (reta << 8) | (j * 0x11);
1708 if ((i & 3) == 3)
1709 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07001710 }
1711
1712 /* Fill out hash function seeds */
1713 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001714 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07001715
1716 mrqc = IXGBE_MRQC_RSSEN
1717 /* Perform hash on these packet types */
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001718 | IXGBE_MRQC_RSS_FIELD_IPV4
1719 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
1720 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
1721 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_TCP
1722 | IXGBE_MRQC_RSS_FIELD_IPV6_EX
1723 | IXGBE_MRQC_RSS_FIELD_IPV6
1724 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
1725 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP
1726 | IXGBE_MRQC_RSS_FIELD_IPV6_EX_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07001727 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Auke Kok9a799d72007-09-15 14:07:45 -07001728 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001729
1730 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
1731
1732 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
1733 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
1734 /* Disable indicating checksum in descriptor, enables
1735 * RSS hash */
1736 rxcsum |= IXGBE_RXCSUM_PCSD;
1737 }
1738 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
1739 /* Enable IPv4 payload checksum for UDP fragments
1740 * if PCSD is not set */
1741 rxcsum |= IXGBE_RXCSUM_IPPCSE;
1742 }
1743
1744 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
Auke Kok9a799d72007-09-15 14:07:45 -07001745}
1746
Auke Kok9a799d72007-09-15 14:07:45 -07001747static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1748{
1749 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001750 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001751
1752 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001753 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07001754}
1755
1756static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1757{
1758 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001759 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07001760
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001761 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1762 ixgbe_irq_disable(adapter);
1763
Auke Kok9a799d72007-09-15 14:07:45 -07001764 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001765
1766 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1767 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001768
1769 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001770 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07001771}
1772
Don Skidmore068c89b2009-01-19 16:54:36 -08001773static void ixgbe_vlan_rx_register(struct net_device *netdev,
1774 struct vlan_group *grp)
1775{
1776 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1777 u32 ctrl;
1778
1779 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1780 ixgbe_irq_disable(adapter);
1781 adapter->vlgrp = grp;
1782
1783 /*
1784 * For a DCB driver, always enable VLAN tag stripping so we can
1785 * still receive traffic from a DCB-enabled host even if we're
1786 * not in DCB mode.
1787 */
1788 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1789 ctrl |= IXGBE_VLNCTRL_VME;
1790 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1791 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1792 ixgbe_vlan_rx_add_vid(netdev, 0);
1793
1794 if (grp) {
1795 /* enable VLAN tag insert/strip */
1796 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
1797 ctrl |= IXGBE_VLNCTRL_VME;
1798 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
1799 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
1800 }
1801
1802 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1803 ixgbe_irq_enable(adapter);
1804}
1805
Auke Kok9a799d72007-09-15 14:07:45 -07001806static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
1807{
1808 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1809
1810 if (adapter->vlgrp) {
1811 u16 vid;
1812 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1813 if (!vlan_group_get_device(adapter->vlgrp, vid))
1814 continue;
1815 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
1816 }
1817 }
1818}
1819
Christopher Leech2c5645c2008-08-26 04:27:02 -07001820static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
1821{
1822 struct dev_mc_list *mc_ptr;
1823 u8 *addr = *mc_addr_ptr;
1824 *vmdq = 0;
1825
1826 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
1827 if (mc_ptr->next)
1828 *mc_addr_ptr = mc_ptr->next->dmi_addr;
1829 else
1830 *mc_addr_ptr = NULL;
1831
1832 return addr;
1833}
1834
Auke Kok9a799d72007-09-15 14:07:45 -07001835/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07001836 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07001837 * @netdev: network interface device structure
1838 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07001839 * The set_rx_method entry point is called whenever the unicast/multicast
1840 * address list or the network interface flags are updated. This routine is
1841 * responsible for configuring the hardware for proper unicast, multicast and
1842 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07001843 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07001844static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07001845{
1846 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1847 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07001848 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001849 u8 *addr_list = NULL;
1850 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001851
1852 /* Check for Promiscuous and All Multicast modes */
1853
1854 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07001855 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07001856
1857 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07001858 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001859 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07001860 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07001861 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07001862 if (netdev->flags & IFF_ALLMULTI) {
1863 fctrl |= IXGBE_FCTRL_MPE;
1864 fctrl &= ~IXGBE_FCTRL_UPE;
1865 } else {
1866 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
1867 }
Alexander Duyck3d016252008-08-26 18:30:04 -07001868 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07001869 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001870 }
1871
1872 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07001873 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07001874
Christopher Leech2c5645c2008-08-26 04:27:02 -07001875 /* reprogram secondary unicast list */
1876 addr_count = netdev->uc_count;
1877 if (addr_count)
1878 addr_list = netdev->uc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001879 hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count,
1880 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07001881
Christopher Leech2c5645c2008-08-26 04:27:02 -07001882 /* reprogram multicast list */
1883 addr_count = netdev->mc_count;
1884 if (addr_count)
1885 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07001886 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
1887 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07001888}
1889
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001890static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
1891{
1892 int q_idx;
1893 struct ixgbe_q_vector *q_vector;
1894 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1895
1896 /* legacy and MSI only use one vector */
1897 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1898 q_vectors = 1;
1899
1900 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001901 struct napi_struct *napi;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001902 q_vector = &adapter->q_vector[q_idx];
1903 if (!q_vector->rxr_count)
1904 continue;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001905 napi = &q_vector->napi;
1906 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) &&
1907 (q_vector->rxr_count > 1))
1908 napi->poll = &ixgbe_clean_rxonly_many;
1909
1910 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001911 }
1912}
1913
1914static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
1915{
1916 int q_idx;
1917 struct ixgbe_q_vector *q_vector;
1918 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1919
1920 /* legacy and MSI only use one vector */
1921 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
1922 q_vectors = 1;
1923
1924 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
1925 q_vector = &adapter->q_vector[q_idx];
1926 if (!q_vector->rxr_count)
1927 continue;
1928 napi_disable(&q_vector->napi);
1929 }
1930}
1931
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08001932#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08001933/*
1934 * ixgbe_configure_dcb - Configure DCB hardware
1935 * @adapter: ixgbe adapter struct
1936 *
1937 * This is called by the driver on open to configure the DCB hardware.
1938 * This is also called by the gennetlink interface when reconfiguring
1939 * the DCB state.
1940 */
1941static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
1942{
1943 struct ixgbe_hw *hw = &adapter->hw;
1944 u32 txdctl, vlnctrl;
1945 int i, j;
1946
1947 ixgbe_dcb_check_config(&adapter->dcb_cfg);
1948 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
1949 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
1950
1951 /* reconfigure the hardware */
1952 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
1953
1954 for (i = 0; i < adapter->num_tx_queues; i++) {
1955 j = adapter->tx_ring[i].reg_idx;
1956 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
1957 /* PThresh workaround for Tx hang with DFP enabled. */
1958 txdctl |= 32;
1959 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
1960 }
1961 /* Enable VLAN tag insert/strip */
1962 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
1963 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
1964 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
1965 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
1966 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
1967}
1968
1969#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001970static void ixgbe_configure(struct ixgbe_adapter *adapter)
1971{
1972 struct net_device *netdev = adapter->netdev;
1973 int i;
1974
Christopher Leech2c5645c2008-08-26 04:27:02 -07001975 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001976
1977 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08001978#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08001979 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
1980 netif_set_gso_max_size(netdev, 32768);
1981 ixgbe_configure_dcb(adapter);
1982 } else {
1983 netif_set_gso_max_size(netdev, 65536);
1984 }
1985#else
1986 netif_set_gso_max_size(netdev, 65536);
1987#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001988
1989 ixgbe_configure_tx(adapter);
1990 ixgbe_configure_rx(adapter);
1991 for (i = 0; i < adapter->num_rx_queues; i++)
1992 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001993 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07001994}
1995
1996static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
1997{
1998 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07001999 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002000 int i, j = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002001 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002002 u32 txdctl, rxdctl, mhadd;
2003 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002004
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002005 ixgbe_get_hw_control(adapter);
2006
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002007 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2008 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002009 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2010 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002011 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002012 } else {
2013 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002014 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002015 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002016 /* XXX: to interrupt immediately for EICS writes, enable this */
2017 /* gpie |= IXGBE_GPIE_EIMEN; */
2018 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2019 }
2020
2021 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2022 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2023 * specifically only auto mask tx and rx interrupts */
2024 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002025 }
2026
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002027 /* Enable fan failure interrupt if media type is copper */
2028 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2029 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2030 gpie |= IXGBE_SDP1_GPIEN;
2031 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2032 }
2033
Auke Kok9a799d72007-09-15 14:07:45 -07002034 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002035 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2036 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2037 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2038
2039 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2040 }
2041
2042 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002043 j = adapter->tx_ring[i].reg_idx;
2044 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002045 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2046 txdctl |= (8 << 16);
Auke Kok9a799d72007-09-15 14:07:45 -07002047 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002048 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002049 }
2050
2051 for (i = 0; i < adapter->num_rx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002052 j = adapter->rx_ring[i].reg_idx;
2053 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2054 /* enable PTHRESH=32 descriptors (half the internal cache)
2055 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2056 * this also removes a pesky rx_no_buffer_count increment */
2057 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002058 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002059 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002060 }
2061 /* enable all receives */
2062 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2063 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2064 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxdctl);
2065
2066 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2067 ixgbe_configure_msix(adapter);
2068 else
2069 ixgbe_configure_msi_and_legacy(adapter);
2070
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08002071 ixgbe_napi_add_all(adapter);
2072
Auke Kok9a799d72007-09-15 14:07:45 -07002073 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002074 ixgbe_napi_enable_all(adapter);
2075
2076 /* clear any pending interrupts, may auto mask */
2077 IXGBE_READ_REG(hw, IXGBE_EICR);
2078
Auke Kok9a799d72007-09-15 14:07:45 -07002079 ixgbe_irq_enable(adapter);
2080
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002081 /* enable transmits */
2082 netif_tx_start_all_queues(netdev);
2083
Auke Kok9a799d72007-09-15 14:07:45 -07002084 /* bring the link up in the watchdog, this could race with our first
2085 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002086 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2087 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002088 mod_timer(&adapter->watchdog_timer, jiffies);
2089 return 0;
2090}
2091
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002092void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2093{
2094 WARN_ON(in_interrupt());
2095 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2096 msleep(1);
2097 ixgbe_down(adapter);
2098 ixgbe_up(adapter);
2099 clear_bit(__IXGBE_RESETTING, &adapter->state);
2100}
2101
Auke Kok9a799d72007-09-15 14:07:45 -07002102int ixgbe_up(struct ixgbe_adapter *adapter)
2103{
2104 /* hardware has been reset, we need to reload some things */
2105 ixgbe_configure(adapter);
2106
2107 return ixgbe_up_complete(adapter);
2108}
2109
2110void ixgbe_reset(struct ixgbe_adapter *adapter)
2111{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002112 struct ixgbe_hw *hw = &adapter->hw;
2113 if (hw->mac.ops.init_hw(hw))
2114 dev_err(&adapter->pdev->dev, "Hardware Error\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002115
2116 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002117 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002118
2119}
2120
Auke Kok9a799d72007-09-15 14:07:45 -07002121/**
2122 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2123 * @adapter: board private structure
2124 * @rx_ring: ring to free buffers from
2125 **/
2126static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002127 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002128{
2129 struct pci_dev *pdev = adapter->pdev;
2130 unsigned long size;
2131 unsigned int i;
2132
2133 /* Free all the Rx ring sk_buffs */
2134
2135 for (i = 0; i < rx_ring->count; i++) {
2136 struct ixgbe_rx_buffer *rx_buffer_info;
2137
2138 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2139 if (rx_buffer_info->dma) {
2140 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002141 rx_ring->rx_buf_len,
2142 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002143 rx_buffer_info->dma = 0;
2144 }
2145 if (rx_buffer_info->skb) {
2146 dev_kfree_skb(rx_buffer_info->skb);
2147 rx_buffer_info->skb = NULL;
2148 }
2149 if (!rx_buffer_info->page)
2150 continue;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002151 pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2,
2152 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002153 rx_buffer_info->page_dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002154 put_page(rx_buffer_info->page);
2155 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002156 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002157 }
2158
2159 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2160 memset(rx_ring->rx_buffer_info, 0, size);
2161
2162 /* Zero out the descriptor ring */
2163 memset(rx_ring->desc, 0, rx_ring->size);
2164
2165 rx_ring->next_to_clean = 0;
2166 rx_ring->next_to_use = 0;
2167
2168 writel(0, adapter->hw.hw_addr + rx_ring->head);
2169 writel(0, adapter->hw.hw_addr + rx_ring->tail);
2170}
2171
2172/**
2173 * ixgbe_clean_tx_ring - Free Tx Buffers
2174 * @adapter: board private structure
2175 * @tx_ring: ring to be cleaned
2176 **/
2177static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002178 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002179{
2180 struct ixgbe_tx_buffer *tx_buffer_info;
2181 unsigned long size;
2182 unsigned int i;
2183
2184 /* Free all the Tx ring sk_buffs */
2185
2186 for (i = 0; i < tx_ring->count; i++) {
2187 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2188 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2189 }
2190
2191 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2192 memset(tx_ring->tx_buffer_info, 0, size);
2193
2194 /* Zero out the descriptor ring */
2195 memset(tx_ring->desc, 0, tx_ring->size);
2196
2197 tx_ring->next_to_use = 0;
2198 tx_ring->next_to_clean = 0;
2199
2200 writel(0, adapter->hw.hw_addr + tx_ring->head);
2201 writel(0, adapter->hw.hw_addr + tx_ring->tail);
2202}
2203
2204/**
Auke Kok9a799d72007-09-15 14:07:45 -07002205 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
2206 * @adapter: board private structure
2207 **/
2208static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
2209{
2210 int i;
2211
2212 for (i = 0; i < adapter->num_rx_queues; i++)
2213 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
2214}
2215
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002216/**
2217 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
2218 * @adapter: board private structure
2219 **/
2220static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
2221{
2222 int i;
2223
2224 for (i = 0; i < adapter->num_tx_queues; i++)
2225 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
2226}
2227
Auke Kok9a799d72007-09-15 14:07:45 -07002228void ixgbe_down(struct ixgbe_adapter *adapter)
2229{
2230 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002231 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002232 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002233 u32 txdctl;
2234 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002235
2236 /* signal that we are down to the interrupt handler */
2237 set_bit(__IXGBE_DOWN, &adapter->state);
2238
2239 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002240 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2241 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07002242
2243 netif_tx_disable(netdev);
2244
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002245 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002246 msleep(10);
2247
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002248 netif_tx_stop_all_queues(netdev);
2249
Auke Kok9a799d72007-09-15 14:07:45 -07002250 ixgbe_irq_disable(adapter);
2251
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002252 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002253
Auke Kok9a799d72007-09-15 14:07:45 -07002254 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002255 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07002256
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002257 /* disable transmits in the hardware now that interrupts are off */
2258 for (i = 0; i < adapter->num_tx_queues; i++) {
2259 j = adapter->tx_ring[i].reg_idx;
2260 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2261 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
2262 (txdctl & ~IXGBE_TXDCTL_ENABLE));
2263 }
2264
Auke Kok9a799d72007-09-15 14:07:45 -07002265 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002266
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002267#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002268 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2269 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
2270 dca_remove_requester(&adapter->pdev->dev);
2271 }
2272
2273#endif
Paul Larson6f4a0e42008-06-24 17:00:56 -07002274 if (!pci_channel_offline(adapter->pdev))
2275 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002276 ixgbe_clean_all_tx_rings(adapter);
2277 ixgbe_clean_all_rx_rings(adapter);
2278
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002279#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002280 /* since we reset the hardware DCA settings were cleared */
2281 if (dca_add_requester(&adapter->pdev->dev) == 0) {
2282 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
2283 /* always use CB2 mode, difference is masked
2284 * in the CB driver */
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002285 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07002286 ixgbe_setup_dca(adapter);
2287 }
2288#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002289}
2290
Auke Kok9a799d72007-09-15 14:07:45 -07002291/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002292 * ixgbe_poll - NAPI Rx polling callback
2293 * @napi: structure for representing this polling device
2294 * @budget: how many packets driver is allowed to clean
2295 *
2296 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07002297 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002298static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002299{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002300 struct ixgbe_q_vector *q_vector = container_of(napi,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002301 struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002302 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -07002303 int tx_cleaned, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002304
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002305#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002306 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2307 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2308 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
2309 }
2310#endif
2311
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002312 tx_cleaned = ixgbe_clean_tx_irq(adapter, adapter->tx_ring);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002313 ixgbe_clean_rx_irq(adapter, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002314
David S. Millerd2c7ddd2008-01-15 22:43:24 -08002315 if (tx_cleaned)
2316 work_done = budget;
2317
David S. Miller53e52c72008-01-07 21:06:12 -08002318 /* If budget not fully consumed, exit the polling mode */
2319 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002320 napi_complete(napi);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002321 if (adapter->itr_setting & 3)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002322 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002323 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2324 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002325 }
Auke Kok9a799d72007-09-15 14:07:45 -07002326 return work_done;
2327}
2328
2329/**
2330 * ixgbe_tx_timeout - Respond to a Tx Hang
2331 * @netdev: network interface device structure
2332 **/
2333static void ixgbe_tx_timeout(struct net_device *netdev)
2334{
2335 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2336
2337 /* Do the reset outside of interrupt context */
2338 schedule_work(&adapter->reset_task);
2339}
2340
2341static void ixgbe_reset_task(struct work_struct *work)
2342{
2343 struct ixgbe_adapter *adapter;
2344 adapter = container_of(work, struct ixgbe_adapter, reset_task);
2345
Alexander Duyck2f90b862008-11-20 20:52:10 -08002346 /* If we're already down or resetting, just bail */
2347 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
2348 test_bit(__IXGBE_RESETTING, &adapter->state))
2349 return;
2350
Auke Kok9a799d72007-09-15 14:07:45 -07002351 adapter->tx_timeout_count++;
2352
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002353 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002354}
2355
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002356static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
2357{
2358 int nrq = 1, ntq = 1;
2359 int feature_mask = 0, rss_i, rss_m;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002360 int dcb_i, dcb_m;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002361
2362 /* Number of supported queues */
2363 switch (adapter->hw.mac.type) {
2364 case ixgbe_mac_82598EB:
Alexander Duyck2f90b862008-11-20 20:52:10 -08002365 dcb_i = adapter->ring_feature[RING_F_DCB].indices;
2366 dcb_m = 0;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002367 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2368 rss_m = 0;
2369 feature_mask |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002370 feature_mask |= IXGBE_FLAG_DCB_ENABLED;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002371
2372 switch (adapter->flags & feature_mask) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002373 case (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_DCB_ENABLED):
2374 dcb_m = 0x7 << 3;
2375 rss_i = min(8, rss_i);
2376 rss_m = 0x7;
2377 nrq = dcb_i * rss_i;
2378 ntq = min(MAX_TX_QUEUES, dcb_i * rss_i);
2379 break;
2380 case (IXGBE_FLAG_DCB_ENABLED):
2381 dcb_m = 0x7 << 3;
2382 nrq = dcb_i;
2383 ntq = dcb_i;
2384 break;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002385 case (IXGBE_FLAG_RSS_ENABLED):
2386 rss_m = 0xF;
2387 nrq = rss_i;
2388 ntq = rss_i;
2389 break;
2390 case 0:
2391 default:
Alexander Duyck2f90b862008-11-20 20:52:10 -08002392 dcb_i = 0;
2393 dcb_m = 0;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002394 rss_i = 0;
2395 rss_m = 0;
2396 nrq = 1;
2397 ntq = 1;
2398 break;
2399 }
2400
Alexander Duyck2f90b862008-11-20 20:52:10 -08002401 /* Sanity check, we should never have zero queues */
2402 nrq = (nrq ?:1);
2403 ntq = (ntq ?:1);
2404
2405 adapter->ring_feature[RING_F_DCB].indices = dcb_i;
2406 adapter->ring_feature[RING_F_DCB].mask = dcb_m;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002407 adapter->ring_feature[RING_F_RSS].indices = rss_i;
2408 adapter->ring_feature[RING_F_RSS].mask = rss_m;
2409 break;
2410 default:
2411 nrq = 1;
2412 ntq = 1;
2413 break;
2414 }
2415
2416 adapter->num_rx_queues = nrq;
2417 adapter->num_tx_queues = ntq;
2418}
2419
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002420static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002421 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002422{
2423 int err, vector_threshold;
2424
2425 /* We'll want at least 3 (vector_threshold):
2426 * 1) TxQ[0] Cleanup
2427 * 2) RxQ[0] Cleanup
2428 * 3) Other (Link Status Change, etc.)
2429 * 4) TCP Timer (optional)
2430 */
2431 vector_threshold = MIN_MSIX_COUNT;
2432
2433 /* The more we get, the more we will assign to Tx/Rx Cleanup
2434 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
2435 * Right now, we simply care about how many we'll get; we'll
2436 * set them up later while requesting irq's.
2437 */
2438 while (vectors >= vector_threshold) {
2439 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002440 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002441 if (!err) /* Success in acquiring all requested vectors. */
2442 break;
2443 else if (err < 0)
2444 vectors = 0; /* Nasty failure, quit now */
2445 else /* err == number of vectors we should try again with */
2446 vectors = err;
2447 }
2448
2449 if (vectors < vector_threshold) {
2450 /* Can't allocate enough MSI-X interrupts? Oh well.
2451 * This just means we'll go with either a single MSI
2452 * vector or fall back to legacy interrupts.
2453 */
2454 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
2455 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2456 kfree(adapter->msix_entries);
2457 adapter->msix_entries = NULL;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002458 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002459 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002460 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002461 } else {
2462 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
2463 adapter->num_msix_vectors = vectors;
2464 }
2465}
2466
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002467/**
2468 * ixgbe_cache_ring_register - Descriptor ring to register mapping
2469 * @adapter: board private structure to initialize
2470 *
2471 * Once we know the feature-set enabled for the device, we'll cache
2472 * the register offset the descriptor ring is assigned to.
2473 **/
Al Virofeea6a52008-11-27 15:34:07 -08002474static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002475{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002476 int feature_mask = 0, rss_i;
2477 int i, txr_idx, rxr_idx;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002478 int dcb_i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002479
2480 /* Number of supported queues */
2481 switch (adapter->hw.mac.type) {
2482 case ixgbe_mac_82598EB:
Alexander Duyck2f90b862008-11-20 20:52:10 -08002483 dcb_i = adapter->ring_feature[RING_F_DCB].indices;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002484 rss_i = adapter->ring_feature[RING_F_RSS].indices;
2485 txr_idx = 0;
2486 rxr_idx = 0;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002487 feature_mask |= IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002488 feature_mask |= IXGBE_FLAG_RSS_ENABLED;
2489 switch (adapter->flags & feature_mask) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002490 case (IXGBE_FLAG_RSS_ENABLED | IXGBE_FLAG_DCB_ENABLED):
2491 for (i = 0; i < dcb_i; i++) {
2492 int j;
2493 /* Rx first */
2494 for (j = 0; j < adapter->num_rx_queues; j++) {
2495 adapter->rx_ring[rxr_idx].reg_idx =
2496 i << 3 | j;
2497 rxr_idx++;
2498 }
2499 /* Tx now */
2500 for (j = 0; j < adapter->num_tx_queues; j++) {
2501 adapter->tx_ring[txr_idx].reg_idx =
2502 i << 2 | (j >> 1);
2503 if (j & 1)
2504 txr_idx++;
2505 }
2506 }
2507 case (IXGBE_FLAG_DCB_ENABLED):
2508 /* the number of queues is assumed to be symmetric */
2509 for (i = 0; i < dcb_i; i++) {
2510 adapter->rx_ring[i].reg_idx = i << 3;
2511 adapter->tx_ring[i].reg_idx = i << 2;
2512 }
2513 break;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002514 case (IXGBE_FLAG_RSS_ENABLED):
2515 for (i = 0; i < adapter->num_rx_queues; i++)
2516 adapter->rx_ring[i].reg_idx = i;
2517 for (i = 0; i < adapter->num_tx_queues; i++)
2518 adapter->tx_ring[i].reg_idx = i;
2519 break;
2520 case 0:
2521 default:
2522 break;
2523 }
2524 break;
2525 default:
2526 break;
2527 }
2528}
2529
Auke Kok9a799d72007-09-15 14:07:45 -07002530/**
2531 * ixgbe_alloc_queues - Allocate memory for all rings
2532 * @adapter: board private structure to initialize
2533 *
2534 * We allocate one ring per queue at run-time since we don't know the
Wang Chena4d2f342008-12-03 22:05:58 -08002535 * number of queues at compile-time.
Auke Kok9a799d72007-09-15 14:07:45 -07002536 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002537static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002538{
2539 int i;
2540
2541 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002542 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07002543 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002544 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07002545
2546 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002547 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002548 if (!adapter->rx_ring)
2549 goto err_rx_ring_allocation;
2550
2551 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002552 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002553 adapter->tx_ring[i].queue_index = i;
2554 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002555
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002556 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07002557 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002558 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07002559 }
2560
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002561 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002562
2563 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002564
2565err_rx_ring_allocation:
2566 kfree(adapter->tx_ring);
2567err_tx_ring_allocation:
2568 return -ENOMEM;
2569}
2570
2571/**
2572 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
2573 * @adapter: board private structure to initialize
2574 *
2575 * Attempt to configure the interrupts using the best available
2576 * capabilities of the hardware and the kernel.
2577 **/
Al Virofeea6a52008-11-27 15:34:07 -08002578static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002579{
2580 int err = 0;
2581 int vector, v_budget;
2582
2583 /*
2584 * It's easy to be greedy for MSI-X vectors, but it really
2585 * doesn't do us much good if we have a lot more vectors
2586 * than CPU's. So let's be conservative and only ask for
2587 * (roughly) twice the number of vectors as there are CPU's.
2588 */
2589 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002590 (int)(num_online_cpus() * 2)) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002591
2592 /*
2593 * At the same time, hardware can only support a maximum of
2594 * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq,
2595 * we can easily reach upwards of 64 Rx descriptor queues and
2596 * 32 Tx queues. Thus, we cap it off in those rare cases where
2597 * the cpu count also exceeds our vector limit.
2598 */
2599 v_budget = min(v_budget, MAX_MSIX_COUNT);
2600
2601 /* A failure in MSI-X entry allocation isn't fatal, but it does
2602 * mean we disable MSI-X capabilities of the adapter. */
2603 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002604 sizeof(struct msix_entry), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002605 if (!adapter->msix_entries) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08002606 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002607 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
2608 ixgbe_set_num_queues(adapter);
2609 kfree(adapter->tx_ring);
2610 kfree(adapter->rx_ring);
2611 err = ixgbe_alloc_queues(adapter);
2612 if (err) {
2613 DPRINTK(PROBE, ERR, "Unable to allocate memory "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002614 "for queues\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002615 goto out;
2616 }
2617
2618 goto try_msi;
2619 }
2620
2621 for (vector = 0; vector < v_budget; vector++)
2622 adapter->msix_entries[vector].entry = vector;
2623
2624 ixgbe_acquire_msix_vectors(adapter, v_budget);
2625
2626 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2627 goto out;
2628
2629try_msi:
2630 err = pci_enable_msi(adapter->pdev);
2631 if (!err) {
2632 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
2633 } else {
2634 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002635 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002636 /* reset err */
2637 err = 0;
2638 }
2639
2640out:
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08002641 /* Notify the stack of the (possibly) reduced Tx Queue count. */
David S. Millerfd2ea0a2008-07-17 01:56:23 -07002642 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002643
2644 return err;
2645}
2646
Alexander Duyck2f90b862008-11-20 20:52:10 -08002647void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002648{
2649 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2650 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2651 pci_disable_msix(adapter->pdev);
2652 kfree(adapter->msix_entries);
2653 adapter->msix_entries = NULL;
2654 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
2655 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
2656 pci_disable_msi(adapter->pdev);
2657 }
2658 return;
2659}
2660
2661/**
2662 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
2663 * @adapter: board private structure to initialize
2664 *
2665 * We determine which interrupt scheme to use based on...
2666 * - Kernel support (MSI, MSI-X)
2667 * - which can be user-defined (via MODULE_PARAM)
2668 * - Hardware queue count (num_*_queues)
2669 * - defined by miscellaneous hardware support/features (RSS, etc.)
2670 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08002671int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002672{
2673 int err;
2674
2675 /* Number of supported queues */
2676 ixgbe_set_num_queues(adapter);
2677
2678 err = ixgbe_alloc_queues(adapter);
2679 if (err) {
2680 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
2681 goto err_alloc_queues;
2682 }
2683
2684 err = ixgbe_set_interrupt_capability(adapter);
2685 if (err) {
2686 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
2687 goto err_set_interrupt;
2688 }
2689
2690 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002691 "Tx Queue count = %u\n",
2692 (adapter->num_rx_queues > 1) ? "Enabled" :
2693 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002694
2695 set_bit(__IXGBE_DOWN, &adapter->state);
2696
2697 return 0;
2698
2699err_set_interrupt:
2700 kfree(adapter->tx_ring);
2701 kfree(adapter->rx_ring);
2702err_alloc_queues:
2703 return err;
Auke Kok9a799d72007-09-15 14:07:45 -07002704}
2705
2706/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08002707 * ixgbe_sfp_timer - worker thread to find a missing module
2708 * @data: pointer to our adapter struct
2709 **/
2710static void ixgbe_sfp_timer(unsigned long data)
2711{
2712 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
2713
2714 /* Do the sfp_timer outside of interrupt context due to the
2715 * delays that sfp+ detection requires
2716 */
2717 schedule_work(&adapter->sfp_task);
2718}
2719
2720/**
2721 * ixgbe_sfp_task - worker thread to find a missing module
2722 * @work: pointer to work_struct containing our data
2723 **/
2724static void ixgbe_sfp_task(struct work_struct *work)
2725{
2726 struct ixgbe_adapter *adapter = container_of(work,
2727 struct ixgbe_adapter,
2728 sfp_task);
2729 struct ixgbe_hw *hw = &adapter->hw;
2730
2731 if ((hw->phy.type == ixgbe_phy_nl) &&
2732 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
2733 s32 ret = hw->phy.ops.identify_sfp(hw);
2734 if (ret)
2735 goto reschedule;
2736 ret = hw->phy.ops.reset(hw);
2737 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
2738 DPRINTK(PROBE, ERR, "failed to initialize because an "
2739 "unsupported SFP+ module type was detected.\n"
2740 "Reload the driver after installing a "
2741 "supported module.\n");
2742 unregister_netdev(adapter->netdev);
2743 } else {
2744 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
2745 hw->phy.sfp_type);
2746 }
2747 /* don't need this routine any more */
2748 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
2749 }
2750 return;
2751reschedule:
2752 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
2753 mod_timer(&adapter->sfp_timer,
2754 round_jiffies(jiffies + (2 * HZ)));
2755}
2756
2757/**
Auke Kok9a799d72007-09-15 14:07:45 -07002758 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
2759 * @adapter: board private structure to initialize
2760 *
2761 * ixgbe_sw_init initializes the Adapter private data structure.
2762 * Fields are initialized based on PCI device information and
2763 * OS network device settings (MTU size).
2764 **/
2765static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
2766{
2767 struct ixgbe_hw *hw = &adapter->hw;
2768 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002769 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002770#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002771 int j;
2772 struct tc_configuration *tc;
2773#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002774
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002775 /* PCI config space info */
2776
2777 hw->vendor_id = pdev->vendor;
2778 hw->device_id = pdev->device;
2779 hw->revision_id = pdev->revision;
2780 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2781 hw->subsystem_device_id = pdev->subsystem_device;
2782
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002783 /* Set capability flags */
2784 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
2785 adapter->ring_feature[RING_F_RSS].indices = rss;
2786 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08002787 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
2788
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002789#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002790 /* Configure DCB traffic classes */
2791 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
2792 tc = &adapter->dcb_cfg.tc_config[j];
2793 tc->path[DCB_TX_CONFIG].bwg_id = 0;
2794 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
2795 tc->path[DCB_RX_CONFIG].bwg_id = 0;
2796 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
2797 tc->dcb_pfc = pfc_disabled;
2798 }
2799 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
2800 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
2801 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
2802 adapter->dcb_cfg.round_robin_enable = false;
2803 adapter->dcb_set_bitmap = 0x00;
2804 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
2805 adapter->ring_feature[RING_F_DCB].indices);
2806
2807#endif
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002808 if (hw->mac.ops.get_media_type &&
2809 (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper))
2810 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Auke Kok9a799d72007-09-15 14:07:45 -07002811
2812 /* default flow control settings */
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07002813 hw->fc.original_type = ixgbe_fc_none;
2814 hw->fc.type = ixgbe_fc_none;
2815 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
2816 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
2817 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
2818 hw->fc.send_xon = true;
Auke Kok9a799d72007-09-15 14:07:45 -07002819
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002820 /* select 10G link by default */
Auke Kok9a799d72007-09-15 14:07:45 -07002821 hw->mac.link_mode_select = IXGBE_AUTOC_LMS_10G_LINK_NO_AN;
Auke Kok9a799d72007-09-15 14:07:45 -07002822
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002823 /* enable itr by default in dynamic mode */
2824 adapter->itr_setting = 1;
2825 adapter->eitr_param = 20000;
2826
2827 /* set defaults for eitr in MegaBytes */
2828 adapter->eitr_low = 10;
2829 adapter->eitr_high = 20;
2830
2831 /* set default ring sizes */
2832 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
2833 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
2834
Auke Kok9a799d72007-09-15 14:07:45 -07002835 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002836 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002837 dev_err(&pdev->dev, "EEPROM initialization failed\n");
2838 return -EIO;
2839 }
2840
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002841 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07002842 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
2843
Auke Kok9a799d72007-09-15 14:07:45 -07002844 set_bit(__IXGBE_DOWN, &adapter->state);
2845
2846 return 0;
2847}
2848
2849/**
2850 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
2851 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002852 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07002853 *
2854 * Return 0 on success, negative on failure
2855 **/
2856int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002857 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002858{
2859 struct pci_dev *pdev = adapter->pdev;
2860 int size;
2861
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002862 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2863 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002864 if (!tx_ring->tx_buffer_info)
2865 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002866 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07002867
2868 /* round up to nearest 4K */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002869 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc) +
2870 sizeof(u32);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002871 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07002872
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002873 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
2874 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002875 if (!tx_ring->desc)
2876 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07002877
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002878 tx_ring->next_to_use = 0;
2879 tx_ring->next_to_clean = 0;
2880 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07002881 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002882
2883err:
2884 vfree(tx_ring->tx_buffer_info);
2885 tx_ring->tx_buffer_info = NULL;
2886 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
2887 "descriptor ring\n");
2888 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07002889}
2890
2891/**
Alexander Duyck69888672008-09-11 20:05:39 -07002892 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
2893 * @adapter: board private structure
2894 *
2895 * If this function returns with an error, then it's possible one or
2896 * more of the rings is populated (while the rest are not). It is the
2897 * callers duty to clean those orphaned rings.
2898 *
2899 * Return 0 on success, negative on failure
2900 **/
2901static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
2902{
2903 int i, err = 0;
2904
2905 for (i = 0; i < adapter->num_tx_queues; i++) {
2906 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
2907 if (!err)
2908 continue;
2909 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
2910 break;
2911 }
2912
2913 return err;
2914}
2915
2916/**
Auke Kok9a799d72007-09-15 14:07:45 -07002917 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
2918 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002919 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07002920 *
2921 * Returns 0 on success, negative on failure
2922 **/
2923int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002924 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002925{
2926 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002927 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002928
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002929 size = sizeof(struct net_lro_desc) * IXGBE_MAX_LRO_DESCRIPTORS;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002930 rx_ring->lro_mgr.lro_arr = vmalloc(size);
2931 if (!rx_ring->lro_mgr.lro_arr)
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002932 return -ENOMEM;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002933 memset(rx_ring->lro_mgr.lro_arr, 0, size);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002934
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002935 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2936 rx_ring->rx_buffer_info = vmalloc(size);
2937 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07002938 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002939 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002940 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07002941 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002942 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07002943
Auke Kok9a799d72007-09-15 14:07:45 -07002944 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002945 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
2946 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07002947
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002948 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07002949
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002950 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07002951 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002952 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002953 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002954 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07002955 }
2956
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002957 rx_ring->next_to_clean = 0;
2958 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002959
2960 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002961
2962alloc_failed:
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002963 vfree(rx_ring->lro_mgr.lro_arr);
2964 rx_ring->lro_mgr.lro_arr = NULL;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002965 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07002966}
2967
2968/**
Alexander Duyck69888672008-09-11 20:05:39 -07002969 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
2970 * @adapter: board private structure
2971 *
2972 * If this function returns with an error, then it's possible one or
2973 * more of the rings is populated (while the rest are not). It is the
2974 * callers duty to clean those orphaned rings.
2975 *
2976 * Return 0 on success, negative on failure
2977 **/
2978
2979static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
2980{
2981 int i, err = 0;
2982
2983 for (i = 0; i < adapter->num_rx_queues; i++) {
2984 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
2985 if (!err)
2986 continue;
2987 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
2988 break;
2989 }
2990
2991 return err;
2992}
2993
2994/**
Auke Kok9a799d72007-09-15 14:07:45 -07002995 * ixgbe_free_tx_resources - Free Tx Resources per Queue
2996 * @adapter: board private structure
2997 * @tx_ring: Tx descriptor ring for a specific queue
2998 *
2999 * Free all transmit software resources
3000 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003001void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
3002 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003003{
3004 struct pci_dev *pdev = adapter->pdev;
3005
3006 ixgbe_clean_tx_ring(adapter, tx_ring);
3007
3008 vfree(tx_ring->tx_buffer_info);
3009 tx_ring->tx_buffer_info = NULL;
3010
3011 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
3012
3013 tx_ring->desc = NULL;
3014}
3015
3016/**
3017 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
3018 * @adapter: board private structure
3019 *
3020 * Free all transmit software resources
3021 **/
3022static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
3023{
3024 int i;
3025
3026 for (i = 0; i < adapter->num_tx_queues; i++)
3027 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
3028}
3029
3030/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003031 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07003032 * @adapter: board private structure
3033 * @rx_ring: ring to clean the resources from
3034 *
3035 * Free all receive software resources
3036 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07003037void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
3038 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003039{
3040 struct pci_dev *pdev = adapter->pdev;
3041
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003042 vfree(rx_ring->lro_mgr.lro_arr);
3043 rx_ring->lro_mgr.lro_arr = NULL;
3044
Auke Kok9a799d72007-09-15 14:07:45 -07003045 ixgbe_clean_rx_ring(adapter, rx_ring);
3046
3047 vfree(rx_ring->rx_buffer_info);
3048 rx_ring->rx_buffer_info = NULL;
3049
3050 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
3051
3052 rx_ring->desc = NULL;
3053}
3054
3055/**
3056 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
3057 * @adapter: board private structure
3058 *
3059 * Free all receive software resources
3060 **/
3061static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
3062{
3063 int i;
3064
3065 for (i = 0; i < adapter->num_rx_queues; i++)
3066 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
3067}
3068
3069/**
Auke Kok9a799d72007-09-15 14:07:45 -07003070 * ixgbe_change_mtu - Change the Maximum Transfer Unit
3071 * @netdev: network interface device structure
3072 * @new_mtu: new value for maximum frame size
3073 *
3074 * Returns 0 on success, negative on failure
3075 **/
3076static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
3077{
3078 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3079 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
3080
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07003081 /* MTU < 68 is an error and causes problems on some kernels */
3082 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07003083 return -EINVAL;
3084
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003085 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003086 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003087 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07003088 netdev->mtu = new_mtu;
3089
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003090 if (netif_running(netdev))
3091 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003092
3093 return 0;
3094}
3095
3096/**
3097 * ixgbe_open - Called when a network interface is made active
3098 * @netdev: network interface device structure
3099 *
3100 * Returns 0 on success, negative value on failure
3101 *
3102 * The open entry point is called when a network interface is made
3103 * active by the system (IFF_UP). At this point all resources needed
3104 * for transmit and receive operations are allocated, the interrupt
3105 * handler is registered with the OS, the watchdog timer is started,
3106 * and the stack is notified that the interface is ready.
3107 **/
3108static int ixgbe_open(struct net_device *netdev)
3109{
3110 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3111 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003112
Auke Kok4bebfaa2008-02-11 09:26:01 -08003113 /* disallow open during test */
3114 if (test_bit(__IXGBE_TESTING, &adapter->state))
3115 return -EBUSY;
3116
Auke Kok9a799d72007-09-15 14:07:45 -07003117 /* allocate transmit descriptors */
3118 err = ixgbe_setup_all_tx_resources(adapter);
3119 if (err)
3120 goto err_setup_tx;
3121
Auke Kok9a799d72007-09-15 14:07:45 -07003122 /* allocate receive descriptors */
3123 err = ixgbe_setup_all_rx_resources(adapter);
3124 if (err)
3125 goto err_setup_rx;
3126
3127 ixgbe_configure(adapter);
3128
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003129 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003130 if (err)
3131 goto err_req_irq;
3132
Auke Kok9a799d72007-09-15 14:07:45 -07003133 err = ixgbe_up_complete(adapter);
3134 if (err)
3135 goto err_up;
3136
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07003137 netif_tx_start_all_queues(netdev);
3138
Auke Kok9a799d72007-09-15 14:07:45 -07003139 return 0;
3140
3141err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003142 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003143 ixgbe_free_irq(adapter);
3144err_req_irq:
3145 ixgbe_free_all_rx_resources(adapter);
3146err_setup_rx:
3147 ixgbe_free_all_tx_resources(adapter);
3148err_setup_tx:
3149 ixgbe_reset(adapter);
3150
3151 return err;
3152}
3153
3154/**
3155 * ixgbe_close - Disables a network interface
3156 * @netdev: network interface device structure
3157 *
3158 * Returns 0, this is not allowed to fail
3159 *
3160 * The close entry point is called when an interface is de-activated
3161 * by the OS. The hardware is still under the drivers control, but
3162 * needs to be disabled. A global MAC reset is issued to stop the
3163 * hardware, and all transmit and receive resources are freed.
3164 **/
3165static int ixgbe_close(struct net_device *netdev)
3166{
3167 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003168
3169 ixgbe_down(adapter);
3170 ixgbe_free_irq(adapter);
3171
3172 ixgbe_free_all_tx_resources(adapter);
3173 ixgbe_free_all_rx_resources(adapter);
3174
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08003175 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003176
3177 return 0;
3178}
3179
3180/**
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003181 * ixgbe_napi_add_all - prep napi structs for use
3182 * @adapter: private struct
3183 * helper function to napi_add each possible q_vector->napi
3184 */
Alexander Duyck2f90b862008-11-20 20:52:10 -08003185void ixgbe_napi_add_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003186{
3187 int q_idx, q_vectors;
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003188 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003189 int (*poll)(struct napi_struct *, int);
3190
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003191 /* check if we already have our netdev->napi_list populated */
3192 if (&netdev->napi_list != netdev->napi_list.next)
3193 return;
3194
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003195 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3196 poll = &ixgbe_clean_rxonly;
3197 /* Only enable as many vectors as we have rx queues. */
3198 q_vectors = adapter->num_rx_queues;
3199 } else {
3200 poll = &ixgbe_poll;
3201 /* only one q_vector for legacy modes */
3202 q_vectors = 1;
3203 }
3204
3205 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3206 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3207 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
3208 }
3209}
3210
Alexander Duyck2f90b862008-11-20 20:52:10 -08003211void ixgbe_napi_del_all(struct ixgbe_adapter *adapter)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003212{
3213 int q_idx;
3214 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3215
3216 /* legacy and MSI only use one vector */
3217 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3218 q_vectors = 1;
3219
3220 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
3221 struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx];
3222 if (!q_vector->rxr_count)
3223 continue;
3224 netif_napi_del(&q_vector->napi);
3225 }
3226}
3227
3228#ifdef CONFIG_PM
3229static int ixgbe_resume(struct pci_dev *pdev)
3230{
3231 struct net_device *netdev = pci_get_drvdata(pdev);
3232 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3233 u32 err;
3234
3235 pci_set_power_state(pdev, PCI_D0);
3236 pci_restore_state(pdev);
3237 err = pci_enable_device(pdev);
3238 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07003239 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003240 "suspend\n");
3241 return err;
3242 }
3243 pci_set_master(pdev);
3244
3245 pci_enable_wake(pdev, PCI_D3hot, 0);
3246 pci_enable_wake(pdev, PCI_D3cold, 0);
3247
3248 err = ixgbe_init_interrupt_scheme(adapter);
3249 if (err) {
3250 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
3251 "device\n");
3252 return err;
3253 }
3254
3255 ixgbe_napi_add_all(adapter);
3256 ixgbe_reset(adapter);
3257
3258 if (netif_running(netdev)) {
3259 err = ixgbe_open(adapter->netdev);
3260 if (err)
3261 return err;
3262 }
3263
3264 netif_device_attach(netdev);
3265
3266 return 0;
3267}
3268
3269#endif /* CONFIG_PM */
3270static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
3271{
3272 struct net_device *netdev = pci_get_drvdata(pdev);
3273 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3274#ifdef CONFIG_PM
3275 int retval = 0;
3276#endif
3277
3278 netif_device_detach(netdev);
3279
3280 if (netif_running(netdev)) {
3281 ixgbe_down(adapter);
3282 ixgbe_free_irq(adapter);
3283 ixgbe_free_all_tx_resources(adapter);
3284 ixgbe_free_all_rx_resources(adapter);
3285 }
3286 ixgbe_reset_interrupt_capability(adapter);
3287 ixgbe_napi_del_all(adapter);
Peter P Waskiewicz Jr7adf1522008-12-26 01:36:05 -08003288 INIT_LIST_HEAD(&netdev->napi_list);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07003289 kfree(adapter->tx_ring);
3290 kfree(adapter->rx_ring);
3291
3292#ifdef CONFIG_PM
3293 retval = pci_save_state(pdev);
3294 if (retval)
3295 return retval;
3296#endif
3297
3298 pci_enable_wake(pdev, PCI_D3hot, 0);
3299 pci_enable_wake(pdev, PCI_D3cold, 0);
3300
3301 ixgbe_release_hw_control(adapter);
3302
3303 pci_disable_device(pdev);
3304
3305 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3306
3307 return 0;
3308}
3309
3310static void ixgbe_shutdown(struct pci_dev *pdev)
3311{
3312 ixgbe_suspend(pdev, PMSG_SUSPEND);
3313}
3314
3315/**
Auke Kok9a799d72007-09-15 14:07:45 -07003316 * ixgbe_update_stats - Update the board statistics counters.
3317 * @adapter: board private structure
3318 **/
3319void ixgbe_update_stats(struct ixgbe_adapter *adapter)
3320{
3321 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003322 u64 total_mpc = 0;
3323 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003324
3325 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003326 for (i = 0; i < 8; i++) {
3327 /* for packet buffers not used, the register should read 0 */
3328 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
3329 missed_rx += mpc;
3330 adapter->stats.mpc[i] += mpc;
3331 total_mpc += adapter->stats.mpc[i];
3332 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08003333 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
3334 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
3335 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
3336 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
3337 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
3338 IXGBE_PXONRXC(i));
3339 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
3340 IXGBE_PXONTXC(i));
3341 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
3342 IXGBE_PXOFFRXC(i));
3343 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
3344 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003345 }
3346 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
3347 /* work around hardware counting issue */
3348 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07003349
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003350 /* 82598 hardware only has a 32 bit counter in the high register */
Auke Kok9a799d72007-09-15 14:07:45 -07003351 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003352 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
3353 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
Auke Kok9a799d72007-09-15 14:07:45 -07003354 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
3355 adapter->stats.bprc += bprc;
3356 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
3357 adapter->stats.mprc -= bprc;
3358 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
3359 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
3360 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
3361 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
3362 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
3363 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
3364 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003365 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
3366 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Auke Kok9a799d72007-09-15 14:07:45 -07003367 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003368 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
3369 adapter->stats.lxontxc += lxon;
3370 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
3371 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07003372 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3373 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003374 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
3375 /*
3376 * 82598 errata - tx of flow control packets is included in tx counters
3377 */
3378 xon_off_tot = lxon + lxoff;
3379 adapter->stats.gptc -= xon_off_tot;
3380 adapter->stats.mptc -= xon_off_tot;
3381 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07003382 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
3383 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
3384 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07003385 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
3386 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003387 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07003388 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
3389 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
3390 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
3391 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
3392 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07003393 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
3394
3395 /* Fill out the OS statistics structure */
Auke Kok9a799d72007-09-15 14:07:45 -07003396 adapter->net_stats.multicast = adapter->stats.mprc;
3397
3398 /* Rx Errors */
3399 adapter->net_stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003400 adapter->stats.rlec;
Auke Kok9a799d72007-09-15 14:07:45 -07003401 adapter->net_stats.rx_dropped = 0;
3402 adapter->net_stats.rx_length_errors = adapter->stats.rlec;
3403 adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08003404 adapter->net_stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07003405}
3406
3407/**
3408 * ixgbe_watchdog - Timer Call-back
3409 * @data: pointer to adapter cast into an unsigned long
3410 **/
3411static void ixgbe_watchdog(unsigned long data)
3412{
3413 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003414 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003415
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003416 /* Do the watchdog outside of interrupt context due to the lovely
3417 * delays that some of the newer hardware requires */
3418 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
3419 /* Cause software interrupt to ensure rx rings are cleaned */
3420 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3421 u32 eics =
3422 (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1;
3423 IXGBE_WRITE_REG(hw, IXGBE_EICS, eics);
3424 } else {
3425 /* For legacy and MSI interrupts don't set any bits that
3426 * are enabled for EIAM, because this operation would
3427 * set *both* EIMS and EICS for any bit in EIAM */
3428 IXGBE_WRITE_REG(hw, IXGBE_EICS,
3429 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
3430 }
3431 /* Reset the timer */
3432 mod_timer(&adapter->watchdog_timer,
3433 round_jiffies(jiffies + 2 * HZ));
3434 }
3435
3436 schedule_work(&adapter->watchdog_task);
3437}
3438
3439/**
Alexander Duyck69888672008-09-11 20:05:39 -07003440 * ixgbe_watchdog_task - worker thread to bring link up
3441 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003442 **/
3443static void ixgbe_watchdog_task(struct work_struct *work)
3444{
3445 struct ixgbe_adapter *adapter = container_of(work,
3446 struct ixgbe_adapter,
3447 watchdog_task);
3448 struct net_device *netdev = adapter->netdev;
3449 struct ixgbe_hw *hw = &adapter->hw;
3450 u32 link_speed = adapter->link_speed;
3451 bool link_up = adapter->link_up;
3452
3453 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
3454
3455 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
3456 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
3457 if (link_up ||
3458 time_after(jiffies, (adapter->link_check_timeout +
3459 IXGBE_TRY_LINK_TIMEOUT))) {
3460 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
3461 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
3462 }
3463 adapter->link_up = link_up;
3464 adapter->link_speed = link_speed;
3465 }
Auke Kok9a799d72007-09-15 14:07:45 -07003466
3467 if (link_up) {
3468 if (!netif_carrier_ok(netdev)) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003469 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3470 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
Auke Kok9a799d72007-09-15 14:07:45 -07003471#define FLOW_RX (frctl & IXGBE_FCTRL_RFCE)
3472#define FLOW_TX (rmcs & IXGBE_RMCS_TFCE_802_3X)
Jeff Kirshera46e5342008-11-27 00:22:21 -08003473 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
3474 "Flow Control: %s\n",
3475 netdev->name,
3476 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
3477 "10 Gbps" :
3478 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
3479 "1 Gbps" : "unknown speed")),
3480 ((FLOW_RX && FLOW_TX) ? "RX/TX" :
3481 (FLOW_RX ? "RX" :
3482 (FLOW_TX ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07003483
3484 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003485 } else {
3486 /* Force detection of hung controller */
3487 adapter->detect_tx_hung = true;
3488 }
3489 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003490 adapter->link_up = false;
3491 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003492 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08003493 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
3494 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07003495 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003496 }
3497 }
3498
3499 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003500 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07003501}
3502
Auke Kok9a799d72007-09-15 14:07:45 -07003503static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003504 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
3505 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07003506{
3507 struct ixgbe_adv_tx_context_desc *context_desc;
3508 unsigned int i;
3509 int err;
3510 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003511 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
3512 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07003513
3514 if (skb_is_gso(skb)) {
3515 if (skb_header_cloned(skb)) {
3516 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
3517 if (err)
3518 return err;
3519 }
3520 l4len = tcp_hdrlen(skb);
3521 *hdr_len += l4len;
3522
Al Viro8327d002007-12-10 18:54:12 +00003523 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003524 struct iphdr *iph = ip_hdr(skb);
3525 iph->tot_len = 0;
3526 iph->check = 0;
3527 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003528 iph->daddr, 0,
3529 IPPROTO_TCP,
3530 0);
Auke Kok9a799d72007-09-15 14:07:45 -07003531 adapter->hw_tso_ctxt++;
3532 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
3533 ipv6_hdr(skb)->payload_len = 0;
3534 tcp_hdr(skb)->check =
3535 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003536 &ipv6_hdr(skb)->daddr,
3537 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07003538 adapter->hw_tso6_ctxt++;
3539 }
3540
3541 i = tx_ring->next_to_use;
3542
3543 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3544 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3545
3546 /* VLAN MACLEN IPLEN */
3547 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3548 vlan_macip_lens |=
3549 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3550 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003551 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003552 *hdr_len += skb_network_offset(skb);
3553 vlan_macip_lens |=
3554 (skb_transport_header(skb) - skb_network_header(skb));
3555 *hdr_len +=
3556 (skb_transport_header(skb) - skb_network_header(skb));
3557 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3558 context_desc->seqnum_seed = 0;
3559
3560 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003561 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003562 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07003563
Al Viro8327d002007-12-10 18:54:12 +00003564 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07003565 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
3566 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
3567 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
3568
3569 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003570 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07003571 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
3572 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003573 /* use index 1 for TSO */
3574 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003575 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
3576
3577 tx_buffer_info->time_stamp = jiffies;
3578 tx_buffer_info->next_to_watch = i;
3579
3580 i++;
3581 if (i == tx_ring->count)
3582 i = 0;
3583 tx_ring->next_to_use = i;
3584
3585 return true;
3586 }
3587 return false;
3588}
3589
3590static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003591 struct ixgbe_ring *tx_ring,
3592 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07003593{
3594 struct ixgbe_adv_tx_context_desc *context_desc;
3595 unsigned int i;
3596 struct ixgbe_tx_buffer *tx_buffer_info;
3597 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
3598
3599 if (skb->ip_summed == CHECKSUM_PARTIAL ||
3600 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
3601 i = tx_ring->next_to_use;
3602 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3603 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
3604
3605 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3606 vlan_macip_lens |=
3607 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
3608 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003609 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003610 if (skb->ip_summed == CHECKSUM_PARTIAL)
3611 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003612 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07003613
3614 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
3615 context_desc->seqnum_seed = 0;
3616
3617 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003618 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07003619
3620 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08003621 switch (skb->protocol) {
3622 case __constant_htons(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07003623 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08003624 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
3625 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003626 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08003627 break;
Auke Kok41825d72008-02-12 15:20:33 -08003628 case __constant_htons(ETH_P_IPV6):
3629 /* XXX what about other V6 headers?? */
3630 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
3631 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003632 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Auke Kok41825d72008-02-12 15:20:33 -08003633 break;
Auke Kok41825d72008-02-12 15:20:33 -08003634 default:
3635 if (unlikely(net_ratelimit())) {
3636 DPRINTK(PROBE, WARNING,
3637 "partial checksum but proto=%x!\n",
3638 skb->protocol);
3639 }
3640 break;
3641 }
Auke Kok9a799d72007-09-15 14:07:45 -07003642 }
3643
3644 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003645 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07003646 context_desc->mss_l4len_idx = 0;
3647
3648 tx_buffer_info->time_stamp = jiffies;
3649 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003650
Auke Kok9a799d72007-09-15 14:07:45 -07003651 adapter->hw_csum_tx_good++;
3652 i++;
3653 if (i == tx_ring->count)
3654 i = 0;
3655 tx_ring->next_to_use = i;
3656
3657 return true;
3658 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003659
Auke Kok9a799d72007-09-15 14:07:45 -07003660 return false;
3661}
3662
3663static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003664 struct ixgbe_ring *tx_ring,
3665 struct sk_buff *skb, unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07003666{
3667 struct ixgbe_tx_buffer *tx_buffer_info;
3668 unsigned int len = skb->len;
3669 unsigned int offset = 0, size, count = 0, i;
3670 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
3671 unsigned int f;
3672
3673 len -= skb->data_len;
3674
3675 i = tx_ring->next_to_use;
3676
3677 while (len) {
3678 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3679 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3680
3681 tx_buffer_info->length = size;
3682 tx_buffer_info->dma = pci_map_single(adapter->pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003683 skb->data + offset,
3684 size, PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003685 tx_buffer_info->time_stamp = jiffies;
3686 tx_buffer_info->next_to_watch = i;
3687
3688 len -= size;
3689 offset += size;
3690 count++;
3691 i++;
3692 if (i == tx_ring->count)
3693 i = 0;
3694 }
3695
3696 for (f = 0; f < nr_frags; f++) {
3697 struct skb_frag_struct *frag;
3698
3699 frag = &skb_shinfo(skb)->frags[f];
3700 len = frag->size;
3701 offset = frag->page_offset;
3702
3703 while (len) {
3704 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3705 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
3706
3707 tx_buffer_info->length = size;
3708 tx_buffer_info->dma = pci_map_page(adapter->pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003709 frag->page,
3710 offset,
3711 size,
3712 PCI_DMA_TODEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003713 tx_buffer_info->time_stamp = jiffies;
3714 tx_buffer_info->next_to_watch = i;
3715
3716 len -= size;
3717 offset += size;
3718 count++;
3719 i++;
3720 if (i == tx_ring->count)
3721 i = 0;
3722 }
3723 }
3724 if (i == 0)
3725 i = tx_ring->count - 1;
3726 else
3727 i = i - 1;
3728 tx_ring->tx_buffer_info[i].skb = skb;
3729 tx_ring->tx_buffer_info[first].next_to_watch = i;
3730
3731 return count;
3732}
3733
3734static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003735 struct ixgbe_ring *tx_ring,
3736 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07003737{
3738 union ixgbe_adv_tx_desc *tx_desc = NULL;
3739 struct ixgbe_tx_buffer *tx_buffer_info;
3740 u32 olinfo_status = 0, cmd_type_len = 0;
3741 unsigned int i;
3742 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
3743
3744 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
3745
3746 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
3747
3748 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
3749 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
3750
3751 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
3752 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
3753
3754 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003755 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003756
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07003757 /* use index 1 context for tso */
3758 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07003759 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
3760 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003761 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003762
3763 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
3764 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003765 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07003766
3767 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
3768
3769 i = tx_ring->next_to_use;
3770 while (count--) {
3771 tx_buffer_info = &tx_ring->tx_buffer_info[i];
3772 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
3773 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
3774 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003775 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07003776 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07003777 i++;
3778 if (i == tx_ring->count)
3779 i = 0;
3780 }
3781
3782 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
3783
3784 /*
3785 * Force memory writes to complete before letting h/w
3786 * know there are new descriptors to fetch. (Only
3787 * applicable for weak-ordered memory model archs,
3788 * such as IA-64).
3789 */
3790 wmb();
3791
3792 tx_ring->next_to_use = i;
3793 writel(i, adapter->hw.hw_addr + tx_ring->tail);
3794}
3795
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003796static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003797 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003798{
3799 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3800
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003801 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003802 /* Herbert's original patch had:
3803 * smp_mb__after_netif_stop_queue();
3804 * but since that doesn't exist yet, just open code it. */
3805 smp_mb();
3806
3807 /* We need to check again in a case another CPU has just
3808 * made room available. */
3809 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
3810 return -EBUSY;
3811
3812 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07003813 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003814 ++adapter->restart_queue;
3815 return 0;
3816}
3817
3818static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003819 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003820{
3821 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
3822 return 0;
3823 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
3824}
3825
Auke Kok9a799d72007-09-15 14:07:45 -07003826static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3827{
3828 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3829 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07003830 unsigned int first;
3831 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003832 u8 hdr_len = 0;
3833 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07003834 int count = 0;
3835 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003836
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003837 r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08003838 tx_ring = &adapter->tx_ring[r_idx];
Auke Kok9a799d72007-09-15 14:07:45 -07003839
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003840 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
3841 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003842 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3843 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
3844 tx_flags |= (skb->queue_mapping << 13);
3845 }
3846 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3847 tx_flags |= IXGBE_TX_FLAGS_VLAN;
3848 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3849 tx_flags |= (skb->queue_mapping << 13);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003850 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
3851 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07003852 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003853 /* three things can cause us to need a context descriptor */
3854 if (skb_is_gso(skb) ||
3855 (skb->ip_summed == CHECKSUM_PARTIAL) ||
3856 (tx_flags & IXGBE_TX_FLAGS_VLAN))
Auke Kok9a799d72007-09-15 14:07:45 -07003857 count++;
3858
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07003859 count += TXD_USE_COUNT(skb_headlen(skb));
3860 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07003861 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
3862
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003863 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07003864 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07003865 return NETDEV_TX_BUSY;
3866 }
Auke Kok9a799d72007-09-15 14:07:45 -07003867
Al Viro8327d002007-12-10 18:54:12 +00003868 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07003869 tx_flags |= IXGBE_TX_FLAGS_IPV4;
3870 first = tx_ring->next_to_use;
3871 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
3872 if (tso < 0) {
3873 dev_kfree_skb_any(skb);
3874 return NETDEV_TX_OK;
3875 }
3876
3877 if (tso)
3878 tx_flags |= IXGBE_TX_FLAGS_TSO;
3879 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003880 (skb->ip_summed == CHECKSUM_PARTIAL))
Auke Kok9a799d72007-09-15 14:07:45 -07003881 tx_flags |= IXGBE_TX_FLAGS_CSUM;
3882
3883 ixgbe_tx_queue(adapter, tx_ring, tx_flags,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003884 ixgbe_tx_map(adapter, tx_ring, skb, first),
3885 skb->len, hdr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07003886
3887 netdev->trans_start = jiffies;
3888
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08003889 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07003890
3891 return NETDEV_TX_OK;
3892}
3893
3894/**
3895 * ixgbe_get_stats - Get System Network Statistics
3896 * @netdev: network interface device structure
3897 *
3898 * Returns the address of the device statistics structure.
3899 * The statistics are actually updated from the timer callback.
3900 **/
3901static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
3902{
3903 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3904
3905 /* only return the current stats */
3906 return &adapter->net_stats;
3907}
3908
3909/**
3910 * ixgbe_set_mac - Change the Ethernet Address of the NIC
3911 * @netdev: network interface device structure
3912 * @p: pointer to an address structure
3913 *
3914 * Returns 0 on success, negative on failure
3915 **/
3916static int ixgbe_set_mac(struct net_device *netdev, void *p)
3917{
3918 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003919 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003920 struct sockaddr *addr = p;
3921
3922 if (!is_valid_ether_addr(addr->sa_data))
3923 return -EADDRNOTAVAIL;
3924
3925 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003926 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07003927
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003928 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003929
3930 return 0;
3931}
3932
3933#ifdef CONFIG_NET_POLL_CONTROLLER
3934/*
3935 * Polling 'interrupt' - used by things like netconsole to send skbs
3936 * without having to re-enable interrupts. It's not called while
3937 * the interrupt routine is executing.
3938 */
3939static void ixgbe_netpoll(struct net_device *netdev)
3940{
3941 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3942
3943 disable_irq(adapter->pdev->irq);
3944 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
3945 ixgbe_intr(adapter->pdev->irq, netdev);
3946 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
3947 enable_irq(adapter->pdev->irq);
3948}
3949#endif
3950
3951/**
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003952 * ixgbe_link_config - set up initial link with default speed and duplex
3953 * @hw: pointer to private hardware struct
3954 *
3955 * Returns 0 on success, negative on failure
3956 **/
3957static int ixgbe_link_config(struct ixgbe_hw *hw)
3958{
3959 u32 autoneg = IXGBE_LINK_SPEED_10GB_FULL;
3960
3961 /* must always autoneg for both 1G and 10G link */
3962 hw->mac.autoneg = true;
3963
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003964 if ((hw->mac.type == ixgbe_mac_82598EB) &&
3965 (hw->phy.media_type == ixgbe_media_type_copper))
3966 autoneg = IXGBE_LINK_SPEED_82598_AUTONEG;
3967
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003968 return hw->mac.ops.setup_link_speed(hw, autoneg, true, true);
3969}
3970
Stephen Hemminger0edc3522008-11-19 22:24:29 -08003971static const struct net_device_ops ixgbe_netdev_ops = {
3972 .ndo_open = ixgbe_open,
3973 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08003974 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08003975 .ndo_get_stats = ixgbe_get_stats,
3976 .ndo_set_multicast_list = ixgbe_set_rx_mode,
3977 .ndo_validate_addr = eth_validate_addr,
3978 .ndo_set_mac_address = ixgbe_set_mac,
3979 .ndo_change_mtu = ixgbe_change_mtu,
3980 .ndo_tx_timeout = ixgbe_tx_timeout,
3981 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
3982 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
3983 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
3984#ifdef CONFIG_NET_POLL_CONTROLLER
3985 .ndo_poll_controller = ixgbe_netpoll,
3986#endif
3987};
3988
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003989/**
Auke Kok9a799d72007-09-15 14:07:45 -07003990 * ixgbe_probe - Device Initialization Routine
3991 * @pdev: PCI device information struct
3992 * @ent: entry in ixgbe_pci_tbl
3993 *
3994 * Returns 0 on success, negative on failure
3995 *
3996 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
3997 * The OS initialization, configuring of the adapter private structure,
3998 * and a hardware reset occur.
3999 **/
4000static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004001 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07004002{
4003 struct net_device *netdev;
4004 struct ixgbe_adapter *adapter = NULL;
4005 struct ixgbe_hw *hw;
4006 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07004007 static int cards_found;
4008 int i, err, pci_using_dac;
4009 u16 link_status, link_speed, link_width;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004010 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07004011
4012 err = pci_enable_device(pdev);
4013 if (err)
4014 return err;
4015
4016 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
4017 !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
4018 pci_using_dac = 1;
4019 } else {
4020 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4021 if (err) {
4022 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
4023 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004024 dev_err(&pdev->dev, "No usable DMA "
4025 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004026 goto err_dma;
4027 }
4028 }
4029 pci_using_dac = 0;
4030 }
4031
4032 err = pci_request_regions(pdev, ixgbe_driver_name);
4033 if (err) {
4034 dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err);
4035 goto err_pci_reg;
4036 }
4037
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004038 err = pci_enable_pcie_error_reporting(pdev);
4039 if (err) {
4040 dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed "
4041 "0x%x\n", err);
4042 /* non-fatal, continue */
4043 }
4044
Auke Kok9a799d72007-09-15 14:07:45 -07004045 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07004046 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004047
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08004048 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07004049 if (!netdev) {
4050 err = -ENOMEM;
4051 goto err_alloc_etherdev;
4052 }
4053
Auke Kok9a799d72007-09-15 14:07:45 -07004054 SET_NETDEV_DEV(netdev, &pdev->dev);
4055
4056 pci_set_drvdata(pdev, netdev);
4057 adapter = netdev_priv(netdev);
4058
4059 adapter->netdev = netdev;
4060 adapter->pdev = pdev;
4061 hw = &adapter->hw;
4062 hw->back = adapter;
4063 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
4064
Jeff Kirsher05857982008-09-11 19:57:00 -07004065 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
4066 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07004067 if (!hw->hw_addr) {
4068 err = -EIO;
4069 goto err_ioremap;
4070 }
4071
4072 for (i = 1; i <= 5; i++) {
4073 if (pci_resource_len(pdev, i) == 0)
4074 continue;
4075 }
4076
Stephen Hemminger0edc3522008-11-19 22:24:29 -08004077 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07004078 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004079 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07004080 strcpy(netdev->name, pci_name(pdev));
4081
Auke Kok9a799d72007-09-15 14:07:45 -07004082 adapter->bd_number = cards_found;
4083
Auke Kok9a799d72007-09-15 14:07:45 -07004084 /* Setup hw api */
4085 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004086 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07004087
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004088 /* EEPROM */
4089 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
4090 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
4091 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
4092 if (!(eec & (1 << 8)))
4093 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
4094
4095 /* PHY */
4096 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08004097 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
4098
4099 /* set up this timer and work struct before calling get_invariants
4100 * which might start the timer
4101 */
4102 init_timer(&adapter->sfp_timer);
4103 adapter->sfp_timer.function = &ixgbe_sfp_timer;
4104 adapter->sfp_timer.data = (unsigned long) adapter;
4105
4106 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004107
Auke Kok9a799d72007-09-15 14:07:45 -07004108 err = ii->get_invariants(hw);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004109 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
4110 /* start a kernel thread to watch for a module to arrive */
4111 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4112 mod_timer(&adapter->sfp_timer,
4113 round_jiffies(jiffies + (2 * HZ)));
4114 err = 0;
4115 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
4116 DPRINTK(PROBE, ERR, "failed to load because an "
4117 "unsupported SFP+ module type was detected.\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004118 goto err_hw_init;
Donald Skidmorec4900be2008-11-20 21:11:42 -08004119 } else if (err) {
4120 goto err_hw_init;
4121 }
Auke Kok9a799d72007-09-15 14:07:45 -07004122
4123 /* setup the private structure */
4124 err = ixgbe_sw_init(adapter);
4125 if (err)
4126 goto err_sw_init;
4127
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004128 /* reset_hw fills in the perm_addr as well */
4129 err = hw->mac.ops.reset_hw(hw);
4130 if (err) {
4131 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
4132 goto err_sw_init;
4133 }
4134
Auke Kok9a799d72007-09-15 14:07:45 -07004135 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004136 NETIF_F_IP_CSUM |
4137 NETIF_F_HW_VLAN_TX |
4138 NETIF_F_HW_VLAN_RX |
4139 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004140
Jesse Brandeburge9990a92008-08-26 04:27:24 -07004141 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07004142 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07004143 netdev->features |= NETIF_F_TSO6;
Jesse Brandeburge9990a92008-08-26 04:27:24 -07004144 netdev->features |= NETIF_F_LRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004145
4146 netdev->vlan_features |= NETIF_F_TSO;
4147 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07004148 netdev->vlan_features |= NETIF_F_IP_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07004149 netdev->vlan_features |= NETIF_F_SG;
4150
Alexander Duyck2f90b862008-11-20 20:52:10 -08004151 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
4152 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
4153
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004154#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004155 netdev->dcbnl_ops = &dcbnl_ops;
4156#endif
4157
Auke Kok9a799d72007-09-15 14:07:45 -07004158 if (pci_using_dac)
4159 netdev->features |= NETIF_F_HIGHDMA;
4160
Auke Kok9a799d72007-09-15 14:07:45 -07004161 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004162 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07004163 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
4164 err = -EIO;
4165 goto err_eeprom;
4166 }
4167
4168 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
4169 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
4170
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004171 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
4172 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004173 err = -EIO;
4174 goto err_eeprom;
4175 }
4176
4177 init_timer(&adapter->watchdog_timer);
4178 adapter->watchdog_timer.function = &ixgbe_watchdog;
4179 adapter->watchdog_timer.data = (unsigned long)adapter;
4180
4181 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004182 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004183
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004184 err = ixgbe_init_interrupt_scheme(adapter);
4185 if (err)
4186 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07004187
4188 /* print bus type/speed/width info */
4189 pci_read_config_word(pdev, IXGBE_PCI_LINK_STATUS, &link_status);
4190 link_speed = link_status & IXGBE_PCI_LINK_SPEED;
4191 link_width = link_status & IXGBE_PCI_LINK_WIDTH;
Johannes Berg7c510e42008-10-27 17:47:26 -07004192 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004193 ((link_speed == IXGBE_PCI_LINK_SPEED_5000) ? "5.0Gb/s" :
4194 (link_speed == IXGBE_PCI_LINK_SPEED_2500) ? "2.5Gb/s" :
4195 "Unknown"),
4196 ((link_width == IXGBE_PCI_LINK_WIDTH_8) ? "Width x8" :
4197 (link_width == IXGBE_PCI_LINK_WIDTH_4) ? "Width x4" :
4198 (link_width == IXGBE_PCI_LINK_WIDTH_2) ? "Width x2" :
4199 (link_width == IXGBE_PCI_LINK_WIDTH_1) ? "Width x1" :
4200 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07004201 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004202 ixgbe_read_pba_num_generic(hw, &part_num);
Auke Kok9a799d72007-09-15 14:07:45 -07004203 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004204 hw->mac.type, hw->phy.type,
4205 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07004206
Auke Kok0c254d82008-02-11 09:25:56 -08004207 if (link_width <= IXGBE_PCI_LINK_WIDTH_4) {
4208 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004209 "this card is not sufficient for optimal "
4210 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004211 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004212 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08004213 }
4214
Auke Kok9a799d72007-09-15 14:07:45 -07004215 /* reset the hardware with the new settings */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004216 hw->mac.ops.start_hw(hw);
4217
4218 /* link_config depends on start_hw being called at least once */
4219 err = ixgbe_link_config(hw);
4220 if (err) {
4221 dev_err(&pdev->dev, "setup_link_speed FAILED %d\n", err);
4222 goto err_register;
4223 }
Auke Kok9a799d72007-09-15 14:07:45 -07004224
4225 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004226
4227 strcpy(netdev->name, "eth%d");
4228 err = register_netdev(netdev);
4229 if (err)
4230 goto err_register;
4231
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004232#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03004233 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004234 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
4235 /* always use CB2 mode, difference is masked
4236 * in the CB driver */
4237 IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2);
4238 ixgbe_setup_dca(adapter);
4239 }
4240#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004241
4242 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
4243 cards_found++;
4244 return 0;
4245
4246err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004247 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004248err_hw_init:
4249err_sw_init:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004250 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004251err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08004252 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4253 del_timer_sync(&adapter->sfp_timer);
4254 cancel_work_sync(&adapter->sfp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004255 iounmap(hw->hw_addr);
4256err_ioremap:
4257 free_netdev(netdev);
4258err_alloc_etherdev:
4259 pci_release_regions(pdev);
4260err_pci_reg:
4261err_dma:
4262 pci_disable_device(pdev);
4263 return err;
4264}
4265
4266/**
4267 * ixgbe_remove - Device Removal Routine
4268 * @pdev: PCI device information struct
4269 *
4270 * ixgbe_remove is called by the PCI subsystem to alert the driver
4271 * that it should release a PCI device. The could be caused by a
4272 * Hot-Plug event, or because the driver is going to be removed from
4273 * memory.
4274 **/
4275static void __devexit ixgbe_remove(struct pci_dev *pdev)
4276{
4277 struct net_device *netdev = pci_get_drvdata(pdev);
4278 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004279 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004280
4281 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08004282 /* clear the module not found bit to make sure the worker won't
4283 * reschedule
4284 */
4285 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07004286 del_timer_sync(&adapter->watchdog_timer);
4287
Donald Skidmorec4900be2008-11-20 21:11:42 -08004288 del_timer_sync(&adapter->sfp_timer);
4289 cancel_work_sync(&adapter->watchdog_task);
4290 cancel_work_sync(&adapter->sfp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004291 flush_scheduled_work();
4292
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004293#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004294 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
4295 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
4296 dca_remove_requester(&pdev->dev);
4297 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
4298 }
4299
4300#endif
Donald Skidmorec4900be2008-11-20 21:11:42 -08004301 if (netdev->reg_state == NETREG_REGISTERED)
4302 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004303
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004304 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004305
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004306 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004307
4308 iounmap(adapter->hw.hw_addr);
4309 pci_release_regions(pdev);
4310
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004311 DPRINTK(PROBE, INFO, "complete\n");
4312 kfree(adapter->tx_ring);
4313 kfree(adapter->rx_ring);
4314
Auke Kok9a799d72007-09-15 14:07:45 -07004315 free_netdev(netdev);
4316
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004317 err = pci_disable_pcie_error_reporting(pdev);
4318 if (err)
4319 dev_err(&pdev->dev,
4320 "pci_disable_pcie_error_reporting failed 0x%x\n", err);
4321
Auke Kok9a799d72007-09-15 14:07:45 -07004322 pci_disable_device(pdev);
4323}
4324
4325/**
4326 * ixgbe_io_error_detected - called when PCI error is detected
4327 * @pdev: Pointer to PCI device
4328 * @state: The current pci connection state
4329 *
4330 * This function is called after a PCI bus error affecting
4331 * this device has been detected.
4332 */
4333static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004334 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07004335{
4336 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004337 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004338
4339 netif_device_detach(netdev);
4340
4341 if (netif_running(netdev))
4342 ixgbe_down(adapter);
4343 pci_disable_device(pdev);
4344
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004345 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07004346 return PCI_ERS_RESULT_NEED_RESET;
4347}
4348
4349/**
4350 * ixgbe_io_slot_reset - called after the pci bus has been reset.
4351 * @pdev: Pointer to PCI device
4352 *
4353 * Restart the card from scratch, as if from a cold-boot.
4354 */
4355static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
4356{
4357 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004358 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004359 pci_ers_result_t result;
4360 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004361
4362 if (pci_enable_device(pdev)) {
4363 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004364 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004365 result = PCI_ERS_RESULT_DISCONNECT;
4366 } else {
4367 pci_set_master(pdev);
4368 pci_restore_state(pdev);
4369
4370 pci_enable_wake(pdev, PCI_D3hot, 0);
4371 pci_enable_wake(pdev, PCI_D3cold, 0);
4372
4373 ixgbe_reset(adapter);
4374
4375 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07004376 }
Auke Kok9a799d72007-09-15 14:07:45 -07004377
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004378 err = pci_cleanup_aer_uncorrect_error_status(pdev);
4379 if (err) {
4380 dev_err(&pdev->dev,
4381 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
4382 /* non-fatal, continue */
4383 }
Auke Kok9a799d72007-09-15 14:07:45 -07004384
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08004385 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07004386}
4387
4388/**
4389 * ixgbe_io_resume - called when traffic can start flowing again.
4390 * @pdev: Pointer to PCI device
4391 *
4392 * This callback is called when the error recovery driver tells us that
4393 * its OK to resume normal operation.
4394 */
4395static void ixgbe_io_resume(struct pci_dev *pdev)
4396{
4397 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08004398 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004399
4400 if (netif_running(netdev)) {
4401 if (ixgbe_up(adapter)) {
4402 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
4403 return;
4404 }
4405 }
4406
4407 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004408}
4409
4410static struct pci_error_handlers ixgbe_err_handler = {
4411 .error_detected = ixgbe_io_error_detected,
4412 .slot_reset = ixgbe_io_slot_reset,
4413 .resume = ixgbe_io_resume,
4414};
4415
4416static struct pci_driver ixgbe_driver = {
4417 .name = ixgbe_driver_name,
4418 .id_table = ixgbe_pci_tbl,
4419 .probe = ixgbe_probe,
4420 .remove = __devexit_p(ixgbe_remove),
4421#ifdef CONFIG_PM
4422 .suspend = ixgbe_suspend,
4423 .resume = ixgbe_resume,
4424#endif
4425 .shutdown = ixgbe_shutdown,
4426 .err_handler = &ixgbe_err_handler
4427};
4428
4429/**
4430 * ixgbe_init_module - Driver Registration Routine
4431 *
4432 * ixgbe_init_module is the first routine called when the driver is
4433 * loaded. All it does is register with the PCI subsystem.
4434 **/
4435static int __init ixgbe_init_module(void)
4436{
4437 int ret;
4438 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
4439 ixgbe_driver_string, ixgbe_driver_version);
4440
4441 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
4442
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004443#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004444 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004445#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004446
Auke Kok9a799d72007-09-15 14:07:45 -07004447 ret = pci_register_driver(&ixgbe_driver);
4448 return ret;
4449}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004450
Auke Kok9a799d72007-09-15 14:07:45 -07004451module_init(ixgbe_init_module);
4452
4453/**
4454 * ixgbe_exit_module - Driver Exit Cleanup Routine
4455 *
4456 * ixgbe_exit_module is called just before the driver is removed
4457 * from memory.
4458 **/
4459static void __exit ixgbe_exit_module(void)
4460{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004461#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004462 dca_unregister_notify(&dca_notifier);
4463#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004464 pci_unregister_driver(&ixgbe_driver);
4465}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004466
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004467#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004468static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004469 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004470{
4471 int ret_val;
4472
4473 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004474 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004475
4476 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4477}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004478#endif /* CONFIG_IXGBE_DCA */
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004479
Auke Kok9a799d72007-09-15 14:07:45 -07004480module_exit(ixgbe_exit_module);
4481
4482/* ixgbe_main.c */