blob: 4374f441c4260465120152aa88d0d20b694248bc [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Peter P Waskiewicz Jr3efac5a2009-02-01 01:19:20 -08004 Copyright(c) 1999 - 2009 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
35#include <linux/ip.h>
36#include <linux/tcp.h>
Lucy Liu60127862009-07-22 14:07:33 +000037#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070038#include <linux/ipv6.h>
39#include <net/checksum.h>
40#include <net/ip6_checksum.h>
41#include <linux/ethtool.h>
42#include <linux/if_vlan.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000043#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070044
45#include "ixgbe.h"
46#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000047#include "ixgbe_dcb_82599.h"
Auke Kok9a799d72007-09-15 14:07:45 -070048
49char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070050static const char ixgbe_driver_string[] =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070051 "Intel(R) 10 Gigabit PCI Express Network Driver";
Auke Kok9a799d72007-09-15 14:07:45 -070052
Peter P Waskiewicz Jre0f4daf2009-09-30 12:07:57 +000053#define DRV_VERSION "2.0.44-k2"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070054const char ixgbe_driver_version[] = DRV_VERSION;
Peter P Waskiewicz Jr3efac5a2009-02-01 01:19:20 -080055static char ixgbe_copyright[] = "Copyright (c) 1999-2009 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070056
57static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070058 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000059 [board_82599] = &ixgbe_82599_info,
Auke Kok9a799d72007-09-15 14:07:45 -070060};
61
62/* ixgbe_pci_tbl - PCI Device ID Table
63 *
64 * Wildcard entries (PCI_ANY_ID) should come last
65 * Last entry must be all 0s
66 *
67 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
68 * Class, Class Mask, private data (not used) }
69 */
70static struct pci_device_id ixgbe_pci_tbl[] = {
Don Skidmore1e336d02009-01-26 20:57:51 -080071 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
72 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070073 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070074 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070075 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070076 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070077 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
78 board_82598 },
Peter P Waskiewicz Jr3845bec2009-07-16 15:50:52 +000079 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
80 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070081 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070082 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070083 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
84 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080085 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
86 board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
88 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070089 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
90 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080091 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
92 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -080093 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
94 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +000095 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
96 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +000097 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
98 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +000099 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
100 board_82599 },
Don Skidmore38ad1c82009-10-08 15:35:58 +0000101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
102 board_82599 },
Don Skidmoredbfec662009-10-02 08:58:25 +0000103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
104 board_82599 },
Peter P Waskiewicz Jr89111842009-09-14 07:47:49 +0000105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
106 board_82599 },
Don Skidmore312eb932009-10-02 08:58:04 +0000107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
108 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700109
110 /* required last entry */
111 {0, }
112};
113MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
114
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400115#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800116static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700117 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800118static struct notifier_block dca_notifier = {
119 .notifier_call = ixgbe_notify_dca,
120 .next = NULL,
121 .priority = 0
122};
123#endif
124
Auke Kok9a799d72007-09-15 14:07:45 -0700125MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
126MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
127MODULE_LICENSE("GPL");
128MODULE_VERSION(DRV_VERSION);
129
130#define DEFAULT_DEBUG_LEVEL_SHIFT 3
131
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800132static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
133{
134 u32 ctrl_ext;
135
136 /* Let firmware take over control of h/w */
137 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
138 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700139 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800140}
141
142static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
143{
144 u32 ctrl_ext;
145
146 /* Let firmware know the driver has taken over */
147 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
148 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700149 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800150}
Auke Kok9a799d72007-09-15 14:07:45 -0700151
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000152/*
153 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
154 * @adapter: pointer to adapter struct
155 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
156 * @queue: queue to map the corresponding interrupt to
157 * @msix_vector: the vector to map to the corresponding queue
158 *
159 */
160static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
161 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700162{
163 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000164 struct ixgbe_hw *hw = &adapter->hw;
165 switch (hw->mac.type) {
166 case ixgbe_mac_82598EB:
167 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
168 if (direction == -1)
169 direction = 0;
170 index = (((direction * 64) + queue) >> 2) & 0x1F;
171 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
172 ivar &= ~(0xFF << (8 * (queue & 0x3)));
173 ivar |= (msix_vector << (8 * (queue & 0x3)));
174 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
175 break;
176 case ixgbe_mac_82599EB:
177 if (direction == -1) {
178 /* other causes */
179 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
180 index = ((queue & 1) * 8);
181 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
182 ivar &= ~(0xFF << index);
183 ivar |= (msix_vector << index);
184 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
185 break;
186 } else {
187 /* tx or rx causes */
188 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
189 index = ((16 * (queue & 1)) + (8 * direction));
190 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
191 ivar &= ~(0xFF << index);
192 ivar |= (msix_vector << index);
193 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
194 break;
195 }
196 default:
197 break;
198 }
Auke Kok9a799d72007-09-15 14:07:45 -0700199}
200
Alexander Duyckfe49f042009-06-04 16:00:09 +0000201static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
202 u64 qmask)
203{
204 u32 mask;
205
206 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
207 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
208 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
209 } else {
210 mask = (qmask & 0xFFFFFFFF);
211 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
212 mask = (qmask >> 32);
213 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
214 }
215}
216
Auke Kok9a799d72007-09-15 14:07:45 -0700217static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700218 struct ixgbe_tx_buffer
219 *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700220{
Alexander Duycke5a43542009-12-02 16:46:56 +0000221 if (tx_buffer_info->dma) {
222 if (tx_buffer_info->mapped_as_page)
223 pci_unmap_page(adapter->pdev,
224 tx_buffer_info->dma,
225 tx_buffer_info->length,
226 PCI_DMA_TODEVICE);
227 else
228 pci_unmap_single(adapter->pdev,
229 tx_buffer_info->dma,
230 tx_buffer_info->length,
231 PCI_DMA_TODEVICE);
232 tx_buffer_info->dma = 0;
233 }
Auke Kok9a799d72007-09-15 14:07:45 -0700234 if (tx_buffer_info->skb) {
235 dev_kfree_skb_any(tx_buffer_info->skb);
236 tx_buffer_info->skb = NULL;
237 }
Alexander Duyck44df32c2009-03-31 21:34:23 +0000238 tx_buffer_info->time_stamp = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700239 /* tx_buffer_info must be completely set up in the transmit path */
240}
241
Yi Zou26f23d82009-11-06 12:56:00 +0000242/**
243 * ixgbe_tx_is_paused - check if the tx ring is paused
244 * @adapter: the ixgbe adapter
245 * @tx_ring: the corresponding tx_ring
246 *
247 * If not in DCB mode, checks TFCS.TXOFF, otherwise, find out the
248 * corresponding TC of this tx_ring when checking TFCS.
249 *
250 * Returns : true if paused
251 */
252static inline bool ixgbe_tx_is_paused(struct ixgbe_adapter *adapter,
253 struct ixgbe_ring *tx_ring)
254{
Yi Zou26f23d82009-11-06 12:56:00 +0000255 u32 txoff = IXGBE_TFCS_TXOFF;
256
257#ifdef CONFIG_IXGBE_DCB
258 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Jaswinder Singh Rajput30b768322009-11-20 04:02:27 +0000259 int tc;
Yi Zou26f23d82009-11-06 12:56:00 +0000260 int reg_idx = tx_ring->reg_idx;
261 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
262
263 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
264 tc = reg_idx >> 2;
265 txoff = IXGBE_TFCS_TXOFF0;
266 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
267 tc = 0;
268 txoff = IXGBE_TFCS_TXOFF;
269 if (dcb_i == 8) {
270 /* TC0, TC1 */
271 tc = reg_idx >> 5;
272 if (tc == 2) /* TC2, TC3 */
273 tc += (reg_idx - 64) >> 4;
274 else if (tc == 3) /* TC4, TC5, TC6, TC7 */
275 tc += 1 + ((reg_idx - 96) >> 3);
276 } else if (dcb_i == 4) {
277 /* TC0, TC1 */
278 tc = reg_idx >> 6;
279 if (tc == 1) {
280 tc += (reg_idx - 64) >> 5;
281 if (tc == 2) /* TC2, TC3 */
282 tc += (reg_idx - 96) >> 4;
283 }
284 }
285 }
286 txoff <<= tc;
287 }
288#endif
289 return IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & txoff;
290}
291
Auke Kok9a799d72007-09-15 14:07:45 -0700292static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700293 struct ixgbe_ring *tx_ring,
294 unsigned int eop)
Auke Kok9a799d72007-09-15 14:07:45 -0700295{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700296 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700297
Auke Kok9a799d72007-09-15 14:07:45 -0700298 /* Detect a transmit hang in hardware, this serializes the
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700299 * check with the clearing of time_stamp and movement of eop */
Auke Kok9a799d72007-09-15 14:07:45 -0700300 adapter->detect_tx_hung = false;
Alexander Duyck44df32c2009-03-31 21:34:23 +0000301 if (tx_ring->tx_buffer_info[eop].time_stamp &&
Auke Kok9a799d72007-09-15 14:07:45 -0700302 time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
Yi Zou26f23d82009-11-06 12:56:00 +0000303 !ixgbe_tx_is_paused(adapter, tx_ring)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700304 /* detected Tx unit hang */
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700305 union ixgbe_adv_tx_desc *tx_desc;
306 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
Auke Kok9a799d72007-09-15 14:07:45 -0700307 DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700308 " Tx Queue <%d>\n"
309 " TDH, TDT <%x>, <%x>\n"
Auke Kok9a799d72007-09-15 14:07:45 -0700310 " next_to_use <%x>\n"
311 " next_to_clean <%x>\n"
312 "tx_buffer_info[next_to_clean]\n"
313 " time_stamp <%lx>\n"
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700314 " jiffies <%lx>\n",
315 tx_ring->queue_index,
Alexander Duyck44df32c2009-03-31 21:34:23 +0000316 IXGBE_READ_REG(hw, tx_ring->head),
317 IXGBE_READ_REG(hw, tx_ring->tail),
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700318 tx_ring->next_to_use, eop,
319 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
Auke Kok9a799d72007-09-15 14:07:45 -0700320 return true;
321 }
322
323 return false;
324}
325
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700326#define IXGBE_MAX_TXD_PWR 14
327#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800328
329/* Tx Descriptors needed, worst case */
330#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
331 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
332#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700333 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800334
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700335static void ixgbe_tx_timeout(struct net_device *netdev);
336
Auke Kok9a799d72007-09-15 14:07:45 -0700337/**
338 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000339 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700340 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700341 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000342static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700343 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700344{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000345 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700346 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800347 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
348 struct ixgbe_tx_buffer *tx_buffer_info;
349 unsigned int i, eop, count = 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700350 unsigned int total_bytes = 0, total_packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700351
352 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800353 eop = tx_ring->tx_buffer_info[i].next_to_watch;
354 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
355
356 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000357 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800358 bool cleaned = false;
359 for ( ; !cleaned; count++) {
360 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700361 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
362 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800363 cleaned = (i == eop);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700364 skb = tx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -0700365
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800366 if (cleaned && skb) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800367 unsigned int segs, bytecount;
Yi Zou3d8fd382009-06-08 14:38:44 +0000368 unsigned int hlen = skb_headlen(skb);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700369
370 /* gso_segs is currently only valid for tcp */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800371 segs = skb_shinfo(skb)->gso_segs ?: 1;
Yi Zou3d8fd382009-06-08 14:38:44 +0000372#ifdef IXGBE_FCOE
373 /* adjust for FCoE Sequence Offload */
374 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
375 && (skb->protocol == htons(ETH_P_FCOE)) &&
376 skb_is_gso(skb)) {
377 hlen = skb_transport_offset(skb) +
378 sizeof(struct fc_frame_header) +
379 sizeof(struct fcoe_crc_eof);
380 segs = DIV_ROUND_UP(skb->len - hlen,
381 skb_shinfo(skb)->gso_size);
382 }
383#endif /* IXGBE_FCOE */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800384 /* multiply data chunks by size of headers */
Yi Zou3d8fd382009-06-08 14:38:44 +0000385 bytecount = ((segs - 1) * hlen) + skb->len;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700386 total_packets += segs;
387 total_bytes += bytecount;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800388 }
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700389
Auke Kok9a799d72007-09-15 14:07:45 -0700390 ixgbe_unmap_and_free_tx_resource(adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700391 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700392
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800393 tx_desc->wb.status = 0;
394
Auke Kok9a799d72007-09-15 14:07:45 -0700395 i++;
396 if (i == tx_ring->count)
397 i = 0;
398 }
399
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800400 eop = tx_ring->tx_buffer_info[i].next_to_watch;
401 eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop);
402 }
403
Auke Kok9a799d72007-09-15 14:07:45 -0700404 tx_ring->next_to_clean = i;
405
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800406#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700407 if (unlikely(count && netif_carrier_ok(netdev) &&
408 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800409 /* Make sure that anybody stopping the queue after this
410 * sees the new next_to_clean.
411 */
412 smp_mb();
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800413 if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
414 !test_bit(__IXGBE_DOWN, &adapter->state)) {
415 netif_wake_subqueue(netdev, tx_ring->queue_index);
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +0000416 ++tx_ring->restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800417 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800418 }
Auke Kok9a799d72007-09-15 14:07:45 -0700419
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700420 if (adapter->detect_tx_hung) {
421 if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
422 /* schedule immediate reset if we believe we hung */
423 DPRINTK(PROBE, INFO,
424 "tx hang %d detected, resetting adapter\n",
425 adapter->tx_timeout_count + 1);
426 ixgbe_tx_timeout(adapter->netdev);
427 }
428 }
Auke Kok9a799d72007-09-15 14:07:45 -0700429
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700430 /* re-arm the interrupt */
Alexander Duyckfe49f042009-06-04 16:00:09 +0000431 if (count >= tx_ring->work_limit)
432 ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -0700433
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700434 tx_ring->total_bytes += total_bytes;
435 tx_ring->total_packets += total_packets;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700436 tx_ring->stats.packets += total_packets;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800437 tx_ring->stats.bytes += total_bytes;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000438 return (count < tx_ring->work_limit);
Auke Kok9a799d72007-09-15 14:07:45 -0700439}
440
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400441#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800442static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700443 struct ixgbe_ring *rx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800444{
445 u32 rxctrl;
446 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700447 int q = rx_ring - adapter->rx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800448
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700449 if (rx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800450 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000451 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
452 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
453 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
454 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
455 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
456 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
457 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
458 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800459 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
460 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
Don Skidmore15005a32009-01-19 16:54:13 -0800461 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
462 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000463 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800464 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700465 rx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800466 }
467 put_cpu();
468}
469
470static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700471 struct ixgbe_ring *tx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800472{
473 u32 txctrl;
474 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700475 int q = tx_ring - adapter->tx_ring;
Don Skidmoreee5f7842009-11-06 12:56:20 +0000476 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800477
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700478 if (tx_ring->cpu != cpu) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000479 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Don Skidmoreee5f7842009-11-06 12:56:20 +0000480 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000481 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
482 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
Don Skidmoreee5f7842009-11-06 12:56:20 +0000483 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
484 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000485 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Don Skidmoreee5f7842009-11-06 12:56:20 +0000486 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000487 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
488 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
Don Skidmoreee5f7842009-11-06 12:56:20 +0000489 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
490 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
491 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000492 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700493 tx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800494 }
495 put_cpu();
496}
497
498static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
499{
500 int i;
501
502 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
503 return;
504
Alexander Duycke35ec122009-05-21 13:07:12 +0000505 /* always use CB2 mode, difference is masked in the CB driver */
506 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
507
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800508 for (i = 0; i < adapter->num_tx_queues; i++) {
509 adapter->tx_ring[i].cpu = -1;
510 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
511 }
512 for (i = 0; i < adapter->num_rx_queues; i++) {
513 adapter->rx_ring[i].cpu = -1;
514 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
515 }
516}
517
518static int __ixgbe_notify_dca(struct device *dev, void *data)
519{
520 struct net_device *netdev = dev_get_drvdata(dev);
521 struct ixgbe_adapter *adapter = netdev_priv(netdev);
522 unsigned long event = *(unsigned long *)data;
523
524 switch (event) {
525 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700526 /* if we're already enabled, don't do it again */
527 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
528 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300529 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700530 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800531 ixgbe_setup_dca(adapter);
532 break;
533 }
534 /* Fall Through since DCA is disabled. */
535 case DCA_PROVIDER_REMOVE:
536 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
537 dca_remove_requester(dev);
538 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
539 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
540 }
541 break;
542 }
543
Denis V. Lunev652f0932008-03-27 14:39:17 +0300544 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800545}
546
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400547#endif /* CONFIG_IXGBE_DCA */
Auke Kok9a799d72007-09-15 14:07:45 -0700548/**
549 * ixgbe_receive_skb - Send a completed packet up the stack
550 * @adapter: board private structure
551 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700552 * @status: hardware indication of status of receive
553 * @rx_ring: rx descriptor ring (for a specific queue) to setup
554 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -0700555 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800556static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700557 struct sk_buff *skb, u8 status,
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000558 struct ixgbe_ring *ring,
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700559 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -0700560{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800561 struct ixgbe_adapter *adapter = q_vector->adapter;
562 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700563 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
564 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -0700565
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000566 skb_record_rx_queue(skb, ring->queue_index);
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000567 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
Lucy Liu8a62bab2009-08-13 14:09:38 +0000568 if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800569 vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700570 else
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800571 napi_gro_receive(napi, skb);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700572 } else {
Lucy Liu8a62bab2009-08-13 14:09:38 +0000573 if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000574 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
575 else
576 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700577 }
578}
579
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800580/**
581 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
582 * @adapter: address of board private structure
583 * @status_err: hardware indication of status of receive
584 * @skb: skb currently being received and modified
585 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700586static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +0000587 union ixgbe_adv_rx_desc *rx_desc,
588 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700589{
Don Skidmore8bae1b22009-07-23 18:00:39 +0000590 u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
591
Auke Kok9a799d72007-09-15 14:07:45 -0700592 skb->ip_summed = CHECKSUM_NONE;
593
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700594 /* Rx csum disabled */
595 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -0700596 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800597
598 /* if IP and error */
599 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
600 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700601 adapter->hw_csum_rx_error++;
602 return;
603 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800604
605 if (!(status_err & IXGBE_RXD_STAT_L4CS))
606 return;
607
608 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +0000609 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
610
611 /*
612 * 82599 errata, UDP frames with a 0 checksum can be marked as
613 * checksum errors.
614 */
615 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
616 (adapter->hw.mac.type == ixgbe_mac_82599EB))
617 return;
618
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800619 adapter->hw_csum_rx_error++;
620 return;
621 }
622
Auke Kok9a799d72007-09-15 14:07:45 -0700623 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800624 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -0700625}
626
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000627static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
628 struct ixgbe_ring *rx_ring, u32 val)
629{
630 /*
631 * Force memory writes to complete before letting h/w
632 * know there are new descriptors to fetch. (Only
633 * applicable for weak-ordered memory model archs,
634 * such as IA-64).
635 */
636 wmb();
637 IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
638}
639
Auke Kok9a799d72007-09-15 14:07:45 -0700640/**
641 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
642 * @adapter: address of board private structure
643 **/
644static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700645 struct ixgbe_ring *rx_ring,
646 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700647{
Auke Kok9a799d72007-09-15 14:07:45 -0700648 struct pci_dev *pdev = adapter->pdev;
649 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700650 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700651 unsigned int i;
Auke Kok9a799d72007-09-15 14:07:45 -0700652
653 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700654 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700655
656 while (cleaned_count--) {
657 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
658
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700659 if (!bi->page_dma &&
Yi Zou6e455b892009-08-06 13:05:44 +0000660 (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700661 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700662 bi->page = alloc_page(GFP_ATOMIC);
663 if (!bi->page) {
664 adapter->alloc_rx_page_failed++;
665 goto no_buffers;
666 }
667 bi->page_offset = 0;
668 } else {
669 /* use a half page if we're re-using */
670 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700671 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700672
673 bi->page_dma = pci_map_page(pdev, bi->page,
674 bi->page_offset,
675 (PAGE_SIZE / 2),
676 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700677 }
678
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700679 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800680 struct sk_buff *skb;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +0000681 /* netdev_alloc_skb reserves 32 bytes up front!! */
682 uint bufsz = rx_ring->rx_buf_len + SMP_CACHE_BYTES;
683 skb = netdev_alloc_skb(adapter->netdev, bufsz);
Auke Kok9a799d72007-09-15 14:07:45 -0700684
685 if (!skb) {
686 adapter->alloc_rx_buff_failed++;
687 goto no_buffers;
688 }
689
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +0000690 /* advance the data pointer to the next cache line */
691 skb_reserve(skb, (PTR_ALIGN(skb->data, SMP_CACHE_BYTES)
692 - skb->data));
693
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700694 bi->skb = skb;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000695 bi->dma = pci_map_single(pdev, skb->data,
696 rx_ring->rx_buf_len,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700697 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700698 }
699 /* Refresh the desc even if buffer_addrs didn't change because
700 * each write-back erases this info. */
Yi Zou6e455b892009-08-06 13:05:44 +0000701 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700702 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
703 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700704 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700705 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700706 }
707
708 i++;
709 if (i == rx_ring->count)
710 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700711 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700712 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700713
Auke Kok9a799d72007-09-15 14:07:45 -0700714no_buffers:
715 if (rx_ring->next_to_use != i) {
716 rx_ring->next_to_use = i;
717 if (i-- == 0)
718 i = (rx_ring->count - 1);
719
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000720 ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700721 }
722}
723
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700724static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
725{
726 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
727}
728
729static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
730{
731 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
732}
733
Alexander Duyckf8212f92009-04-27 22:42:37 +0000734static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
735{
736 return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
737 IXGBE_RXDADV_RSCCNT_MASK) >>
738 IXGBE_RXDADV_RSCCNT_SHIFT;
739}
740
741/**
742 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
743 * @skb: pointer to the last skb in the rsc queue
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +0000744 * @count: pointer to number of packets coalesced in this context
Alexander Duyckf8212f92009-04-27 22:42:37 +0000745 *
746 * This function changes a queue full of hw rsc buffers into a completed
747 * packet. It uses the ->prev pointers to find the first packet and then
748 * turns it into the frag list owner.
749 **/
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +0000750static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb,
751 u64 *count)
Alexander Duyckf8212f92009-04-27 22:42:37 +0000752{
753 unsigned int frag_list_size = 0;
754
755 while (skb->prev) {
756 struct sk_buff *prev = skb->prev;
757 frag_list_size += skb->len;
758 skb->prev = NULL;
759 skb = prev;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +0000760 *count += 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000761 }
762
763 skb_shinfo(skb)->frag_list = skb->next;
764 skb->next = NULL;
765 skb->len += frag_list_size;
766 skb->data_len += frag_list_size;
767 skb->truesize += frag_list_size;
768 return skb;
769}
770
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800771static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700772 struct ixgbe_ring *rx_ring,
773 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700774{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800775 struct ixgbe_adapter *adapter = q_vector->adapter;
Ajit Khaparde2d86f132009-10-07 02:43:49 +0000776 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -0700777 struct pci_dev *pdev = adapter->pdev;
778 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
779 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
780 struct sk_buff *skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000781 unsigned int i, rsc_count = 0;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700782 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700783 u16 hdr_info;
784 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700785 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800786 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +0000787#ifdef IXGBE_FCOE
788 int ddp_bytes = 0;
789#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -0700790
791 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700792 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
793 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
794 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700795
796 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700797 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700798 if (*work_done >= work_to_do)
799 break;
800 (*work_done)++;
801
Yi Zou6e455b892009-08-06 13:05:44 +0000802 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700803 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
804 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700805 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700806 if (len > IXGBE_RX_HDR_SIZE)
807 len = IXGBE_RX_HDR_SIZE;
808 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700809 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700810 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700811 }
Auke Kok9a799d72007-09-15 14:07:45 -0700812
813 cleaned = true;
814 skb = rx_buffer_info->skb;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +0000815 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -0700816 rx_buffer_info->skb = NULL;
817
Alexander Duyck21fa4e62009-06-04 15:59:49 +0000818 if (rx_buffer_info->dma) {
Auke Kok9a799d72007-09-15 14:07:45 -0700819 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800820 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700821 PCI_DMA_FROMDEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000822 rx_buffer_info->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700823 skb_put(skb, len);
824 }
825
826 if (upper_len) {
827 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700828 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700829 rx_buffer_info->page_dma = 0;
830 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700831 rx_buffer_info->page,
832 rx_buffer_info->page_offset,
833 upper_len);
834
835 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
836 (page_count(rx_buffer_info->page) != 1))
837 rx_buffer_info->page = NULL;
838 else
839 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700840
841 skb->len += upper_len;
842 skb->data_len += upper_len;
843 skb->truesize += upper_len;
844 }
845
846 i++;
847 if (i == rx_ring->count)
848 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700849
850 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
851 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -0700852 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000853
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +0000854 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
Alexander Duyckf8212f92009-04-27 22:42:37 +0000855 rsc_count = ixgbe_get_rsc_count(rx_desc);
856
857 if (rsc_count) {
858 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
859 IXGBE_RXDADV_NEXTP_SHIFT;
860 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +0000861 } else {
862 next_buffer = &rx_ring->rx_buffer_info[i];
863 }
864
Auke Kok9a799d72007-09-15 14:07:45 -0700865 if (staterr & IXGBE_RXD_STAT_EOP) {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000866 if (skb->prev)
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +0000867 skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count));
868 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
869 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)
870 rx_ring->rsc_count += skb_shinfo(skb)->nr_frags;
871 else
872 rx_ring->rsc_count++;
873 rx_ring->rsc_flush++;
874 }
Auke Kok9a799d72007-09-15 14:07:45 -0700875 rx_ring->stats.packets++;
876 rx_ring->stats.bytes += skb->len;
877 } else {
Yi Zou6e455b892009-08-06 13:05:44 +0000878 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000879 rx_buffer_info->skb = next_buffer->skb;
880 rx_buffer_info->dma = next_buffer->dma;
881 next_buffer->skb = skb;
882 next_buffer->dma = 0;
883 } else {
884 skb->next = next_buffer->skb;
885 skb->next->prev = skb;
886 }
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +0000887 rx_ring->non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -0700888 goto next_desc;
889 }
890
891 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
892 dev_kfree_skb_irq(skb);
893 goto next_desc;
894 }
895
Don Skidmore8bae1b22009-07-23 18:00:39 +0000896 ixgbe_rx_checksum(adapter, rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800897
898 /* probably a little skewed due to removing CRC */
899 total_rx_bytes += skb->len;
900 total_rx_packets++;
901
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700902 skb->protocol = eth_type_trans(skb, adapter->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +0000903#ifdef IXGBE_FCOE
904 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +0000905 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
906 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
907 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +0000908 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +0000909 }
Yi Zou332d4a72009-05-13 13:11:53 +0000910#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000911 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700912
913next_desc:
914 rx_desc->wb.upper.status_error = 0;
915
916 /* return some buffers to hardware, one at a time is too slow */
917 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
918 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
919 cleaned_count = 0;
920 }
921
922 /* use prefetched values */
923 rx_desc = next_rxd;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000924 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700925
926 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700927 }
928
Auke Kok9a799d72007-09-15 14:07:45 -0700929 rx_ring->next_to_clean = i;
930 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
931
932 if (cleaned_count)
933 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
934
Yi Zou3d8fd382009-06-08 14:38:44 +0000935#ifdef IXGBE_FCOE
936 /* include DDPed FCoE data */
937 if (ddp_bytes > 0) {
938 unsigned int mss;
939
940 mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) -
941 sizeof(struct fc_frame_header) -
942 sizeof(struct fcoe_crc_eof);
943 if (mss > 512)
944 mss &= ~511;
945 total_rx_bytes += ddp_bytes;
946 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
947 }
948#endif /* IXGBE_FCOE */
949
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800950 rx_ring->total_packets += total_rx_packets;
951 rx_ring->total_bytes += total_rx_bytes;
Ajit Khaparde2d86f132009-10-07 02:43:49 +0000952 netdev->stats.rx_bytes += total_rx_bytes;
953 netdev->stats.rx_packets += total_rx_packets;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800954
Auke Kok9a799d72007-09-15 14:07:45 -0700955 return cleaned;
956}
957
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800958static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700959/**
960 * ixgbe_configure_msix - Configure MSI-X hardware
961 * @adapter: board private structure
962 *
963 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
964 * interrupts.
965 **/
966static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
967{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800968 struct ixgbe_q_vector *q_vector;
969 int i, j, q_vectors, v_idx, r_idx;
970 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700971
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800972 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
973
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000974 /*
975 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800976 * corresponding register.
977 */
978 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +0000979 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800980 /* XXX for_each_bit(...) */
981 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700982 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800983
984 for (i = 0; i < q_vector->rxr_count; i++) {
985 j = adapter->rx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000986 ixgbe_set_ivar(adapter, 0, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800987 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700988 adapter->num_rx_queues,
989 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800990 }
991 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700992 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800993
994 for (i = 0; i < q_vector->txr_count; i++) {
995 j = adapter->tx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000996 ixgbe_set_ivar(adapter, 1, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800997 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700998 adapter->num_tx_queues,
999 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001000 }
1001
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001002 if (q_vector->txr_count && !q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001003 /* tx only */
1004 q_vector->eitr = adapter->tx_eitr_param;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001005 else if (q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001006 /* rx or mixed */
1007 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001008
Alexander Duyckfe49f042009-06-04 16:00:09 +00001009 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001010 }
1011
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001012 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
1013 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
1014 v_idx);
1015 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
1016 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001017 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001018
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001019 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001020 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001021 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001022 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001023}
1024
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001025enum latency_range {
1026 lowest_latency = 0,
1027 low_latency = 1,
1028 bulk_latency = 2,
1029 latency_invalid = 255
1030};
1031
1032/**
1033 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1034 * @adapter: pointer to adapter
1035 * @eitr: eitr setting (ints per sec) to give last timeslice
1036 * @itr_setting: current throttle rate in ints/second
1037 * @packets: the number of packets during this measurement interval
1038 * @bytes: the number of bytes during this measurement interval
1039 *
1040 * Stores a new ITR value based on packets and byte
1041 * counts during the last interrupt. The advantage of per interrupt
1042 * computation is faster updates and more accurate ITR for the current
1043 * traffic pattern. Constants in this function were computed
1044 * based on theoretical maximum wire speed and thresholds were set based
1045 * on testing data as well as attempting to minimize response time
1046 * while increasing bulk throughput.
1047 * this functionality is controlled by the InterruptThrottleRate module
1048 * parameter (see ixgbe_param.c)
1049 **/
1050static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001051 u32 eitr, u8 itr_setting,
1052 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001053{
1054 unsigned int retval = itr_setting;
1055 u32 timepassed_us;
1056 u64 bytes_perint;
1057
1058 if (packets == 0)
1059 goto update_itr_done;
1060
1061
1062 /* simple throttlerate management
1063 * 0-20MB/s lowest (100000 ints/s)
1064 * 20-100MB/s low (20000 ints/s)
1065 * 100-1249MB/s bulk (8000 ints/s)
1066 */
1067 /* what was last interrupt timeslice? */
1068 timepassed_us = 1000000/eitr;
1069 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1070
1071 switch (itr_setting) {
1072 case lowest_latency:
1073 if (bytes_perint > adapter->eitr_low)
1074 retval = low_latency;
1075 break;
1076 case low_latency:
1077 if (bytes_perint > adapter->eitr_high)
1078 retval = bulk_latency;
1079 else if (bytes_perint <= adapter->eitr_low)
1080 retval = lowest_latency;
1081 break;
1082 case bulk_latency:
1083 if (bytes_perint <= adapter->eitr_high)
1084 retval = low_latency;
1085 break;
1086 }
1087
1088update_itr_done:
1089 return retval;
1090}
1091
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001092/**
1093 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001094 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001095 *
1096 * This function is made to be called by ethtool and by the driver
1097 * when it needs to update EITR registers at runtime. Hardware
1098 * specific quirks/differences are taken care of here.
1099 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001100void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001101{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001102 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001103 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001104 int v_idx = q_vector->v_idx;
1105 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1106
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001107 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1108 /* must write high and low 16 bits to reset counter */
1109 itr_reg |= (itr_reg << 16);
1110 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1111 /*
1112 * set the WDIS bit to not clear the timer bits and cause an
1113 * immediate assertion of the interrupt
1114 */
1115 itr_reg |= IXGBE_EITR_CNT_WDIS;
1116 }
1117 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1118}
1119
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001120static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1121{
1122 struct ixgbe_adapter *adapter = q_vector->adapter;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001123 u32 new_itr;
1124 u8 current_itr, ret_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001125 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001126 struct ixgbe_ring *rx_ring, *tx_ring;
1127
1128 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1129 for (i = 0; i < q_vector->txr_count; i++) {
1130 tx_ring = &(adapter->tx_ring[r_idx]);
1131 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001132 q_vector->tx_itr,
1133 tx_ring->total_packets,
1134 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001135 /* if the result for this queue would decrease interrupt
1136 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001137 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001138 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001139 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001140 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001141 }
1142
1143 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1144 for (i = 0; i < q_vector->rxr_count; i++) {
1145 rx_ring = &(adapter->rx_ring[r_idx]);
1146 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001147 q_vector->rx_itr,
1148 rx_ring->total_packets,
1149 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001150 /* if the result for this queue would decrease interrupt
1151 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001152 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001153 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001154 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001155 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001156 }
1157
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001158 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001159
1160 switch (current_itr) {
1161 /* counts and packets in update_itr are dependent on these numbers */
1162 case lowest_latency:
1163 new_itr = 100000;
1164 break;
1165 case low_latency:
1166 new_itr = 20000; /* aka hwitr = ~200 */
1167 break;
1168 case bulk_latency:
1169 default:
1170 new_itr = 8000;
1171 break;
1172 }
1173
1174 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001175 /* do an exponential smoothing */
1176 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001177
1178 /* save the algorithm value here, not the smoothed one */
1179 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001180
1181 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001182 }
1183
1184 return;
1185}
1186
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001187static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1188{
1189 struct ixgbe_hw *hw = &adapter->hw;
1190
1191 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1192 (eicr & IXGBE_EICR_GPI_SDP1)) {
1193 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
1194 /* write to clear the interrupt */
1195 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1196 }
1197}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001198
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001199static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1200{
1201 struct ixgbe_hw *hw = &adapter->hw;
1202
1203 if (eicr & IXGBE_EICR_GPI_SDP1) {
1204 /* Clear the interrupt */
1205 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1206 schedule_work(&adapter->multispeed_fiber_task);
1207 } else if (eicr & IXGBE_EICR_GPI_SDP2) {
1208 /* Clear the interrupt */
1209 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1210 schedule_work(&adapter->sfp_config_module_task);
1211 } else {
1212 /* Interrupt isn't for us... */
1213 return;
1214 }
1215}
1216
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001217static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1218{
1219 struct ixgbe_hw *hw = &adapter->hw;
1220
1221 adapter->lsc_int++;
1222 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1223 adapter->link_check_timeout = jiffies;
1224 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1225 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001226 IXGBE_WRITE_FLUSH(hw);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001227 schedule_work(&adapter->watchdog_task);
1228 }
1229}
1230
Auke Kok9a799d72007-09-15 14:07:45 -07001231static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1232{
1233 struct net_device *netdev = data;
1234 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1235 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001236 u32 eicr;
1237
1238 /*
1239 * Workaround for Silicon errata. Use clear-by-write instead
1240 * of clear-by-read. Reading with EICS will return the
1241 * interrupt causes without clearing, which later be done
1242 * with the write to EICR.
1243 */
1244 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1245 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001246
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001247 if (eicr & IXGBE_EICR_LSC)
1248 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001249
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001250 if (hw->mac.type == ixgbe_mac_82598EB)
1251 ixgbe_check_fan_failure(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001252
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001253 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001254 ixgbe_check_sfp_event(adapter, eicr);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001255
1256 /* Handle Flow Director Full threshold interrupt */
1257 if (eicr & IXGBE_EICR_FLOW_DIR) {
1258 int i;
1259 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
1260 /* Disable transmits before FDIR Re-initialization */
1261 netif_tx_stop_all_queues(netdev);
1262 for (i = 0; i < adapter->num_tx_queues; i++) {
1263 struct ixgbe_ring *tx_ring =
1264 &adapter->tx_ring[i];
1265 if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE,
1266 &tx_ring->reinit_state))
1267 schedule_work(&adapter->fdir_reinit_task);
1268 }
1269 }
1270 }
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001271 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1272 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -07001273
1274 return IRQ_HANDLED;
1275}
1276
Alexander Duyckfe49f042009-06-04 16:00:09 +00001277static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1278 u64 qmask)
1279{
1280 u32 mask;
1281
1282 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1283 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1284 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1285 } else {
1286 mask = (qmask & 0xFFFFFFFF);
1287 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
1288 mask = (qmask >> 32);
1289 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
1290 }
1291 /* skip the flush */
1292}
1293
1294static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
1295 u64 qmask)
1296{
1297 u32 mask;
1298
1299 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1300 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1301 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
1302 } else {
1303 mask = (qmask & 0xFFFFFFFF);
1304 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
1305 mask = (qmask >> 32);
1306 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
1307 }
1308 /* skip the flush */
1309}
1310
Auke Kok9a799d72007-09-15 14:07:45 -07001311static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1312{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001313 struct ixgbe_q_vector *q_vector = data;
1314 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001315 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001316 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001317
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001318 if (!q_vector->txr_count)
1319 return IRQ_HANDLED;
1320
1321 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1322 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001323 tx_ring = &(adapter->tx_ring[r_idx]);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001324 tx_ring->total_bytes = 0;
1325 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001326 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001327 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001328 }
1329
Jesse Brandeburg9b471442009-12-03 11:33:54 +00001330 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00001331 napi_schedule(&q_vector->napi);
1332
Auke Kok9a799d72007-09-15 14:07:45 -07001333 return IRQ_HANDLED;
1334}
1335
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001336/**
1337 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1338 * @irq: unused
1339 * @data: pointer to our q_vector struct for this interrupt vector
1340 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001341static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1342{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001343 struct ixgbe_q_vector *q_vector = data;
1344 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001345 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001346 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001347 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001348
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001349 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001350 for (i = 0; i < q_vector->rxr_count; i++) {
1351 rx_ring = &(adapter->rx_ring[r_idx]);
1352 rx_ring->total_bytes = 0;
1353 rx_ring->total_packets = 0;
1354 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1355 r_idx + 1);
1356 }
1357
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001358 if (!q_vector->rxr_count)
1359 return IRQ_HANDLED;
1360
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001361 /* disable interrupts on this vector only */
Jesse Brandeburg9b471442009-12-03 11:33:54 +00001362 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08001363 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001364
Auke Kok9a799d72007-09-15 14:07:45 -07001365 return IRQ_HANDLED;
1366}
1367
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001368static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1369{
Alexander Duyck91281fd2009-06-04 16:00:27 +00001370 struct ixgbe_q_vector *q_vector = data;
1371 struct ixgbe_adapter *adapter = q_vector->adapter;
1372 struct ixgbe_ring *ring;
1373 int r_idx;
1374 int i;
1375
1376 if (!q_vector->txr_count && !q_vector->rxr_count)
1377 return IRQ_HANDLED;
1378
1379 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1380 for (i = 0; i < q_vector->txr_count; i++) {
1381 ring = &(adapter->tx_ring[r_idx]);
1382 ring->total_bytes = 0;
1383 ring->total_packets = 0;
1384 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1385 r_idx + 1);
1386 }
1387
1388 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1389 for (i = 0; i < q_vector->rxr_count; i++) {
1390 ring = &(adapter->rx_ring[r_idx]);
1391 ring->total_bytes = 0;
1392 ring->total_packets = 0;
1393 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1394 r_idx + 1);
1395 }
1396
Jesse Brandeburg9b471442009-12-03 11:33:54 +00001397 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00001398 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001399
1400 return IRQ_HANDLED;
1401}
1402
1403/**
1404 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1405 * @napi: napi struct with our devices info in it
1406 * @budget: amount of work driver is allowed to do this pass, in packets
1407 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001408 * This function is optimized for cleaning one queue only on a single
1409 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001410 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001411static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1412{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001413 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001414 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001415 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001416 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001417 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001418 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001419
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001420 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001421 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001422#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001423 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001424 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001425#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001426
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001427 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001428
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001429 /* If all Rx work done, exit the polling mode */
1430 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001431 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001432 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001433 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001434 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001435 ixgbe_irq_enable_queues(adapter,
1436 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07001437 }
1438
1439 return work_done;
1440}
1441
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001442/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00001443 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001444 * @napi: napi struct with our devices info in it
1445 * @budget: amount of work driver is allowed to do this pass, in packets
1446 *
1447 * This function will clean more than one rx queue associated with a
1448 * q_vector.
1449 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00001450static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001451{
1452 struct ixgbe_q_vector *q_vector =
1453 container_of(napi, struct ixgbe_q_vector, napi);
1454 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001455 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001456 int work_done = 0, i;
1457 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001458 bool tx_clean_complete = true;
1459
1460 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1461 for (i = 0; i < q_vector->txr_count; i++) {
1462 ring = &(adapter->tx_ring[r_idx]);
1463#ifdef CONFIG_IXGBE_DCA
1464 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1465 ixgbe_update_tx_dca(adapter, ring);
1466#endif
1467 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
1468 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1469 r_idx + 1);
1470 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001471
1472 /* attempt to distribute budget to each queue fairly, but don't allow
1473 * the budget to go below 1 because we'll exit polling */
1474 budget /= (q_vector->rxr_count ?: 1);
1475 budget = max(budget, 1);
1476 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1477 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck91281fd2009-06-04 16:00:27 +00001478 ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001479#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001480 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck91281fd2009-06-04 16:00:27 +00001481 ixgbe_update_rx_dca(adapter, ring);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001482#endif
Alexander Duyck91281fd2009-06-04 16:00:27 +00001483 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001484 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1485 r_idx + 1);
1486 }
1487
1488 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck91281fd2009-06-04 16:00:27 +00001489 ring = &(adapter->rx_ring[r_idx]);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001490 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001491 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001492 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001493 if (adapter->rx_itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001494 ixgbe_set_itr_msix(q_vector);
1495 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001496 ixgbe_irq_enable_queues(adapter,
1497 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001498 return 0;
1499 }
1500
1501 return work_done;
1502}
Alexander Duyck91281fd2009-06-04 16:00:27 +00001503
1504/**
1505 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
1506 * @napi: napi struct with our devices info in it
1507 * @budget: amount of work driver is allowed to do this pass, in packets
1508 *
1509 * This function is optimized for cleaning one queue only on a single
1510 * q_vector!!!
1511 **/
1512static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
1513{
1514 struct ixgbe_q_vector *q_vector =
1515 container_of(napi, struct ixgbe_q_vector, napi);
1516 struct ixgbe_adapter *adapter = q_vector->adapter;
1517 struct ixgbe_ring *tx_ring = NULL;
1518 int work_done = 0;
1519 long r_idx;
1520
1521 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1522 tx_ring = &(adapter->tx_ring[r_idx]);
1523#ifdef CONFIG_IXGBE_DCA
1524 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1525 ixgbe_update_tx_dca(adapter, tx_ring);
1526#endif
1527
1528 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
1529 work_done = budget;
1530
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001531 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00001532 if (work_done < budget) {
1533 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001534 if (adapter->tx_itr_setting & 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00001535 ixgbe_set_itr_msix(q_vector);
1536 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1537 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
1538 }
1539
1540 return work_done;
1541}
1542
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001543static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001544 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001545{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001546 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1547
1548 set_bit(r_idx, q_vector->rxr_idx);
1549 q_vector->rxr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001550}
Auke Kok9a799d72007-09-15 14:07:45 -07001551
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001552static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001553 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001554{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001555 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1556
1557 set_bit(t_idx, q_vector->txr_idx);
1558 q_vector->txr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001559}
Auke Kok9a799d72007-09-15 14:07:45 -07001560
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001561/**
1562 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1563 * @adapter: board private structure to initialize
1564 * @vectors: allotted vector count for descriptor rings
1565 *
1566 * This function maps descriptor rings to the queue-specific vectors
1567 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1568 * one vector per ring/queue, but on a constrained vector budget, we
1569 * group the rings as "efficiently" as possible. You would add new
1570 * mapping configurations in here.
1571 **/
1572static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001573 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001574{
1575 int v_start = 0;
1576 int rxr_idx = 0, txr_idx = 0;
1577 int rxr_remaining = adapter->num_rx_queues;
1578 int txr_remaining = adapter->num_tx_queues;
1579 int i, j;
1580 int rqpv, tqpv;
1581 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001582
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001583 /* No mapping required if MSI-X is disabled. */
1584 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001585 goto out;
1586
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001587 /*
1588 * The ideal configuration...
1589 * We have enough vectors to map one per queue.
1590 */
1591 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1592 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1593 map_vector_to_rxq(adapter, v_start, rxr_idx);
1594
1595 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1596 map_vector_to_txq(adapter, v_start, txr_idx);
1597
1598 goto out;
1599 }
1600
1601 /*
1602 * If we don't have enough vectors for a 1-to-1
1603 * mapping, we'll have to group them so there are
1604 * multiple queues per vector.
1605 */
1606 /* Re-adjusting *qpv takes care of the remainder. */
1607 for (i = v_start; i < vectors; i++) {
1608 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1609 for (j = 0; j < rqpv; j++) {
1610 map_vector_to_rxq(adapter, i, rxr_idx);
1611 rxr_idx++;
1612 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001613 }
Auke Kok9a799d72007-09-15 14:07:45 -07001614 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001615 for (i = v_start; i < vectors; i++) {
1616 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1617 for (j = 0; j < tqpv; j++) {
1618 map_vector_to_txq(adapter, i, txr_idx);
1619 txr_idx++;
1620 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001621 }
Auke Kok9a799d72007-09-15 14:07:45 -07001622 }
1623
Auke Kok9a799d72007-09-15 14:07:45 -07001624out:
Auke Kok9a799d72007-09-15 14:07:45 -07001625 return err;
1626}
1627
1628/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001629 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1630 * @adapter: board private structure
1631 *
1632 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1633 * interrupts from the kernel.
1634 **/
1635static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1636{
1637 struct net_device *netdev = adapter->netdev;
1638 irqreturn_t (*handler)(int, void *);
1639 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001640 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001641
1642 /* Decrement for Other and TCP Timer vectors */
1643 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1644
1645 /* Map the Tx/Rx rings to the vectors we were allotted. */
1646 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1647 if (err)
1648 goto out;
1649
1650#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001651 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1652 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001653 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001654 handler = SET_HANDLER(adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001655
1656 if(handler == &ixgbe_msix_clean_rx) {
1657 sprintf(adapter->name[vector], "%s-%s-%d",
1658 netdev->name, "rx", ri++);
1659 }
1660 else if(handler == &ixgbe_msix_clean_tx) {
1661 sprintf(adapter->name[vector], "%s-%s-%d",
1662 netdev->name, "tx", ti++);
1663 }
1664 else
1665 sprintf(adapter->name[vector], "%s-%s-%d",
1666 netdev->name, "TxRx", vector);
1667
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001668 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001669 handler, 0, adapter->name[vector],
Alexander Duyck7a921c92009-05-06 10:43:28 +00001670 adapter->q_vector[vector]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001671 if (err) {
1672 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001673 "request_irq failed for MSIX interrupt "
1674 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001675 goto free_queue_irqs;
1676 }
1677 }
1678
1679 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1680 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001681 ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001682 if (err) {
1683 DPRINTK(PROBE, ERR,
1684 "request_irq for msix_lsc failed: %d\n", err);
1685 goto free_queue_irqs;
1686 }
1687
1688 return 0;
1689
1690free_queue_irqs:
1691 for (i = vector - 1; i >= 0; i--)
1692 free_irq(adapter->msix_entries[--vector].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001693 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001694 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1695 pci_disable_msix(adapter->pdev);
1696 kfree(adapter->msix_entries);
1697 adapter->msix_entries = NULL;
1698out:
1699 return err;
1700}
1701
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001702static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1703{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001704 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001705 u8 current_itr;
1706 u32 new_itr = q_vector->eitr;
1707 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1708 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1709
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001710 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001711 q_vector->tx_itr,
1712 tx_ring->total_packets,
1713 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001714 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001715 q_vector->rx_itr,
1716 rx_ring->total_packets,
1717 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001718
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001719 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001720
1721 switch (current_itr) {
1722 /* counts and packets in update_itr are dependent on these numbers */
1723 case lowest_latency:
1724 new_itr = 100000;
1725 break;
1726 case low_latency:
1727 new_itr = 20000; /* aka hwitr = ~200 */
1728 break;
1729 case bulk_latency:
1730 new_itr = 8000;
1731 break;
1732 default:
1733 break;
1734 }
1735
1736 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001737 /* do an exponential smoothing */
1738 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001739
1740 /* save the algorithm value here, not the smoothed one */
1741 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001742
1743 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001744 }
1745
1746 return;
1747}
1748
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001749/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001750 * ixgbe_irq_enable - Enable default interrupt generation settings
1751 * @adapter: board private structure
1752 **/
1753static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1754{
1755 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00001756
1757 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
David S. Miller6ab33d52008-11-20 16:44:00 -08001758 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1759 mask |= IXGBE_EIMS_GPI_SDP1;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001760 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001761 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001762 mask |= IXGBE_EIMS_GPI_SDP1;
1763 mask |= IXGBE_EIMS_GPI_SDP2;
1764 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001765 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
1766 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
1767 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001768
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001769 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Nelson, Shannon835462f2009-04-27 22:42:54 +00001770 ixgbe_irq_enable_queues(adapter, ~0);
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001771 IXGBE_WRITE_FLUSH(&adapter->hw);
1772}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001773
1774/**
1775 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001776 * @irq: interrupt number
1777 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001778 **/
1779static irqreturn_t ixgbe_intr(int irq, void *data)
1780{
1781 struct net_device *netdev = data;
1782 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1783 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001784 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07001785 u32 eicr;
1786
Don Skidmore54037502009-02-21 15:42:56 -08001787 /*
1788 * Workaround for silicon errata. Mask the interrupts
1789 * before the read of EICR.
1790 */
1791 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1792
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001793 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1794 * therefore no explict interrupt disable is necessary */
1795 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001796 if (!eicr) {
1797 /* shared interrupt alert!
1798 * make sure interrupts are enabled because the read will
1799 * have disabled interrupts due to EIAM */
1800 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001801 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001802 }
Auke Kok9a799d72007-09-15 14:07:45 -07001803
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001804 if (eicr & IXGBE_EICR_LSC)
1805 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001806
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001807 if (hw->mac.type == ixgbe_mac_82599EB)
1808 ixgbe_check_sfp_event(adapter, eicr);
1809
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001810 ixgbe_check_fan_failure(adapter, eicr);
1811
Alexander Duyck7a921c92009-05-06 10:43:28 +00001812 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001813 adapter->tx_ring[0].total_packets = 0;
1814 adapter->tx_ring[0].total_bytes = 0;
1815 adapter->rx_ring[0].total_packets = 0;
1816 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001817 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00001818 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07001819 }
1820
1821 return IRQ_HANDLED;
1822}
1823
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001824static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1825{
1826 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1827
1828 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001829 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001830 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1831 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1832 q_vector->rxr_count = 0;
1833 q_vector->txr_count = 0;
1834 }
1835}
1836
Auke Kok9a799d72007-09-15 14:07:45 -07001837/**
1838 * ixgbe_request_irq - initialize interrupts
1839 * @adapter: board private structure
1840 *
1841 * Attempts to configure interrupts using the best available
1842 * capabilities of the hardware and kernel.
1843 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001844static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001845{
1846 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001847 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001848
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001849 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1850 err = ixgbe_request_msix_irqs(adapter);
1851 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001852 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001853 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001854 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001855 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001856 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001857 }
1858
Auke Kok9a799d72007-09-15 14:07:45 -07001859 if (err)
1860 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1861
Auke Kok9a799d72007-09-15 14:07:45 -07001862 return err;
1863}
1864
1865static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1866{
1867 struct net_device *netdev = adapter->netdev;
1868
1869 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001870 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001871
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001872 q_vectors = adapter->num_msix_vectors;
1873
1874 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001875 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001876
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001877 i--;
1878 for (; i >= 0; i--) {
1879 free_irq(adapter->msix_entries[i].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001880 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001881 }
1882
1883 ixgbe_reset_q_vectors(adapter);
1884 } else {
1885 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001886 }
1887}
1888
1889/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001890 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1891 * @adapter: board private structure
1892 **/
1893static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1894{
Nelson, Shannon835462f2009-04-27 22:42:54 +00001895 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1896 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1897 } else {
1898 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
1899 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001900 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001901 }
1902 IXGBE_WRITE_FLUSH(&adapter->hw);
1903 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1904 int i;
1905 for (i = 0; i < adapter->num_msix_vectors; i++)
1906 synchronize_irq(adapter->msix_entries[i].vector);
1907 } else {
1908 synchronize_irq(adapter->pdev->irq);
1909 }
1910}
1911
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001912/**
Auke Kok9a799d72007-09-15 14:07:45 -07001913 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1914 *
1915 **/
1916static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1917{
Auke Kok9a799d72007-09-15 14:07:45 -07001918 struct ixgbe_hw *hw = &adapter->hw;
1919
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001920 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001921 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001922
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001923 ixgbe_set_ivar(adapter, 0, 0, 0);
1924 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001925
1926 map_vector_to_rxq(adapter, 0, 0);
1927 map_vector_to_txq(adapter, 0, 0);
1928
1929 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001930}
1931
1932/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001933 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001934 * @adapter: board private structure
1935 *
1936 * Configure the Tx unit of the MAC after a reset.
1937 **/
1938static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1939{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001940 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001941 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001942 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001943
1944 /* Setup the HW Tx Head and Tail descriptor pointers */
1945 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001946 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1947 j = ring->reg_idx;
1948 tdba = ring->dma;
1949 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001950 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Yang Hongyang284901a2009-04-06 19:01:15 -07001951 (tdba & DMA_BIT_MASK(32)));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001952 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1953 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1954 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1955 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1956 adapter->tx_ring[i].head = IXGBE_TDH(j);
1957 adapter->tx_ring[i].tail = IXGBE_TDT(j);
Peter P Waskiewicz Jr84f62d42009-09-30 12:07:16 +00001958 /*
1959 * Disable Tx Head Writeback RO bit, since this hoses
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001960 * bookkeeping if things aren't delivered in order.
1961 */
Peter P Waskiewicz Jr84f62d42009-09-30 12:07:16 +00001962 switch (hw->mac.type) {
1963 case ixgbe_mac_82598EB:
1964 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
1965 break;
1966 case ixgbe_mac_82599EB:
1967 default:
1968 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j));
1969 break;
1970 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001971 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Peter P Waskiewicz Jr84f62d42009-09-30 12:07:16 +00001972 switch (hw->mac.type) {
1973 case ixgbe_mac_82598EB:
1974 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
1975 break;
1976 case ixgbe_mac_82599EB:
1977 default:
1978 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl);
1979 break;
1980 }
Auke Kok9a799d72007-09-15 14:07:45 -07001981 }
Don Skidmoreee5f7842009-11-06 12:56:20 +00001982
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001983 if (hw->mac.type == ixgbe_mac_82599EB) {
Don Skidmoreee5f7842009-11-06 12:56:20 +00001984 u32 rttdcs;
1985
1986 /* disable the arbiter while setting MTQC */
1987 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
1988 rttdcs |= IXGBE_RTTDCS_ARBDIS;
1989 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
1990
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001991 /* We enable 8 traffic classes, DCB only */
1992 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1993 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1994 IXGBE_MTQC_8TC_8TQ));
Don Skidmoreee5f7842009-11-06 12:56:20 +00001995 else
1996 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
1997
1998 /* re-eable the arbiter */
1999 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2000 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002001 }
Auke Kok9a799d72007-09-15 14:07:45 -07002002}
2003
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002004#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002005
Yi Zoua6616b42009-08-06 13:05:23 +00002006static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
2007 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002008{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002009 u32 srrctl;
Yi Zoua6616b42009-08-06 13:05:23 +00002010 int index;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002011 struct ixgbe_ring_feature *feature = adapter->ring_feature;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002012
Yi Zoua6616b42009-08-06 13:05:23 +00002013 index = rx_ring->reg_idx;
2014 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
2015 unsigned long mask;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002016 mask = (unsigned long) feature[RING_F_RSS].mask;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07002017 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002018 }
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002019 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
2020
2021 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2022 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
2023
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002024 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2025 IXGBE_SRRCTL_BSIZEHDR_MASK;
2026
Yi Zou6e455b892009-08-06 13:05:44 +00002027 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002028#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2029 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2030#else
2031 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2032#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002033 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002034 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002035 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2036 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002037 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002038 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002039
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002040 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
2041}
2042
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002043static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
2044{
2045 u32 mrqc = 0;
2046 int mask;
2047
2048 if (!(adapter->hw.mac.type == ixgbe_mac_82599EB))
2049 return mrqc;
2050
2051 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2052#ifdef CONFIG_IXGBE_DCB
2053 | IXGBE_FLAG_DCB_ENABLED
2054#endif
2055 );
2056
2057 switch (mask) {
2058 case (IXGBE_FLAG_RSS_ENABLED):
2059 mrqc = IXGBE_MRQC_RSSEN;
2060 break;
2061#ifdef CONFIG_IXGBE_DCB
2062 case (IXGBE_FLAG_DCB_ENABLED):
2063 mrqc = IXGBE_MRQC_RT8TCEN;
2064 break;
2065#endif /* CONFIG_IXGBE_DCB */
2066 default:
2067 break;
2068 }
2069
2070 return mrqc;
2071}
2072
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002073/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002074 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2075 * @adapter: address of board private structure
2076 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002077 **/
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002078static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002079{
2080 struct ixgbe_ring *rx_ring;
2081 struct ixgbe_hw *hw = &adapter->hw;
2082 int j;
2083 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002084 int rx_buf_len;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002085
2086 rx_ring = &adapter->rx_ring[index];
2087 j = rx_ring->reg_idx;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002088 rx_buf_len = rx_ring->rx_buf_len;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002089 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j));
2090 rscctrl |= IXGBE_RSCCTL_RSCEN;
2091 /*
2092 * we must limit the number of descriptors so that the
2093 * total size of max desc * buf_len is not greater
2094 * than 65535
2095 */
2096 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
2097#if (MAX_SKB_FRAGS > 16)
2098 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2099#elif (MAX_SKB_FRAGS > 8)
2100 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2101#elif (MAX_SKB_FRAGS > 4)
2102 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2103#else
2104 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2105#endif
2106 } else {
2107 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2108 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2109 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2110 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2111 else
2112 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2113 }
2114 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl);
2115}
2116
2117/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002118 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002119 * @adapter: board private structure
2120 *
2121 * Configure the Rx unit of the MAC after a reset.
2122 **/
2123static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
2124{
2125 u64 rdba;
2126 struct ixgbe_hw *hw = &adapter->hw;
Yi Zoua6616b42009-08-06 13:05:23 +00002127 struct ixgbe_ring *rx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07002128 struct net_device *netdev = adapter->netdev;
2129 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002130 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002131 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002132 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2133 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2134 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07002135 u32 fctrl, hlreg0;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002136 u32 reta = 0, mrqc = 0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002137 u32 rdrxctl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002138 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07002139
2140 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002141 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07002142
2143 /* Set the RX buffer length according to the mode */
2144 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002145 rx_buf_len = IXGBE_RX_HDR_SIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002146 if (hw->mac.type == ixgbe_mac_82599EB) {
2147 /* PSRTYPE must be initialized in 82599 */
2148 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
2149 IXGBE_PSRTYPE_UDPHDR |
2150 IXGBE_PSRTYPE_IPV4HDR |
Yi Zoudfa12f02009-05-07 10:39:35 +00002151 IXGBE_PSRTYPE_IPV6HDR |
2152 IXGBE_PSRTYPE_L2HDR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002153 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
2154 }
Auke Kok9a799d72007-09-15 14:07:45 -07002155 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00002156 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00002157 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002158 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07002159 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002160 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07002161 }
2162
2163 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
2164 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002165 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002166 fctrl |= IXGBE_FCTRL_PMCF;
Auke Kok9a799d72007-09-15 14:07:45 -07002167 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
2168
2169 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2170 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2171 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
2172 else
2173 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Yi Zou63f39bd2009-05-17 12:34:35 +00002174#ifdef IXGBE_FCOE
Yi Zouf34c5c82009-08-14 12:42:17 +00002175 if (netdev->features & NETIF_F_FCOE_MTU)
Yi Zou63f39bd2009-05-17 12:34:35 +00002176 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2177#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002178 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2179
Auke Kok9a799d72007-09-15 14:07:45 -07002180 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
2181 /* disable receives while setting up the descriptors */
2182 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2183 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
2184
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002185 /*
2186 * Setup the HW Rx Head and Tail Descriptor Pointers and
2187 * the Base and Length of the Rx Descriptor Ring
2188 */
Auke Kok9a799d72007-09-15 14:07:45 -07002189 for (i = 0; i < adapter->num_rx_queues; i++) {
Yi Zoua6616b42009-08-06 13:05:23 +00002190 rx_ring = &adapter->rx_ring[i];
2191 rdba = rx_ring->dma;
2192 j = rx_ring->reg_idx;
Yang Hongyang284901a2009-04-06 19:01:15 -07002193 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32)));
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002194 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
2195 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
2196 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
2197 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
Yi Zoua6616b42009-08-06 13:05:23 +00002198 rx_ring->head = IXGBE_RDH(j);
2199 rx_ring->tail = IXGBE_RDT(j);
2200 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002201
Yi Zou6e455b892009-08-06 13:05:44 +00002202 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
2203 rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED;
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00002204 else
2205 rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002206
Yi Zou63f39bd2009-05-17 12:34:35 +00002207#ifdef IXGBE_FCOE
Yi Zouf34c5c82009-08-14 12:42:17 +00002208 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00002209 struct ixgbe_ring_feature *f;
2210 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00002211 if ((i >= f->mask) && (i < f->mask + f->indices)) {
2212 rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
2213 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
2214 rx_ring->rx_buf_len =
2215 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2216 }
Yi Zou63f39bd2009-05-17 12:34:35 +00002217 }
2218
2219#endif /* IXGBE_FCOE */
Yi Zoua6616b42009-08-06 13:05:23 +00002220 ixgbe_configure_srrctl(adapter, rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002221 }
2222
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002223 if (hw->mac.type == ixgbe_mac_82598EB) {
2224 /*
2225 * For VMDq support of different descriptor types or
2226 * buffer sizes through the use of multiple SRRCTL
2227 * registers, RDRXCTL.MVMEN must be set to 1
2228 *
2229 * also, the manual doesn't mention it clearly but DCA hints
2230 * will only use queue 0's tags unless this bit is set. Side
2231 * effects of setting this bit are only that SRRCTL must be
2232 * fully programmed [0..15]
2233 */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002234 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2235 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
2236 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
Alexander Duyck2f90b862008-11-20 20:52:10 -08002237 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002238
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002239 /* Program MRQC for the distribution of queues */
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002240 mrqc = ixgbe_setup_mrqc(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002241
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002242 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07002243 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002244 for (i = 0, j = 0; i < 128; i++, j++) {
2245 if (j == adapter->ring_feature[RING_F_RSS].indices)
2246 j = 0;
2247 /* reta = 4-byte sliding window of
2248 * 0x00..(indices-1)(indices-1)00..etc. */
2249 reta = (reta << 8) | (j * 0x11);
2250 if ((i & 3) == 3)
2251 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07002252 }
2253
2254 /* Fill out hash function seeds */
2255 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002256 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002257
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002258 if (hw->mac.type == ixgbe_mac_82598EB)
2259 mrqc |= IXGBE_MRQC_RSSEN;
Auke Kok9a799d72007-09-15 14:07:45 -07002260 /* Perform hash on these packet types */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002261 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2262 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2263 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
2264 | IXGBE_MRQC_RSS_FIELD_IPV6
2265 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
2266 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07002267 }
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002268 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002269
2270 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2271
2272 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
2273 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
2274 /* Disable indicating checksum in descriptor, enables
2275 * RSS hash */
2276 rxcsum |= IXGBE_RXCSUM_PCSD;
2277 }
2278 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
2279 /* Enable IPv4 payload checksum for UDP fragments
2280 * if PCSD is not set */
2281 rxcsum |= IXGBE_RXCSUM_IPPCSE;
2282 }
2283
2284 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002285
2286 if (hw->mac.type == ixgbe_mac_82599EB) {
2287 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2288 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002289 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002290 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
2291 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002292
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00002293 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002294 /* Enable 82599 HW-RSC */
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002295 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002296 ixgbe_configure_rscctl(adapter, i);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002297
Alexander Duyckf8212f92009-04-27 22:42:37 +00002298 /* Disable RSC for ACK packets */
2299 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
2300 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
2301 }
Auke Kok9a799d72007-09-15 14:07:45 -07002302}
2303
Auke Kok9a799d72007-09-15 14:07:45 -07002304static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2305{
2306 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002307 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002308
2309 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002310 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002311}
2312
2313static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2314{
2315 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002316 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002317
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002318 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2319 ixgbe_irq_disable(adapter);
2320
Auke Kok9a799d72007-09-15 14:07:45 -07002321 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002322
2323 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2324 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002325
2326 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002327 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07002328}
2329
Don Skidmore068c89b2009-01-19 16:54:36 -08002330static void ixgbe_vlan_rx_register(struct net_device *netdev,
2331 struct vlan_group *grp)
2332{
2333 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2334 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002335 int i, j;
Don Skidmore068c89b2009-01-19 16:54:36 -08002336
2337 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2338 ixgbe_irq_disable(adapter);
2339 adapter->vlgrp = grp;
2340
2341 /*
2342 * For a DCB driver, always enable VLAN tag stripping so we can
2343 * still receive traffic from a DCB-enabled host even if we're
2344 * not in DCB mode.
2345 */
2346 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
Alexander Duyckdc63d372009-11-23 06:32:57 +00002347
2348 /* Disable CFI check */
2349 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2350
2351 /* enable VLAN tag stripping */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002352 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckdc63d372009-11-23 06:32:57 +00002353 ctrl |= IXGBE_VLNCTRL_VME;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002354 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002355 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckdc63d372009-11-23 06:32:57 +00002356 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002357 j = adapter->rx_ring[i].reg_idx;
2358 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
2359 ctrl |= IXGBE_RXDCTL_VME;
2360 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
2361 }
Don Skidmore068c89b2009-01-19 16:54:36 -08002362 }
Alexander Duyckdc63d372009-11-23 06:32:57 +00002363
2364 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
2365
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002366 ixgbe_vlan_rx_add_vid(netdev, 0);
Don Skidmore068c89b2009-01-19 16:54:36 -08002367
2368 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2369 ixgbe_irq_enable(adapter);
2370}
2371
Auke Kok9a799d72007-09-15 14:07:45 -07002372static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
2373{
2374 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2375
2376 if (adapter->vlgrp) {
2377 u16 vid;
2378 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2379 if (!vlan_group_get_device(adapter->vlgrp, vid))
2380 continue;
2381 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
2382 }
2383 }
2384}
2385
Christopher Leech2c5645c2008-08-26 04:27:02 -07002386static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
2387{
2388 struct dev_mc_list *mc_ptr;
2389 u8 *addr = *mc_addr_ptr;
2390 *vmdq = 0;
2391
2392 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
2393 if (mc_ptr->next)
2394 *mc_addr_ptr = mc_ptr->next->dmi_addr;
2395 else
2396 *mc_addr_ptr = NULL;
2397
2398 return addr;
2399}
2400
Auke Kok9a799d72007-09-15 14:07:45 -07002401/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07002402 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07002403 * @netdev: network interface device structure
2404 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07002405 * The set_rx_method entry point is called whenever the unicast/multicast
2406 * address list or the network interface flags are updated. This routine is
2407 * responsible for configuring the hardware for proper unicast, multicast and
2408 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07002409 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07002410static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07002411{
2412 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2413 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07002414 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002415 u8 *addr_list = NULL;
2416 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002417
2418 /* Check for Promiscuous and All Multicast modes */
2419
2420 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07002421 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07002422
2423 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07002424 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002425 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07002426 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07002427 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002428 if (netdev->flags & IFF_ALLMULTI) {
2429 fctrl |= IXGBE_FCTRL_MPE;
2430 fctrl &= ~IXGBE_FCTRL_UPE;
2431 } else {
2432 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2433 }
Alexander Duyck3d016252008-08-26 18:30:04 -07002434 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002435 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002436 }
2437
2438 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07002439 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07002440
Christopher Leech2c5645c2008-08-26 04:27:02 -07002441 /* reprogram secondary unicast list */
Jiri Pirko31278e72009-06-17 01:12:19 +00002442 hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list);
Auke Kok9a799d72007-09-15 14:07:45 -07002443
Christopher Leech2c5645c2008-08-26 04:27:02 -07002444 /* reprogram multicast list */
2445 addr_count = netdev->mc_count;
2446 if (addr_count)
2447 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002448 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2449 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002450}
2451
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002452static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2453{
2454 int q_idx;
2455 struct ixgbe_q_vector *q_vector;
2456 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2457
2458 /* legacy and MSI only use one vector */
2459 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2460 q_vectors = 1;
2461
2462 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002463 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002464 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002465 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002466 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2467 if (!q_vector->rxr_count || !q_vector->txr_count) {
2468 if (q_vector->txr_count == 1)
2469 napi->poll = &ixgbe_clean_txonly;
2470 else if (q_vector->rxr_count == 1)
2471 napi->poll = &ixgbe_clean_rxonly;
2472 }
2473 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002474
2475 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002476 }
2477}
2478
2479static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2480{
2481 int q_idx;
2482 struct ixgbe_q_vector *q_vector;
2483 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2484
2485 /* legacy and MSI only use one vector */
2486 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2487 q_vectors = 1;
2488
2489 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002490 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002491 napi_disable(&q_vector->napi);
2492 }
2493}
2494
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002495#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002496/*
2497 * ixgbe_configure_dcb - Configure DCB hardware
2498 * @adapter: ixgbe adapter struct
2499 *
2500 * This is called by the driver on open to configure the DCB hardware.
2501 * This is also called by the gennetlink interface when reconfiguring
2502 * the DCB state.
2503 */
2504static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2505{
2506 struct ixgbe_hw *hw = &adapter->hw;
2507 u32 txdctl, vlnctrl;
2508 int i, j;
2509
2510 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2511 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2512 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2513
2514 /* reconfigure the hardware */
2515 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2516
2517 for (i = 0; i < adapter->num_tx_queues; i++) {
2518 j = adapter->tx_ring[i].reg_idx;
2519 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2520 /* PThresh workaround for Tx hang with DFP enabled. */
2521 txdctl |= 32;
2522 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2523 }
2524 /* Enable VLAN tag insert/strip */
2525 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002526 if (hw->mac.type == ixgbe_mac_82598EB) {
2527 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2528 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2529 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2530 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2531 vlnctrl |= IXGBE_VLNCTRL_VFE;
2532 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2533 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2534 for (i = 0; i < adapter->num_rx_queues; i++) {
2535 j = adapter->rx_ring[i].reg_idx;
2536 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2537 vlnctrl |= IXGBE_RXDCTL_VME;
2538 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2539 }
2540 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08002541 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2542}
2543
2544#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002545static void ixgbe_configure(struct ixgbe_adapter *adapter)
2546{
2547 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002548 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002549 int i;
2550
Christopher Leech2c5645c2008-08-26 04:27:02 -07002551 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002552
2553 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002554#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002555 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Yi Zoub352e402009-11-06 12:55:38 +00002556 if (hw->mac.type == ixgbe_mac_82598EB)
2557 netif_set_gso_max_size(netdev, 32768);
2558 else
2559 netif_set_gso_max_size(netdev, 65536);
Alexander Duyck2f90b862008-11-20 20:52:10 -08002560 ixgbe_configure_dcb(adapter);
2561 } else {
2562 netif_set_gso_max_size(netdev, 65536);
2563 }
2564#else
2565 netif_set_gso_max_size(netdev, 65536);
2566#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002567
Yi Zoueacd73f2009-05-13 13:11:06 +00002568#ifdef IXGBE_FCOE
2569 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2570 ixgbe_configure_fcoe(adapter);
2571
2572#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002573 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2574 for (i = 0; i < adapter->num_tx_queues; i++)
2575 adapter->tx_ring[i].atr_sample_rate =
2576 adapter->atr_sample_rate;
2577 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
2578 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
2579 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
2580 }
2581
Auke Kok9a799d72007-09-15 14:07:45 -07002582 ixgbe_configure_tx(adapter);
2583 ixgbe_configure_rx(adapter);
2584 for (i = 0; i < adapter->num_rx_queues; i++)
2585 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002586 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07002587}
2588
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002589static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2590{
2591 switch (hw->phy.type) {
2592 case ixgbe_phy_sfp_avago:
2593 case ixgbe_phy_sfp_ftl:
2594 case ixgbe_phy_sfp_intel:
2595 case ixgbe_phy_sfp_unknown:
2596 case ixgbe_phy_tw_tyco:
2597 case ixgbe_phy_tw_unknown:
2598 return true;
2599 default:
2600 return false;
2601 }
2602}
2603
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002604/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002605 * ixgbe_sfp_link_config - set up SFP+ link
2606 * @adapter: pointer to private adapter struct
2607 **/
2608static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2609{
2610 struct ixgbe_hw *hw = &adapter->hw;
2611
2612 if (hw->phy.multispeed_fiber) {
2613 /*
2614 * In multispeed fiber setups, the device may not have
2615 * had a physical connection when the driver loaded.
2616 * If that's the case, the initial link configuration
2617 * couldn't get the MAC into 10G or 1G mode, so we'll
2618 * never have a link status change interrupt fire.
2619 * We need to try and force an autonegotiation
2620 * session, then bring up link.
2621 */
2622 hw->mac.ops.setup_sfp(hw);
2623 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2624 schedule_work(&adapter->multispeed_fiber_task);
2625 } else {
2626 /*
2627 * Direct Attach Cu and non-multispeed fiber modules
2628 * still need to be configured properly prior to
2629 * attempting link.
2630 */
2631 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2632 schedule_work(&adapter->sfp_config_module_task);
2633 }
2634}
2635
2636/**
2637 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002638 * @hw: pointer to private hardware struct
2639 *
2640 * Returns 0 on success, negative on failure
2641 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002642static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002643{
2644 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00002645 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002646 u32 ret = IXGBE_ERR_LINK_SETUP;
2647
2648 if (hw->mac.ops.check_link)
2649 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2650
2651 if (ret)
2652 goto link_cfg_out;
2653
2654 if (hw->mac.ops.get_link_capabilities)
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00002655 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002656 if (ret)
2657 goto link_cfg_out;
2658
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00002659 if (hw->mac.ops.setup_link)
2660 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002661link_cfg_out:
2662 return ret;
2663}
2664
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002665#define IXGBE_MAX_RX_DESC_POLL 10
2666static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2667 int rxr)
2668{
2669 int j = adapter->rx_ring[rxr].reg_idx;
2670 int k;
2671
2672 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2673 if (IXGBE_READ_REG(&adapter->hw,
2674 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2675 break;
2676 else
2677 msleep(1);
2678 }
2679 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2680 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2681 "not set within the polling period\n", rxr);
2682 }
2683 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2684 (adapter->rx_ring[rxr].count - 1));
2685}
2686
Auke Kok9a799d72007-09-15 14:07:45 -07002687static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2688{
2689 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07002690 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002691 int i, j = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002692 int num_rx_rings = adapter->num_rx_queues;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002693 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002694 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002695 u32 txdctl, rxdctl, mhadd;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002696 u32 dmatxctl;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002697 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002698
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002699 ixgbe_get_hw_control(adapter);
2700
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002701 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2702 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002703 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2704 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002705 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002706 } else {
2707 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002708 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002709 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002710 /* XXX: to interrupt immediately for EICS writes, enable this */
2711 /* gpie |= IXGBE_GPIE_EIMEN; */
2712 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2713 }
2714
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002715 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2716 /*
2717 * use EIAM to auto-mask when MSI-X interrupt is asserted
2718 * this saves a register write for every interrupt
2719 */
2720 switch (hw->mac.type) {
2721 case ixgbe_mac_82598EB:
2722 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
2723 break;
2724 default:
2725 case ixgbe_mac_82599EB:
2726 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
2727 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
2728 break;
2729 }
2730 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002731 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2732 * specifically only auto mask tx and rx interrupts */
2733 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002734 }
2735
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002736 /* Enable fan failure interrupt if media type is copper */
2737 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2738 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2739 gpie |= IXGBE_SDP1_GPIEN;
2740 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2741 }
2742
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002743 if (hw->mac.type == ixgbe_mac_82599EB) {
2744 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2745 gpie |= IXGBE_SDP1_GPIEN;
2746 gpie |= IXGBE_SDP2_GPIEN;
2747 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2748 }
2749
Yi Zou63f39bd2009-05-17 12:34:35 +00002750#ifdef IXGBE_FCOE
2751 /* adjust max frame to be able to do baby jumbo for FCoE */
Yi Zouf34c5c82009-08-14 12:42:17 +00002752 if ((netdev->features & NETIF_F_FCOE_MTU) &&
Yi Zou63f39bd2009-05-17 12:34:35 +00002753 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
2754 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
2755
2756#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07002757 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002758 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2759 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2760 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2761
2762 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2763 }
2764
2765 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002766 j = adapter->tx_ring[i].reg_idx;
2767 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002768 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2769 txdctl |= (8 << 16);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002770 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2771 }
2772
2773 if (hw->mac.type == ixgbe_mac_82599EB) {
2774 /* DMATXCTL.EN must be set after all Tx queue config is done */
2775 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2776 dmatxctl |= IXGBE_DMATXCTL_TE;
2777 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2778 }
2779 for (i = 0; i < adapter->num_tx_queues; i++) {
2780 j = adapter->tx_ring[i].reg_idx;
2781 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Auke Kok9a799d72007-09-15 14:07:45 -07002782 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002783 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002784 }
2785
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002786 for (i = 0; i < num_rx_rings; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002787 j = adapter->rx_ring[i].reg_idx;
2788 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2789 /* enable PTHRESH=32 descriptors (half the internal cache)
2790 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2791 * this also removes a pesky rx_no_buffer_count increment */
2792 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002793 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002794 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002795 if (hw->mac.type == ixgbe_mac_82599EB)
2796 ixgbe_rx_desc_queue_enable(adapter, i);
Auke Kok9a799d72007-09-15 14:07:45 -07002797 }
2798 /* enable all receives */
2799 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002800 if (hw->mac.type == ixgbe_mac_82598EB)
2801 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2802 else
2803 rxdctl |= IXGBE_RXCTRL_RXEN;
2804 hw->mac.ops.enable_rx_dma(hw, rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002805
2806 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2807 ixgbe_configure_msix(adapter);
2808 else
2809 ixgbe_configure_msi_and_legacy(adapter);
2810
2811 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002812 ixgbe_napi_enable_all(adapter);
2813
2814 /* clear any pending interrupts, may auto mask */
2815 IXGBE_READ_REG(hw, IXGBE_EICR);
2816
Auke Kok9a799d72007-09-15 14:07:45 -07002817 ixgbe_irq_enable(adapter);
2818
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002819 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00002820 * If this adapter has a fan, check to see if we had a failure
2821 * before we enabled the interrupt.
2822 */
2823 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2824 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2825 if (esdp & IXGBE_ESDP_SDP1)
2826 DPRINTK(DRV, CRIT,
2827 "Fan has stopped, replace the adapter\n");
2828 }
2829
2830 /*
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002831 * For hot-pluggable SFP+ devices, a new SFP+ module may have
Don Skidmore19343de2009-07-02 12:50:31 +00002832 * arrived before interrupts were enabled but after probe. Such
2833 * devices wouldn't have their type identified yet. We need to
2834 * kick off the SFP+ module setup first, then try to bring up link.
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002835 * If we're not hot-pluggable SFP+, we just need to configure link
2836 * and bring it up.
2837 */
Don Skidmore19343de2009-07-02 12:50:31 +00002838 if (hw->phy.type == ixgbe_phy_unknown) {
2839 err = hw->phy.ops.identify(hw);
2840 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore5da43c12009-07-02 12:50:52 +00002841 /*
2842 * Take the device down and schedule the sfp tasklet
2843 * which will unregister_netdev and log it.
2844 */
Don Skidmore19343de2009-07-02 12:50:31 +00002845 ixgbe_down(adapter);
Don Skidmore5da43c12009-07-02 12:50:52 +00002846 schedule_work(&adapter->sfp_config_module_task);
Don Skidmore19343de2009-07-02 12:50:31 +00002847 return err;
2848 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002849 }
2850
2851 if (ixgbe_is_sfp(hw)) {
2852 ixgbe_sfp_link_config(adapter);
2853 } else {
2854 err = ixgbe_non_sfp_link_config(hw);
2855 if (err)
2856 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2857 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002858
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002859 for (i = 0; i < adapter->num_tx_queues; i++)
2860 set_bit(__IXGBE_FDIR_INIT_DONE,
2861 &(adapter->tx_ring[i].reinit_state));
2862
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002863 /* enable transmits */
2864 netif_tx_start_all_queues(netdev);
2865
Auke Kok9a799d72007-09-15 14:07:45 -07002866 /* bring the link up in the watchdog, this could race with our first
2867 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002868 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2869 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002870 mod_timer(&adapter->watchdog_timer, jiffies);
2871 return 0;
2872}
2873
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002874void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2875{
2876 WARN_ON(in_interrupt());
2877 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2878 msleep(1);
2879 ixgbe_down(adapter);
2880 ixgbe_up(adapter);
2881 clear_bit(__IXGBE_RESETTING, &adapter->state);
2882}
2883
Auke Kok9a799d72007-09-15 14:07:45 -07002884int ixgbe_up(struct ixgbe_adapter *adapter)
2885{
2886 /* hardware has been reset, we need to reload some things */
2887 ixgbe_configure(adapter);
2888
2889 return ixgbe_up_complete(adapter);
2890}
2891
2892void ixgbe_reset(struct ixgbe_adapter *adapter)
2893{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002894 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07002895 int err;
2896
2897 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002898 switch (err) {
2899 case 0:
2900 case IXGBE_ERR_SFP_NOT_PRESENT:
2901 break;
2902 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
2903 dev_err(&adapter->pdev->dev, "master disable timed out\n");
2904 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00002905 case IXGBE_ERR_EEPROM_VERSION:
2906 /* We are running on a pre-production device, log a warning */
2907 dev_warn(&adapter->pdev->dev, "This device is a pre-production "
2908 "adapter/LOM. Please be aware there may be issues "
2909 "associated with your hardware. If you are "
2910 "experiencing problems please contact your Intel or "
2911 "hardware representative who provided you with this "
2912 "hardware.\n");
2913 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002914 default:
2915 dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err);
2916 }
Auke Kok9a799d72007-09-15 14:07:45 -07002917
2918 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002919 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002920}
2921
Auke Kok9a799d72007-09-15 14:07:45 -07002922/**
2923 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2924 * @adapter: board private structure
2925 * @rx_ring: ring to free buffers from
2926 **/
2927static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002928 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002929{
2930 struct pci_dev *pdev = adapter->pdev;
2931 unsigned long size;
2932 unsigned int i;
2933
2934 /* Free all the Rx ring sk_buffs */
2935
2936 for (i = 0; i < rx_ring->count; i++) {
2937 struct ixgbe_rx_buffer *rx_buffer_info;
2938
2939 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2940 if (rx_buffer_info->dma) {
2941 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002942 rx_ring->rx_buf_len,
2943 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002944 rx_buffer_info->dma = 0;
2945 }
2946 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002947 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002948 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002949 do {
2950 struct sk_buff *this = skb;
2951 skb = skb->prev;
2952 dev_kfree_skb(this);
2953 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002954 }
2955 if (!rx_buffer_info->page)
2956 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00002957 if (rx_buffer_info->page_dma) {
2958 pci_unmap_page(pdev, rx_buffer_info->page_dma,
2959 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
2960 rx_buffer_info->page_dma = 0;
2961 }
Auke Kok9a799d72007-09-15 14:07:45 -07002962 put_page(rx_buffer_info->page);
2963 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002964 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002965 }
2966
2967 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2968 memset(rx_ring->rx_buffer_info, 0, size);
2969
2970 /* Zero out the descriptor ring */
2971 memset(rx_ring->desc, 0, rx_ring->size);
2972
2973 rx_ring->next_to_clean = 0;
2974 rx_ring->next_to_use = 0;
2975
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002976 if (rx_ring->head)
2977 writel(0, adapter->hw.hw_addr + rx_ring->head);
2978 if (rx_ring->tail)
2979 writel(0, adapter->hw.hw_addr + rx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002980}
2981
2982/**
2983 * ixgbe_clean_tx_ring - Free Tx Buffers
2984 * @adapter: board private structure
2985 * @tx_ring: ring to be cleaned
2986 **/
2987static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002988 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002989{
2990 struct ixgbe_tx_buffer *tx_buffer_info;
2991 unsigned long size;
2992 unsigned int i;
2993
2994 /* Free all the Tx ring sk_buffs */
2995
2996 for (i = 0; i < tx_ring->count; i++) {
2997 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2998 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2999 }
3000
3001 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
3002 memset(tx_ring->tx_buffer_info, 0, size);
3003
3004 /* Zero out the descriptor ring */
3005 memset(tx_ring->desc, 0, tx_ring->size);
3006
3007 tx_ring->next_to_use = 0;
3008 tx_ring->next_to_clean = 0;
3009
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00003010 if (tx_ring->head)
3011 writel(0, adapter->hw.hw_addr + tx_ring->head);
3012 if (tx_ring->tail)
3013 writel(0, adapter->hw.hw_addr + tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07003014}
3015
3016/**
Auke Kok9a799d72007-09-15 14:07:45 -07003017 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
3018 * @adapter: board private structure
3019 **/
3020static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
3021{
3022 int i;
3023
3024 for (i = 0; i < adapter->num_rx_queues; i++)
3025 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
3026}
3027
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003028/**
3029 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
3030 * @adapter: board private structure
3031 **/
3032static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
3033{
3034 int i;
3035
3036 for (i = 0; i < adapter->num_tx_queues; i++)
3037 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
3038}
3039
Auke Kok9a799d72007-09-15 14:07:45 -07003040void ixgbe_down(struct ixgbe_adapter *adapter)
3041{
3042 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003043 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003044 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003045 u32 txdctl;
3046 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07003047
3048 /* signal that we are down to the interrupt handler */
3049 set_bit(__IXGBE_DOWN, &adapter->state);
3050
3051 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003052 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3053 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07003054
3055 netif_tx_disable(netdev);
3056
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003057 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07003058 msleep(10);
3059
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003060 netif_tx_stop_all_queues(netdev);
3061
Auke Kok9a799d72007-09-15 14:07:45 -07003062 ixgbe_irq_disable(adapter);
3063
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003064 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003065
Don Skidmore0a1f87c2009-09-18 09:45:43 +00003066 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3067 del_timer_sync(&adapter->sfp_timer);
Auke Kok9a799d72007-09-15 14:07:45 -07003068 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003069 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07003070
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003071 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3072 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3073 cancel_work_sync(&adapter->fdir_reinit_task);
3074
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003075 /* disable transmits in the hardware now that interrupts are off */
3076 for (i = 0; i < adapter->num_tx_queues; i++) {
3077 j = adapter->tx_ring[i].reg_idx;
3078 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
3079 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
3080 (txdctl & ~IXGBE_TXDCTL_ENABLE));
3081 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00003082 /* Disable the Tx DMA engine on 82599 */
3083 if (hw->mac.type == ixgbe_mac_82599EB)
3084 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
3085 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
3086 ~IXGBE_DMATXCTL_TE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003087
Auke Kok9a799d72007-09-15 14:07:45 -07003088 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003089
Paul Larson6f4a0e42008-06-24 17:00:56 -07003090 if (!pci_channel_offline(adapter->pdev))
3091 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003092 ixgbe_clean_all_tx_rings(adapter);
3093 ixgbe_clean_all_rx_rings(adapter);
3094
Jeff Garzik5dd2d332008-10-16 05:09:31 -04003095#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07003096 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00003097 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07003098#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003099}
3100
Auke Kok9a799d72007-09-15 14:07:45 -07003101/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003102 * ixgbe_poll - NAPI Rx polling callback
3103 * @napi: structure for representing this polling device
3104 * @budget: how many packets driver is allowed to clean
3105 *
3106 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07003107 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003108static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07003109{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00003110 struct ixgbe_q_vector *q_vector =
3111 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003112 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00003113 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003114
Jeff Garzik5dd2d332008-10-16 05:09:31 -04003115#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08003116 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
3117 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
3118 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
3119 }
3120#endif
3121
Alexander Duyckfe49f042009-06-04 16:00:09 +00003122 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08003123 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07003124
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00003125 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003126 work_done = budget;
3127
David S. Miller53e52c72008-01-07 21:06:12 -08003128 /* If budget not fully consumed, exit the polling mode */
3129 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08003130 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00003131 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08003132 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003133 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00003134 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003135 }
Auke Kok9a799d72007-09-15 14:07:45 -07003136 return work_done;
3137}
3138
3139/**
3140 * ixgbe_tx_timeout - Respond to a Tx Hang
3141 * @netdev: network interface device structure
3142 **/
3143static void ixgbe_tx_timeout(struct net_device *netdev)
3144{
3145 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3146
3147 /* Do the reset outside of interrupt context */
3148 schedule_work(&adapter->reset_task);
3149}
3150
3151static void ixgbe_reset_task(struct work_struct *work)
3152{
3153 struct ixgbe_adapter *adapter;
3154 adapter = container_of(work, struct ixgbe_adapter, reset_task);
3155
Alexander Duyck2f90b862008-11-20 20:52:10 -08003156 /* If we're already down or resetting, just bail */
3157 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
3158 test_bit(__IXGBE_RESETTING, &adapter->state))
3159 return;
3160
Auke Kok9a799d72007-09-15 14:07:45 -07003161 adapter->tx_timeout_count++;
3162
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003163 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003164}
3165
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003166#ifdef CONFIG_IXGBE_DCB
3167static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003168{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003169 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003170 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003171
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003172 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
3173 return ret;
3174
3175 f->mask = 0x7 << 3;
3176 adapter->num_rx_queues = f->indices;
3177 adapter->num_tx_queues = f->indices;
3178 ret = true;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003179
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003180 return ret;
3181}
3182#endif
3183
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003184/**
3185 * ixgbe_set_rss_queues: Allocate queues for RSS
3186 * @adapter: board private structure to initialize
3187 *
3188 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
3189 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
3190 *
3191 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003192static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
3193{
3194 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003195 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003196
3197 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003198 f->mask = 0xF;
3199 adapter->num_rx_queues = f->indices;
3200 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003201 ret = true;
3202 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003203 ret = false;
3204 }
3205
3206 return ret;
3207}
3208
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003209/**
3210 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
3211 * @adapter: board private structure to initialize
3212 *
3213 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
3214 * to the original CPU that initiated the Tx session. This runs in addition
3215 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
3216 * Rx load across CPUs using RSS.
3217 *
3218 **/
3219static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
3220{
3221 bool ret = false;
3222 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
3223
3224 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
3225 f_fdir->mask = 0;
3226
3227 /* Flow Director must have RSS enabled */
3228 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3229 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3230 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
3231 adapter->num_tx_queues = f_fdir->indices;
3232 adapter->num_rx_queues = f_fdir->indices;
3233 ret = true;
3234 } else {
3235 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3236 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3237 }
3238 return ret;
3239}
3240
Yi Zou0331a832009-05-17 12:33:52 +00003241#ifdef IXGBE_FCOE
3242/**
3243 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
3244 * @adapter: board private structure to initialize
3245 *
3246 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
3247 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
3248 * rx queues out of the max number of rx queues, instead, it is used as the
3249 * index of the first rx queue used by FCoE.
3250 *
3251 **/
3252static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
3253{
3254 bool ret = false;
3255 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3256
3257 f->indices = min((int)num_online_cpus(), f->indices);
3258 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003259 adapter->num_rx_queues = 1;
3260 adapter->num_tx_queues = 1;
Yi Zou0331a832009-05-17 12:33:52 +00003261#ifdef CONFIG_IXGBE_DCB
3262 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003263 DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n");
Yi Zou0331a832009-05-17 12:33:52 +00003264 ixgbe_set_dcb_queues(adapter);
3265 }
3266#endif
3267 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003268 DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n");
Yi Zou8faa2a72009-07-09 02:29:50 +00003269 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3270 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
3271 ixgbe_set_fdir_queues(adapter);
3272 else
3273 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00003274 }
3275 /* adding FCoE rx rings to the end */
3276 f->mask = adapter->num_rx_queues;
3277 adapter->num_rx_queues += f->indices;
Yi Zou8de8b2e2009-09-03 14:55:50 +00003278 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00003279
3280 ret = true;
3281 }
3282
3283 return ret;
3284}
3285
3286#endif /* IXGBE_FCOE */
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003287/*
3288 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
3289 * @adapter: board private structure to initialize
3290 *
3291 * This is the top level queue allocation routine. The order here is very
3292 * important, starting with the "most" number of features turned on at once,
3293 * and ending with the smallest set of features. This way large combinations
3294 * can be allocated if they're turned on, and smaller combinations are the
3295 * fallthrough conditions.
3296 *
3297 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003298static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
3299{
Yi Zou0331a832009-05-17 12:33:52 +00003300#ifdef IXGBE_FCOE
3301 if (ixgbe_set_fcoe_queues(adapter))
3302 goto done;
3303
3304#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003305#ifdef CONFIG_IXGBE_DCB
3306 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003307 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003308
3309#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003310 if (ixgbe_set_fdir_queues(adapter))
3311 goto done;
3312
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003313 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003314 goto done;
3315
3316 /* fallback to base case */
3317 adapter->num_rx_queues = 1;
3318 adapter->num_tx_queues = 1;
3319
3320done:
3321 /* Notify the stack of the (possibly) reduced Tx Queue count. */
3322 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003323}
3324
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003325static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003326 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003327{
3328 int err, vector_threshold;
3329
3330 /* We'll want at least 3 (vector_threshold):
3331 * 1) TxQ[0] Cleanup
3332 * 2) RxQ[0] Cleanup
3333 * 3) Other (Link Status Change, etc.)
3334 * 4) TCP Timer (optional)
3335 */
3336 vector_threshold = MIN_MSIX_COUNT;
3337
3338 /* The more we get, the more we will assign to Tx/Rx Cleanup
3339 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
3340 * Right now, we simply care about how many we'll get; we'll
3341 * set them up later while requesting irq's.
3342 */
3343 while (vectors >= vector_threshold) {
3344 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003345 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003346 if (!err) /* Success in acquiring all requested vectors. */
3347 break;
3348 else if (err < 0)
3349 vectors = 0; /* Nasty failure, quit now */
3350 else /* err == number of vectors we should try again with */
3351 vectors = err;
3352 }
3353
3354 if (vectors < vector_threshold) {
3355 /* Can't allocate enough MSI-X interrupts? Oh well.
3356 * This just means we'll go with either a single MSI
3357 * vector or fall back to legacy interrupts.
3358 */
3359 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
3360 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3361 kfree(adapter->msix_entries);
3362 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003363 } else {
3364 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08003365 /*
3366 * Adjust for only the vectors we'll use, which is minimum
3367 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
3368 * vectors we were allocated.
3369 */
3370 adapter->num_msix_vectors = min(vectors,
3371 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003372 }
3373}
3374
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003375/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003376 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003377 * @adapter: board private structure to initialize
3378 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003379 * Cache the descriptor ring offsets for RSS to the assigned rings.
3380 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003381 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003382static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003383{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003384 int i;
3385 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003386
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003387 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3388 for (i = 0; i < adapter->num_rx_queues; i++)
3389 adapter->rx_ring[i].reg_idx = i;
3390 for (i = 0; i < adapter->num_tx_queues; i++)
3391 adapter->tx_ring[i].reg_idx = i;
3392 ret = true;
3393 } else {
3394 ret = false;
3395 }
3396
3397 return ret;
3398}
3399
3400#ifdef CONFIG_IXGBE_DCB
3401/**
3402 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
3403 * @adapter: board private structure to initialize
3404 *
3405 * Cache the descriptor ring offsets for DCB to the assigned rings.
3406 *
3407 **/
3408static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
3409{
3410 int i;
3411 bool ret = false;
3412 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
3413
3414 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3415 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08003416 /* the number of queues is assumed to be symmetric */
3417 for (i = 0; i < dcb_i; i++) {
3418 adapter->rx_ring[i].reg_idx = i << 3;
3419 adapter->tx_ring[i].reg_idx = i << 2;
3420 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003421 ret = true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003422 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
PJ Waskiewiczf92ef202009-04-16 15:00:20 +00003423 if (dcb_i == 8) {
3424 /*
3425 * Tx TC0 starts at: descriptor queue 0
3426 * Tx TC1 starts at: descriptor queue 32
3427 * Tx TC2 starts at: descriptor queue 64
3428 * Tx TC3 starts at: descriptor queue 80
3429 * Tx TC4 starts at: descriptor queue 96
3430 * Tx TC5 starts at: descriptor queue 104
3431 * Tx TC6 starts at: descriptor queue 112
3432 * Tx TC7 starts at: descriptor queue 120
3433 *
3434 * Rx TC0-TC7 are offset by 16 queues each
3435 */
3436 for (i = 0; i < 3; i++) {
3437 adapter->tx_ring[i].reg_idx = i << 5;
3438 adapter->rx_ring[i].reg_idx = i << 4;
3439 }
3440 for ( ; i < 5; i++) {
3441 adapter->tx_ring[i].reg_idx =
3442 ((i + 2) << 4);
3443 adapter->rx_ring[i].reg_idx = i << 4;
3444 }
3445 for ( ; i < dcb_i; i++) {
3446 adapter->tx_ring[i].reg_idx =
3447 ((i + 8) << 3);
3448 adapter->rx_ring[i].reg_idx = i << 4;
3449 }
3450
3451 ret = true;
3452 } else if (dcb_i == 4) {
3453 /*
3454 * Tx TC0 starts at: descriptor queue 0
3455 * Tx TC1 starts at: descriptor queue 64
3456 * Tx TC2 starts at: descriptor queue 96
3457 * Tx TC3 starts at: descriptor queue 112
3458 *
3459 * Rx TC0-TC3 are offset by 32 queues each
3460 */
3461 adapter->tx_ring[0].reg_idx = 0;
3462 adapter->tx_ring[1].reg_idx = 64;
3463 adapter->tx_ring[2].reg_idx = 96;
3464 adapter->tx_ring[3].reg_idx = 112;
3465 for (i = 0 ; i < dcb_i; i++)
3466 adapter->rx_ring[i].reg_idx = i << 5;
3467
3468 ret = true;
3469 } else {
3470 ret = false;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003471 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003472 } else {
3473 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003474 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003475 } else {
3476 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003477 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003478
3479 return ret;
3480}
3481#endif
3482
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003483/**
3484 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
3485 * @adapter: board private structure to initialize
3486 *
3487 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
3488 *
3489 **/
3490static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
3491{
3492 int i;
3493 bool ret = false;
3494
3495 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3496 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3497 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
3498 for (i = 0; i < adapter->num_rx_queues; i++)
3499 adapter->rx_ring[i].reg_idx = i;
3500 for (i = 0; i < adapter->num_tx_queues; i++)
3501 adapter->tx_ring[i].reg_idx = i;
3502 ret = true;
3503 }
3504
3505 return ret;
3506}
3507
Yi Zou0331a832009-05-17 12:33:52 +00003508#ifdef IXGBE_FCOE
3509/**
3510 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
3511 * @adapter: board private structure to initialize
3512 *
3513 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
3514 *
3515 */
3516static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
3517{
Yi Zou8de8b2e2009-09-03 14:55:50 +00003518 int i, fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00003519 bool ret = false;
3520 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3521
3522 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3523#ifdef CONFIG_IXGBE_DCB
3524 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003525 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
3526
Yi Zou0331a832009-05-17 12:33:52 +00003527 ixgbe_cache_ring_dcb(adapter);
Yi Zou8de8b2e2009-09-03 14:55:50 +00003528 /* find out queues in TC for FCoE */
3529 fcoe_rx_i = adapter->rx_ring[fcoe->tc].reg_idx + 1;
3530 fcoe_tx_i = adapter->tx_ring[fcoe->tc].reg_idx + 1;
3531 /*
3532 * In 82599, the number of Tx queues for each traffic
3533 * class for both 8-TC and 4-TC modes are:
3534 * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7
3535 * 8 TCs: 32 32 16 16 8 8 8 8
3536 * 4 TCs: 64 64 32 32
3537 * We have max 8 queues for FCoE, where 8 the is
3538 * FCoE redirection table size. If TC for FCoE is
3539 * less than or equal to TC3, we have enough queues
3540 * to add max of 8 queues for FCoE, so we start FCoE
3541 * tx descriptor from the next one, i.e., reg_idx + 1.
3542 * If TC for FCoE is above TC3, implying 8 TC mode,
3543 * and we need 8 for FCoE, we have to take all queues
3544 * in that traffic class for FCoE.
3545 */
3546 if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3))
3547 fcoe_tx_i--;
Yi Zou0331a832009-05-17 12:33:52 +00003548 }
3549#endif /* CONFIG_IXGBE_DCB */
3550 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Yi Zou8faa2a72009-07-09 02:29:50 +00003551 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3552 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
3553 ixgbe_cache_ring_fdir(adapter);
3554 else
3555 ixgbe_cache_ring_rss(adapter);
3556
Yi Zou8de8b2e2009-09-03 14:55:50 +00003557 fcoe_rx_i = f->mask;
3558 fcoe_tx_i = f->mask;
Yi Zou0331a832009-05-17 12:33:52 +00003559 }
Yi Zou8de8b2e2009-09-03 14:55:50 +00003560 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
3561 adapter->rx_ring[f->mask + i].reg_idx = fcoe_rx_i;
3562 adapter->tx_ring[f->mask + i].reg_idx = fcoe_tx_i;
3563 }
Yi Zou0331a832009-05-17 12:33:52 +00003564 ret = true;
3565 }
3566 return ret;
3567}
3568
3569#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003570/**
3571 * ixgbe_cache_ring_register - Descriptor ring to register mapping
3572 * @adapter: board private structure to initialize
3573 *
3574 * Once we know the feature-set enabled for the device, we'll cache
3575 * the register offset the descriptor ring is assigned to.
3576 *
3577 * Note, the order the various feature calls is important. It must start with
3578 * the "most" features enabled at the same time, then trickle down to the
3579 * least amount of features turned on at once.
3580 **/
3581static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
3582{
3583 /* start with default case */
3584 adapter->rx_ring[0].reg_idx = 0;
3585 adapter->tx_ring[0].reg_idx = 0;
3586
Yi Zou0331a832009-05-17 12:33:52 +00003587#ifdef IXGBE_FCOE
3588 if (ixgbe_cache_ring_fcoe(adapter))
3589 return;
3590
3591#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003592#ifdef CONFIG_IXGBE_DCB
3593 if (ixgbe_cache_ring_dcb(adapter))
3594 return;
3595
3596#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003597 if (ixgbe_cache_ring_fdir(adapter))
3598 return;
3599
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003600 if (ixgbe_cache_ring_rss(adapter))
3601 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003602}
3603
Auke Kok9a799d72007-09-15 14:07:45 -07003604/**
3605 * ixgbe_alloc_queues - Allocate memory for all rings
3606 * @adapter: board private structure to initialize
3607 *
3608 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003609 * number of queues at compile-time. The polling_netdev array is
3610 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07003611 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003612static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003613{
3614 int i;
3615
3616 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003617 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07003618 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003619 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07003620
3621 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003622 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003623 if (!adapter->rx_ring)
3624 goto err_rx_ring_allocation;
3625
3626 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003627 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003628 adapter->tx_ring[i].queue_index = i;
3629 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003630
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003631 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003632 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003633 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07003634 }
3635
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003636 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003637
3638 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003639
3640err_rx_ring_allocation:
3641 kfree(adapter->tx_ring);
3642err_tx_ring_allocation:
3643 return -ENOMEM;
3644}
3645
3646/**
3647 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3648 * @adapter: board private structure to initialize
3649 *
3650 * Attempt to configure the interrupts using the best available
3651 * capabilities of the hardware and the kernel.
3652 **/
Al Virofeea6a52008-11-27 15:34:07 -08003653static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003654{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003655 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003656 int err = 0;
3657 int vector, v_budget;
3658
3659 /*
3660 * It's easy to be greedy for MSI-X vectors, but it really
3661 * doesn't do us much good if we have a lot more vectors
3662 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00003663 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003664 */
3665 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
PJ Waskiewicz342bde12009-11-12 23:50:43 +00003666 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003667
3668 /*
3669 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003670 * hw.mac->max_msix_vectors vectors. With features
3671 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3672 * descriptor queues supported by our device. Thus, we cap it off in
3673 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003674 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003675 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003676
3677 /* A failure in MSI-X entry allocation isn't fatal, but it does
3678 * mean we disable MSI-X capabilities of the adapter. */
3679 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003680 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003681 if (adapter->msix_entries) {
3682 for (vector = 0; vector < v_budget; vector++)
3683 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003684
Alexander Duyck7a921c92009-05-06 10:43:28 +00003685 ixgbe_acquire_msix_vectors(adapter, v_budget);
3686
3687 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3688 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003689 }
3690
Alexander Duyck7a921c92009-05-06 10:43:28 +00003691 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
3692 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003693 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3694 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3695 adapter->atr_sample_rate = 0;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003696 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003697
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003698 err = pci_enable_msi(adapter->pdev);
3699 if (!err) {
3700 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
3701 } else {
3702 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003703 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003704 /* reset err */
3705 err = 0;
3706 }
3707
3708out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003709 return err;
3710}
3711
Alexander Duyck7a921c92009-05-06 10:43:28 +00003712/**
3713 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
3714 * @adapter: board private structure to initialize
3715 *
3716 * We allocate one q_vector per queue interrupt. If allocation fails we
3717 * return -ENOMEM.
3718 **/
3719static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
3720{
3721 int q_idx, num_q_vectors;
3722 struct ixgbe_q_vector *q_vector;
3723 int napi_vectors;
3724 int (*poll)(struct napi_struct *, int);
3725
3726 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3727 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3728 napi_vectors = adapter->num_rx_queues;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003729 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003730 } else {
3731 num_q_vectors = 1;
3732 napi_vectors = 1;
3733 poll = &ixgbe_poll;
3734 }
3735
3736 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3737 q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL);
3738 if (!q_vector)
3739 goto err_out;
3740 q_vector->adapter = adapter;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00003741 if (q_vector->txr_count && !q_vector->rxr_count)
3742 q_vector->eitr = adapter->tx_eitr_param;
3743 else
3744 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00003745 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003746 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003747 adapter->q_vector[q_idx] = q_vector;
3748 }
3749
3750 return 0;
3751
3752err_out:
3753 while (q_idx) {
3754 q_idx--;
3755 q_vector = adapter->q_vector[q_idx];
3756 netif_napi_del(&q_vector->napi);
3757 kfree(q_vector);
3758 adapter->q_vector[q_idx] = NULL;
3759 }
3760 return -ENOMEM;
3761}
3762
3763/**
3764 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
3765 * @adapter: board private structure to initialize
3766 *
3767 * This function frees the memory allocated to the q_vectors. In addition if
3768 * NAPI is enabled it will delete any references to the NAPI struct prior
3769 * to freeing the q_vector.
3770 **/
3771static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
3772{
3773 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003774
Alexander Duyck91281fd2009-06-04 16:00:27 +00003775 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00003776 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003777 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00003778 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003779
3780 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3781 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00003782 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003783 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003784 kfree(q_vector);
3785 }
3786}
3787
Don Skidmore7b25cdb2009-08-25 04:47:32 +00003788static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003789{
3790 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3791 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3792 pci_disable_msix(adapter->pdev);
3793 kfree(adapter->msix_entries);
3794 adapter->msix_entries = NULL;
3795 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
3796 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
3797 pci_disable_msi(adapter->pdev);
3798 }
3799 return;
3800}
3801
3802/**
3803 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3804 * @adapter: board private structure to initialize
3805 *
3806 * We determine which interrupt scheme to use based on...
3807 * - Kernel support (MSI, MSI-X)
3808 * - which can be user-defined (via MODULE_PARAM)
3809 * - Hardware queue count (num_*_queues)
3810 * - defined by miscellaneous hardware support/features (RSS, etc.)
3811 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003812int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003813{
3814 int err;
3815
3816 /* Number of supported queues */
3817 ixgbe_set_num_queues(adapter);
3818
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003819 err = ixgbe_set_interrupt_capability(adapter);
3820 if (err) {
3821 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3822 goto err_set_interrupt;
3823 }
3824
Alexander Duyck7a921c92009-05-06 10:43:28 +00003825 err = ixgbe_alloc_q_vectors(adapter);
3826 if (err) {
3827 DPRINTK(PROBE, ERR, "Unable to allocate memory for queue "
3828 "vectors\n");
3829 goto err_alloc_q_vectors;
3830 }
3831
3832 err = ixgbe_alloc_queues(adapter);
3833 if (err) {
3834 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3835 goto err_alloc_queues;
3836 }
3837
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003838 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003839 "Tx Queue count = %u\n",
3840 (adapter->num_rx_queues > 1) ? "Enabled" :
3841 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003842
3843 set_bit(__IXGBE_DOWN, &adapter->state);
3844
3845 return 0;
3846
Alexander Duyck7a921c92009-05-06 10:43:28 +00003847err_alloc_queues:
3848 ixgbe_free_q_vectors(adapter);
3849err_alloc_q_vectors:
3850 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003851err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00003852 return err;
3853}
3854
3855/**
3856 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
3857 * @adapter: board private structure to clear interrupt scheme on
3858 *
3859 * We go through and clear interrupt specific resources and reset the structure
3860 * to pre-load conditions
3861 **/
3862void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
3863{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003864 kfree(adapter->tx_ring);
3865 kfree(adapter->rx_ring);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003866 adapter->tx_ring = NULL;
3867 adapter->rx_ring = NULL;
3868
3869 ixgbe_free_q_vectors(adapter);
3870 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003871}
3872
3873/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08003874 * ixgbe_sfp_timer - worker thread to find a missing module
3875 * @data: pointer to our adapter struct
3876 **/
3877static void ixgbe_sfp_timer(unsigned long data)
3878{
3879 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3880
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003881 /*
3882 * Do the sfp_timer outside of interrupt context due to the
Donald Skidmorec4900be2008-11-20 21:11:42 -08003883 * delays that sfp+ detection requires
3884 */
3885 schedule_work(&adapter->sfp_task);
3886}
3887
3888/**
3889 * ixgbe_sfp_task - worker thread to find a missing module
3890 * @work: pointer to work_struct containing our data
3891 **/
3892static void ixgbe_sfp_task(struct work_struct *work)
3893{
3894 struct ixgbe_adapter *adapter = container_of(work,
3895 struct ixgbe_adapter,
3896 sfp_task);
3897 struct ixgbe_hw *hw = &adapter->hw;
3898
3899 if ((hw->phy.type == ixgbe_phy_nl) &&
3900 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3901 s32 ret = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00003902 if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
Donald Skidmorec4900be2008-11-20 21:11:42 -08003903 goto reschedule;
3904 ret = hw->phy.ops.reset(hw);
3905 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00003906 dev_err(&adapter->pdev->dev, "failed to initialize "
3907 "because an unsupported SFP+ module type "
3908 "was detected.\n"
3909 "Reload the driver after installing a "
3910 "supported module.\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08003911 unregister_netdev(adapter->netdev);
3912 } else {
3913 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3914 hw->phy.sfp_type);
3915 }
3916 /* don't need this routine any more */
3917 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3918 }
3919 return;
3920reschedule:
3921 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3922 mod_timer(&adapter->sfp_timer,
3923 round_jiffies(jiffies + (2 * HZ)));
3924}
3925
3926/**
Auke Kok9a799d72007-09-15 14:07:45 -07003927 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3928 * @adapter: board private structure to initialize
3929 *
3930 * ixgbe_sw_init initializes the Adapter private data structure.
3931 * Fields are initialized based on PCI device information and
3932 * OS network device settings (MTU size).
3933 **/
3934static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3935{
3936 struct ixgbe_hw *hw = &adapter->hw;
3937 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003938 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003939#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003940 int j;
3941 struct tc_configuration *tc;
3942#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003943
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003944 /* PCI config space info */
3945
3946 hw->vendor_id = pdev->vendor;
3947 hw->device_id = pdev->device;
3948 hw->revision_id = pdev->revision;
3949 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3950 hw->subsystem_device_id = pdev->subsystem_device;
3951
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003952 /* Set capability flags */
3953 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3954 adapter->ring_feature[RING_F_RSS].indices = rss;
3955 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003956 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Don Skidmorebf069c92009-05-07 10:39:54 +00003957 if (hw->mac.type == ixgbe_mac_82598EB) {
3958 if (hw->device_id == IXGBE_DEV_ID_82598AT)
3959 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003960 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Don Skidmorebf069c92009-05-07 10:39:54 +00003961 } else if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003962 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003963 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
3964 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003965 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
3966 adapter->ring_feature[RING_F_FDIR].indices =
3967 IXGBE_MAX_FDIR_INDICES;
3968 adapter->atr_sample_rate = 20;
3969 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00003970#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00003971 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
3972 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
3973 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00003974#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00003975 /* Default traffic class to use for FCoE */
3976 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00003977#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00003978#endif /* IXGBE_FCOE */
Alexander Duyckf8212f92009-04-27 22:42:37 +00003979 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003980
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003981#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003982 /* Configure DCB traffic classes */
3983 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3984 tc = &adapter->dcb_cfg.tc_config[j];
3985 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3986 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3987 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3988 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3989 tc->dcb_pfc = pfc_disabled;
3990 }
3991 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3992 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3993 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003994 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003995 adapter->dcb_cfg.round_robin_enable = false;
3996 adapter->dcb_set_bitmap = 0x00;
3997 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3998 adapter->ring_feature[RING_F_DCB].indices);
3999
4000#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004001
4002 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004003 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004004 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004005#ifdef CONFIG_DCB
4006 adapter->last_lfc_mode = hw->fc.current_mode;
4007#endif
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07004008 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
4009 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
4010 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4011 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00004012 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07004013
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004014 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004015 adapter->rx_itr_setting = 1;
4016 adapter->rx_eitr_param = 20000;
4017 adapter->tx_itr_setting = 1;
4018 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004019
4020 /* set defaults for eitr in MegaBytes */
4021 adapter->eitr_low = 10;
4022 adapter->eitr_high = 20;
4023
4024 /* set default ring sizes */
4025 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4026 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4027
Auke Kok9a799d72007-09-15 14:07:45 -07004028 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004029 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004030 dev_err(&pdev->dev, "EEPROM initialization failed\n");
4031 return -EIO;
4032 }
4033
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004034 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07004035 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
4036
Auke Kok9a799d72007-09-15 14:07:45 -07004037 set_bit(__IXGBE_DOWN, &adapter->state);
4038
4039 return 0;
4040}
4041
4042/**
4043 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
4044 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004045 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004046 *
4047 * Return 0 on success, negative on failure
4048 **/
4049int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004050 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004051{
4052 struct pci_dev *pdev = adapter->pdev;
4053 int size;
4054
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004055 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4056 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004057 if (!tx_ring->tx_buffer_info)
4058 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004059 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07004060
4061 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004062 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004063 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004064
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004065 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
4066 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004067 if (!tx_ring->desc)
4068 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004069
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004070 tx_ring->next_to_use = 0;
4071 tx_ring->next_to_clean = 0;
4072 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07004073 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004074
4075err:
4076 vfree(tx_ring->tx_buffer_info);
4077 tx_ring->tx_buffer_info = NULL;
4078 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
4079 "descriptor ring\n");
4080 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004081}
4082
4083/**
Alexander Duyck69888672008-09-11 20:05:39 -07004084 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4085 * @adapter: board private structure
4086 *
4087 * If this function returns with an error, then it's possible one or
4088 * more of the rings is populated (while the rest are not). It is the
4089 * callers duty to clean those orphaned rings.
4090 *
4091 * Return 0 on success, negative on failure
4092 **/
4093static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4094{
4095 int i, err = 0;
4096
4097 for (i = 0; i < adapter->num_tx_queues; i++) {
4098 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
4099 if (!err)
4100 continue;
4101 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
4102 break;
4103 }
4104
4105 return err;
4106}
4107
4108/**
Auke Kok9a799d72007-09-15 14:07:45 -07004109 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
4110 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004111 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004112 *
4113 * Returns 0 on success, negative on failure
4114 **/
4115int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004116 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004117{
4118 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004119 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004120
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004121 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4122 rx_ring->rx_buffer_info = vmalloc(size);
4123 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07004124 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004125 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004126 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07004127 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004128 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07004129
Auke Kok9a799d72007-09-15 14:07:45 -07004130 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004131 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4132 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004133
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004134 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004135
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004136 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07004137 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004138 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004139 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004140 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07004141 }
4142
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004143 rx_ring->next_to_clean = 0;
4144 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004145
4146 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004147
4148alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004149 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004150}
4151
4152/**
Alexander Duyck69888672008-09-11 20:05:39 -07004153 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4154 * @adapter: board private structure
4155 *
4156 * If this function returns with an error, then it's possible one or
4157 * more of the rings is populated (while the rest are not). It is the
4158 * callers duty to clean those orphaned rings.
4159 *
4160 * Return 0 on success, negative on failure
4161 **/
4162
4163static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4164{
4165 int i, err = 0;
4166
4167 for (i = 0; i < adapter->num_rx_queues; i++) {
4168 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
4169 if (!err)
4170 continue;
4171 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
4172 break;
4173 }
4174
4175 return err;
4176}
4177
4178/**
Auke Kok9a799d72007-09-15 14:07:45 -07004179 * ixgbe_free_tx_resources - Free Tx Resources per Queue
4180 * @adapter: board private structure
4181 * @tx_ring: Tx descriptor ring for a specific queue
4182 *
4183 * Free all transmit software resources
4184 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07004185void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
4186 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004187{
4188 struct pci_dev *pdev = adapter->pdev;
4189
4190 ixgbe_clean_tx_ring(adapter, tx_ring);
4191
4192 vfree(tx_ring->tx_buffer_info);
4193 tx_ring->tx_buffer_info = NULL;
4194
4195 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
4196
4197 tx_ring->desc = NULL;
4198}
4199
4200/**
4201 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4202 * @adapter: board private structure
4203 *
4204 * Free all transmit software resources
4205 **/
4206static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4207{
4208 int i;
4209
4210 for (i = 0; i < adapter->num_tx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004211 if (adapter->tx_ring[i].desc)
4212 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004213}
4214
4215/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004216 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004217 * @adapter: board private structure
4218 * @rx_ring: ring to clean the resources from
4219 *
4220 * Free all receive software resources
4221 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07004222void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
4223 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004224{
4225 struct pci_dev *pdev = adapter->pdev;
4226
4227 ixgbe_clean_rx_ring(adapter, rx_ring);
4228
4229 vfree(rx_ring->rx_buffer_info);
4230 rx_ring->rx_buffer_info = NULL;
4231
4232 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
4233
4234 rx_ring->desc = NULL;
4235}
4236
4237/**
4238 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4239 * @adapter: board private structure
4240 *
4241 * Free all receive software resources
4242 **/
4243static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4244{
4245 int i;
4246
4247 for (i = 0; i < adapter->num_rx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004248 if (adapter->rx_ring[i].desc)
4249 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004250}
4251
4252/**
Auke Kok9a799d72007-09-15 14:07:45 -07004253 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4254 * @netdev: network interface device structure
4255 * @new_mtu: new value for maximum frame size
4256 *
4257 * Returns 0 on success, negative on failure
4258 **/
4259static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4260{
4261 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4262 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4263
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004264 /* MTU < 68 is an error and causes problems on some kernels */
4265 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07004266 return -EINVAL;
4267
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004268 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004269 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004270 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004271 netdev->mtu = new_mtu;
4272
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004273 if (netif_running(netdev))
4274 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004275
4276 return 0;
4277}
4278
4279/**
4280 * ixgbe_open - Called when a network interface is made active
4281 * @netdev: network interface device structure
4282 *
4283 * Returns 0 on success, negative value on failure
4284 *
4285 * The open entry point is called when a network interface is made
4286 * active by the system (IFF_UP). At this point all resources needed
4287 * for transmit and receive operations are allocated, the interrupt
4288 * handler is registered with the OS, the watchdog timer is started,
4289 * and the stack is notified that the interface is ready.
4290 **/
4291static int ixgbe_open(struct net_device *netdev)
4292{
4293 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4294 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004295
Auke Kok4bebfaa2008-02-11 09:26:01 -08004296 /* disallow open during test */
4297 if (test_bit(__IXGBE_TESTING, &adapter->state))
4298 return -EBUSY;
4299
Jesse Brandeburg54386462009-04-17 20:44:27 +00004300 netif_carrier_off(netdev);
4301
Auke Kok9a799d72007-09-15 14:07:45 -07004302 /* allocate transmit descriptors */
4303 err = ixgbe_setup_all_tx_resources(adapter);
4304 if (err)
4305 goto err_setup_tx;
4306
Auke Kok9a799d72007-09-15 14:07:45 -07004307 /* allocate receive descriptors */
4308 err = ixgbe_setup_all_rx_resources(adapter);
4309 if (err)
4310 goto err_setup_rx;
4311
4312 ixgbe_configure(adapter);
4313
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004314 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004315 if (err)
4316 goto err_req_irq;
4317
Auke Kok9a799d72007-09-15 14:07:45 -07004318 err = ixgbe_up_complete(adapter);
4319 if (err)
4320 goto err_up;
4321
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004322 netif_tx_start_all_queues(netdev);
4323
Auke Kok9a799d72007-09-15 14:07:45 -07004324 return 0;
4325
4326err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004327 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004328 ixgbe_free_irq(adapter);
4329err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07004330err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004331 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004332err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004333 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004334 ixgbe_reset(adapter);
4335
4336 return err;
4337}
4338
4339/**
4340 * ixgbe_close - Disables a network interface
4341 * @netdev: network interface device structure
4342 *
4343 * Returns 0, this is not allowed to fail
4344 *
4345 * The close entry point is called when an interface is de-activated
4346 * by the OS. The hardware is still under the drivers control, but
4347 * needs to be disabled. A global MAC reset is issued to stop the
4348 * hardware, and all transmit and receive resources are freed.
4349 **/
4350static int ixgbe_close(struct net_device *netdev)
4351{
4352 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004353
4354 ixgbe_down(adapter);
4355 ixgbe_free_irq(adapter);
4356
4357 ixgbe_free_all_tx_resources(adapter);
4358 ixgbe_free_all_rx_resources(adapter);
4359
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004360 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004361
4362 return 0;
4363}
4364
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004365#ifdef CONFIG_PM
4366static int ixgbe_resume(struct pci_dev *pdev)
4367{
4368 struct net_device *netdev = pci_get_drvdata(pdev);
4369 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4370 u32 err;
4371
4372 pci_set_power_state(pdev, PCI_D0);
4373 pci_restore_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004374
4375 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004376 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07004377 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004378 "suspend\n");
4379 return err;
4380 }
4381 pci_set_master(pdev);
4382
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004383 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004384
4385 err = ixgbe_init_interrupt_scheme(adapter);
4386 if (err) {
4387 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
4388 "device\n");
4389 return err;
4390 }
4391
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004392 ixgbe_reset(adapter);
4393
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00004394 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4395
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004396 if (netif_running(netdev)) {
4397 err = ixgbe_open(adapter->netdev);
4398 if (err)
4399 return err;
4400 }
4401
4402 netif_device_attach(netdev);
4403
4404 return 0;
4405}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004406#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004407
4408static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004409{
4410 struct net_device *netdev = pci_get_drvdata(pdev);
4411 struct ixgbe_adapter *adapter = netdev_priv(netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004412 struct ixgbe_hw *hw = &adapter->hw;
4413 u32 ctrl, fctrl;
4414 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004415#ifdef CONFIG_PM
4416 int retval = 0;
4417#endif
4418
4419 netif_device_detach(netdev);
4420
4421 if (netif_running(netdev)) {
4422 ixgbe_down(adapter);
4423 ixgbe_free_irq(adapter);
4424 ixgbe_free_all_tx_resources(adapter);
4425 ixgbe_free_all_rx_resources(adapter);
4426 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00004427 ixgbe_clear_interrupt_scheme(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004428
4429#ifdef CONFIG_PM
4430 retval = pci_save_state(pdev);
4431 if (retval)
4432 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004433
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004434#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004435 if (wufc) {
4436 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004437
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004438 /* turn on all-multi mode if wake on multicast is enabled */
4439 if (wufc & IXGBE_WUFC_MC) {
4440 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4441 fctrl |= IXGBE_FCTRL_MPE;
4442 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4443 }
4444
4445 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4446 ctrl |= IXGBE_CTRL_GIO_DIS;
4447 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4448
4449 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4450 } else {
4451 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4452 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4453 }
4454
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004455 if (wufc && hw->mac.type == ixgbe_mac_82599EB)
4456 pci_wake_from_d3(pdev, true);
4457 else
4458 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004459
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004460 *enable_wake = !!wufc;
4461
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004462 ixgbe_release_hw_control(adapter);
4463
4464 pci_disable_device(pdev);
4465
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004466 return 0;
4467}
4468
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004469#ifdef CONFIG_PM
4470static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4471{
4472 int retval;
4473 bool wake;
4474
4475 retval = __ixgbe_shutdown(pdev, &wake);
4476 if (retval)
4477 return retval;
4478
4479 if (wake) {
4480 pci_prepare_to_sleep(pdev);
4481 } else {
4482 pci_wake_from_d3(pdev, false);
4483 pci_set_power_state(pdev, PCI_D3hot);
4484 }
4485
4486 return 0;
4487}
4488#endif /* CONFIG_PM */
4489
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004490static void ixgbe_shutdown(struct pci_dev *pdev)
4491{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004492 bool wake;
4493
4494 __ixgbe_shutdown(pdev, &wake);
4495
4496 if (system_state == SYSTEM_POWER_OFF) {
4497 pci_wake_from_d3(pdev, wake);
4498 pci_set_power_state(pdev, PCI_D3hot);
4499 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004500}
4501
4502/**
Auke Kok9a799d72007-09-15 14:07:45 -07004503 * ixgbe_update_stats - Update the board statistics counters.
4504 * @adapter: board private structure
4505 **/
4506void ixgbe_update_stats(struct ixgbe_adapter *adapter)
4507{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004508 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07004509 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004510 u64 total_mpc = 0;
4511 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004512
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004513 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004514 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004515 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004516 for (i = 0; i < 16; i++)
4517 adapter->hw_rx_no_dma_resources +=
4518 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004519 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004520 rsc_count += adapter->rx_ring[i].rsc_count;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004521 rsc_flush += adapter->rx_ring[i].rsc_flush;
4522 }
4523 adapter->rsc_total_count = rsc_count;
4524 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004525 }
4526
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00004527 /* gather some stats to the adapter struct that are per queue */
4528 for (i = 0; i < adapter->num_tx_queues; i++)
4529 adapter->restart_queue += adapter->tx_ring[i].restart_queue;
4530
4531 for (i = 0; i < adapter->num_rx_queues; i++)
4532 adapter->non_eop_descs += adapter->tx_ring[i].non_eop_descs;
4533
Auke Kok9a799d72007-09-15 14:07:45 -07004534 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004535 for (i = 0; i < 8; i++) {
4536 /* for packet buffers not used, the register should read 0 */
4537 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
4538 missed_rx += mpc;
4539 adapter->stats.mpc[i] += mpc;
4540 total_mpc += adapter->stats.mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004541 if (hw->mac.type == ixgbe_mac_82598EB)
4542 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004543 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
4544 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
4545 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
4546 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004547 if (hw->mac.type == ixgbe_mac_82599EB) {
4548 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4549 IXGBE_PXONRXCNT(i));
4550 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4551 IXGBE_PXOFFRXCNT(i));
4552 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004553 } else {
4554 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4555 IXGBE_PXONRXC(i));
4556 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4557 IXGBE_PXOFFRXC(i));
4558 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004559 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
4560 IXGBE_PXONTXC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004561 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004562 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004563 }
4564 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
4565 /* work around hardware counting issue */
4566 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07004567
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004568 /* 82598 hardware only has a 32 bit counter in the high register */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004569 if (hw->mac.type == ixgbe_mac_82599EB) {
Ben Greearaad71912009-09-30 12:08:16 +00004570 u64 tmp;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004571 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Ben Greearaad71912009-09-30 12:08:16 +00004572 tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */
4573 adapter->stats.gorc += (tmp << 32);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004574 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Ben Greearaad71912009-09-30 12:08:16 +00004575 tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */
4576 adapter->stats.gotc += (tmp << 32);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004577 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
4578 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
4579 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
4580 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004581 adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
4582 adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00004583#ifdef IXGBE_FCOE
4584 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
4585 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
4586 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
4587 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
4588 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
4589 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
4590#endif /* IXGBE_FCOE */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004591 } else {
4592 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
4593 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
4594 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
4595 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
4596 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
4597 }
Auke Kok9a799d72007-09-15 14:07:45 -07004598 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
4599 adapter->stats.bprc += bprc;
4600 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004601 if (hw->mac.type == ixgbe_mac_82598EB)
4602 adapter->stats.mprc -= bprc;
Auke Kok9a799d72007-09-15 14:07:45 -07004603 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
4604 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
4605 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
4606 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
4607 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
4608 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
4609 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004610 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004611 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
4612 adapter->stats.lxontxc += lxon;
4613 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
4614 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07004615 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4616 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004617 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
4618 /*
4619 * 82598 errata - tx of flow control packets is included in tx counters
4620 */
4621 xon_off_tot = lxon + lxoff;
4622 adapter->stats.gptc -= xon_off_tot;
4623 adapter->stats.mptc -= xon_off_tot;
4624 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07004625 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4626 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
4627 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07004628 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
4629 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004630 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004631 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
4632 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
4633 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
4634 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
4635 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004636 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
4637
4638 /* Fill out the OS statistics structure */
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004639 netdev->stats.multicast = adapter->stats.mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07004640
4641 /* Rx Errors */
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004642 netdev->stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004643 adapter->stats.rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004644 netdev->stats.rx_dropped = 0;
4645 netdev->stats.rx_length_errors = adapter->stats.rlec;
4646 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4647 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07004648}
4649
4650/**
4651 * ixgbe_watchdog - Timer Call-back
4652 * @data: pointer to adapter cast into an unsigned long
4653 **/
4654static void ixgbe_watchdog(unsigned long data)
4655{
4656 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004657 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004658 u64 eics = 0;
4659 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004660
Alexander Duyckfe49f042009-06-04 16:00:09 +00004661 /*
4662 * Do the watchdog outside of interrupt context due to the lovely
4663 * delays that some of the newer hardware requires
4664 */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004665
Alexander Duyckfe49f042009-06-04 16:00:09 +00004666 if (test_bit(__IXGBE_DOWN, &adapter->state))
4667 goto watchdog_short_circuit;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004668
Alexander Duyckfe49f042009-06-04 16:00:09 +00004669 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
4670 /*
4671 * for legacy and MSI interrupts don't set any bits
4672 * that are enabled for EIAM, because this operation
4673 * would set *both* EIMS and EICS for any bit in EIAM
4674 */
4675 IXGBE_WRITE_REG(hw, IXGBE_EICS,
4676 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
4677 goto watchdog_reschedule;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004678 }
4679
Alexander Duyckfe49f042009-06-04 16:00:09 +00004680 /* get one bit for every active tx/rx interrupt vector */
4681 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
4682 struct ixgbe_q_vector *qv = adapter->q_vector[i];
4683 if (qv->rxr_count || qv->txr_count)
4684 eics |= ((u64)1 << i);
4685 }
4686
4687 /* Cause software interrupt to ensure rx rings are cleaned */
4688 ixgbe_irq_rearm_queues(adapter, eics);
4689
4690watchdog_reschedule:
4691 /* Reset the timer */
4692 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
4693
4694watchdog_short_circuit:
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004695 schedule_work(&adapter->watchdog_task);
4696}
4697
4698/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004699 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
4700 * @work: pointer to work_struct containing our data
4701 **/
4702static void ixgbe_multispeed_fiber_task(struct work_struct *work)
4703{
4704 struct ixgbe_adapter *adapter = container_of(work,
4705 struct ixgbe_adapter,
4706 multispeed_fiber_task);
4707 struct ixgbe_hw *hw = &adapter->hw;
4708 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004709 bool negotiation;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004710
4711 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
Mallikarjuna R Chilakalaa1f25322009-06-30 11:44:36 +00004712 autoneg = hw->phy.autoneg_advertised;
4713 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004714 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
4715 if (hw->mac.ops.setup_link)
4716 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004717 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4718 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
4719}
4720
4721/**
4722 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
4723 * @work: pointer to work_struct containing our data
4724 **/
4725static void ixgbe_sfp_config_module_task(struct work_struct *work)
4726{
4727 struct ixgbe_adapter *adapter = container_of(work,
4728 struct ixgbe_adapter,
4729 sfp_config_module_task);
4730 struct ixgbe_hw *hw = &adapter->hw;
4731 u32 err;
4732
4733 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004734
4735 /* Time for electrical oscillations to settle down */
4736 msleep(100);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004737 err = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004738
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004739 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00004740 dev_err(&adapter->pdev->dev, "failed to initialize because "
4741 "an unsupported SFP+ module type was detected.\n"
4742 "Reload the driver after installing a supported "
4743 "module.\n");
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004744 unregister_netdev(adapter->netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004745 return;
4746 }
4747 hw->mac.ops.setup_sfp(hw);
4748
Tony Breeds8d1c3c02009-04-09 22:29:10 +00004749 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004750 /* This will also work for DA Twinax connections */
4751 schedule_work(&adapter->multispeed_fiber_task);
4752 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
4753}
4754
4755/**
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004756 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
4757 * @work: pointer to work_struct containing our data
4758 **/
4759static void ixgbe_fdir_reinit_task(struct work_struct *work)
4760{
4761 struct ixgbe_adapter *adapter = container_of(work,
4762 struct ixgbe_adapter,
4763 fdir_reinit_task);
4764 struct ixgbe_hw *hw = &adapter->hw;
4765 int i;
4766
4767 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
4768 for (i = 0; i < adapter->num_tx_queues; i++)
4769 set_bit(__IXGBE_FDIR_INIT_DONE,
4770 &(adapter->tx_ring[i].reinit_state));
4771 } else {
4772 DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, "
4773 "ignored adding FDIR ATR filters \n");
4774 }
4775 /* Done FDIR Re-initialization, enable transmits */
4776 netif_tx_start_all_queues(adapter->netdev);
4777}
4778
4779/**
Alexander Duyck69888672008-09-11 20:05:39 -07004780 * ixgbe_watchdog_task - worker thread to bring link up
4781 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004782 **/
4783static void ixgbe_watchdog_task(struct work_struct *work)
4784{
4785 struct ixgbe_adapter *adapter = container_of(work,
4786 struct ixgbe_adapter,
4787 watchdog_task);
4788 struct net_device *netdev = adapter->netdev;
4789 struct ixgbe_hw *hw = &adapter->hw;
4790 u32 link_speed = adapter->link_speed;
4791 bool link_up = adapter->link_up;
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004792 int i;
4793 struct ixgbe_ring *tx_ring;
4794 int some_tx_pending = 0;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004795
4796 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
4797
4798 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4799 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004800 if (link_up) {
4801#ifdef CONFIG_DCB
4802 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4803 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004804 hw->mac.ops.fc_enable(hw, i);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004805 } else {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004806 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004807 }
4808#else
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004809 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004810#endif
4811 }
4812
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004813 if (link_up ||
4814 time_after(jiffies, (adapter->link_check_timeout +
4815 IXGBE_TRY_LINK_TIMEOUT))) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004816 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004817 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004818 }
4819 adapter->link_up = link_up;
4820 adapter->link_speed = link_speed;
4821 }
Auke Kok9a799d72007-09-15 14:07:45 -07004822
4823 if (link_up) {
4824 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004825 bool flow_rx, flow_tx;
4826
4827 if (hw->mac.type == ixgbe_mac_82599EB) {
4828 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4829 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
Peter P Waskiewicz Jr078788b2009-07-16 15:50:32 +00004830 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
4831 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004832 } else {
4833 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4834 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
Peter P Waskiewicz Jr078788b2009-07-16 15:50:32 +00004835 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
4836 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004837 }
4838
Jeff Kirshera46e5342008-11-27 00:22:21 -08004839 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
4840 "Flow Control: %s\n",
4841 netdev->name,
4842 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
4843 "10 Gbps" :
4844 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
4845 "1 Gbps" : "unknown speed")),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004846 ((flow_rx && flow_tx) ? "RX/TX" :
4847 (flow_rx ? "RX" :
4848 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07004849
4850 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004851 } else {
4852 /* Force detection of hung controller */
4853 adapter->detect_tx_hung = true;
4854 }
4855 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004856 adapter->link_up = false;
4857 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004858 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08004859 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
4860 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07004861 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004862 }
4863 }
4864
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004865 if (!netif_carrier_ok(netdev)) {
4866 for (i = 0; i < adapter->num_tx_queues; i++) {
4867 tx_ring = &adapter->tx_ring[i];
4868 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
4869 some_tx_pending = 1;
4870 break;
4871 }
4872 }
4873
4874 if (some_tx_pending) {
4875 /* We've lost link, so the controller stops DMA,
4876 * but we've got queued Tx work that's never going
4877 * to get done, so reset controller to flush Tx.
4878 * (Do the reset outside of interrupt context).
4879 */
4880 schedule_work(&adapter->reset_task);
4881 }
4882 }
4883
Auke Kok9a799d72007-09-15 14:07:45 -07004884 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004885 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07004886}
4887
Auke Kok9a799d72007-09-15 14:07:45 -07004888static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004889 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
4890 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004891{
4892 struct ixgbe_adv_tx_context_desc *context_desc;
4893 unsigned int i;
4894 int err;
4895 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004896 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
4897 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07004898
4899 if (skb_is_gso(skb)) {
4900 if (skb_header_cloned(skb)) {
4901 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4902 if (err)
4903 return err;
4904 }
4905 l4len = tcp_hdrlen(skb);
4906 *hdr_len += l4len;
4907
Al Viro8327d002007-12-10 18:54:12 +00004908 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004909 struct iphdr *iph = ip_hdr(skb);
4910 iph->tot_len = 0;
4911 iph->check = 0;
4912 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004913 iph->daddr, 0,
4914 IPPROTO_TCP,
4915 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004916 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
4917 ipv6_hdr(skb)->payload_len = 0;
4918 tcp_hdr(skb)->check =
4919 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004920 &ipv6_hdr(skb)->daddr,
4921 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004922 }
4923
4924 i = tx_ring->next_to_use;
4925
4926 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4927 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4928
4929 /* VLAN MACLEN IPLEN */
4930 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4931 vlan_macip_lens |=
4932 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4933 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004934 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004935 *hdr_len += skb_network_offset(skb);
4936 vlan_macip_lens |=
4937 (skb_transport_header(skb) - skb_network_header(skb));
4938 *hdr_len +=
4939 (skb_transport_header(skb) - skb_network_header(skb));
4940 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4941 context_desc->seqnum_seed = 0;
4942
4943 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004944 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004945 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004946
Al Viro8327d002007-12-10 18:54:12 +00004947 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004948 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4949 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
4950 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4951
4952 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004953 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07004954 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
4955 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004956 /* use index 1 for TSO */
4957 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004958 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4959
4960 tx_buffer_info->time_stamp = jiffies;
4961 tx_buffer_info->next_to_watch = i;
4962
4963 i++;
4964 if (i == tx_ring->count)
4965 i = 0;
4966 tx_ring->next_to_use = i;
4967
4968 return true;
4969 }
4970 return false;
4971}
4972
4973static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004974 struct ixgbe_ring *tx_ring,
4975 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07004976{
4977 struct ixgbe_adv_tx_context_desc *context_desc;
4978 unsigned int i;
4979 struct ixgbe_tx_buffer *tx_buffer_info;
4980 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4981
4982 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4983 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4984 i = tx_ring->next_to_use;
4985 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4986 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4987
4988 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4989 vlan_macip_lens |=
4990 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4991 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004992 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004993 if (skb->ip_summed == CHECKSUM_PARTIAL)
4994 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004995 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07004996
4997 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4998 context_desc->seqnum_seed = 0;
4999
5000 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005001 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07005002
5003 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08005004 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08005005 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07005006 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08005007 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
5008 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005009 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00005010 else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
5011 type_tucmd_mlhl |=
5012 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08005013 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005014 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08005015 /* XXX what about other V6 headers?? */
5016 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5017 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005018 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00005019 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
5020 type_tucmd_mlhl |=
5021 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08005022 break;
Auke Kok41825d72008-02-12 15:20:33 -08005023 default:
5024 if (unlikely(net_ratelimit())) {
5025 DPRINTK(PROBE, WARNING,
5026 "partial checksum but proto=%x!\n",
5027 skb->protocol);
5028 }
5029 break;
5030 }
Auke Kok9a799d72007-09-15 14:07:45 -07005031 }
5032
5033 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07005034 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07005035 context_desc->mss_l4len_idx = 0;
5036
5037 tx_buffer_info->time_stamp = jiffies;
5038 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005039
Auke Kok9a799d72007-09-15 14:07:45 -07005040 i++;
5041 if (i == tx_ring->count)
5042 i = 0;
5043 tx_ring->next_to_use = i;
5044
5045 return true;
5046 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005047
Auke Kok9a799d72007-09-15 14:07:45 -07005048 return false;
5049}
5050
5051static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005052 struct ixgbe_ring *tx_ring,
Yi Zoueacd73f2009-05-13 13:11:06 +00005053 struct sk_buff *skb, u32 tx_flags,
5054 unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07005055{
Alexander Duycke5a43542009-12-02 16:46:56 +00005056 struct pci_dev *pdev = adapter->pdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005057 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00005058 unsigned int len;
5059 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07005060 unsigned int offset = 0, size, count = 0, i;
5061 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
5062 unsigned int f;
Auke Kok9a799d72007-09-15 14:07:45 -07005063
5064 i = tx_ring->next_to_use;
5065
Yi Zoueacd73f2009-05-13 13:11:06 +00005066 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
5067 /* excluding fcoe_crc_eof for FCoE */
5068 total -= sizeof(struct fcoe_crc_eof);
5069
5070 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07005071 while (len) {
5072 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5073 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
5074
5075 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00005076 tx_buffer_info->mapped_as_page = false;
5077 tx_buffer_info->dma = pci_map_single(pdev,
5078 skb->data + offset,
5079 size, PCI_DMA_TODEVICE);
5080 if (pci_dma_mapping_error(pdev, tx_buffer_info->dma))
5081 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07005082 tx_buffer_info->time_stamp = jiffies;
5083 tx_buffer_info->next_to_watch = i;
5084
5085 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00005086 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07005087 offset += size;
5088 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00005089
5090 if (len) {
5091 i++;
5092 if (i == tx_ring->count)
5093 i = 0;
5094 }
Auke Kok9a799d72007-09-15 14:07:45 -07005095 }
5096
5097 for (f = 0; f < nr_frags; f++) {
5098 struct skb_frag_struct *frag;
5099
5100 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00005101 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00005102 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07005103
5104 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00005105 i++;
5106 if (i == tx_ring->count)
5107 i = 0;
5108
Auke Kok9a799d72007-09-15 14:07:45 -07005109 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5110 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
5111
5112 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00005113 tx_buffer_info->dma = pci_map_page(adapter->pdev,
5114 frag->page,
5115 offset, size,
5116 PCI_DMA_TODEVICE);
5117 tx_buffer_info->mapped_as_page = true;
5118 if (pci_dma_mapping_error(pdev, tx_buffer_info->dma))
5119 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07005120 tx_buffer_info->time_stamp = jiffies;
5121 tx_buffer_info->next_to_watch = i;
5122
5123 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00005124 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07005125 offset += size;
5126 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07005127 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005128 if (total == 0)
5129 break;
Auke Kok9a799d72007-09-15 14:07:45 -07005130 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00005131
Auke Kok9a799d72007-09-15 14:07:45 -07005132 tx_ring->tx_buffer_info[i].skb = skb;
5133 tx_ring->tx_buffer_info[first].next_to_watch = i;
5134
5135 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00005136
5137dma_error:
5138 dev_err(&pdev->dev, "TX DMA map failed\n");
5139
5140 /* clear timestamp and dma mappings for failed tx_buffer_info map */
5141 tx_buffer_info->dma = 0;
5142 tx_buffer_info->time_stamp = 0;
5143 tx_buffer_info->next_to_watch = 0;
5144 count--;
5145
5146 /* clear timestamp and dma mappings for remaining portion of packet */
5147 while (count >= 0) {
5148 count--;
5149 i--;
5150 if (i < 0)
5151 i += tx_ring->count;
5152 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5153 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
5154 }
5155
5156 return count;
Auke Kok9a799d72007-09-15 14:07:45 -07005157}
5158
5159static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005160 struct ixgbe_ring *tx_ring,
5161 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07005162{
5163 union ixgbe_adv_tx_desc *tx_desc = NULL;
5164 struct ixgbe_tx_buffer *tx_buffer_info;
5165 u32 olinfo_status = 0, cmd_type_len = 0;
5166 unsigned int i;
5167 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
5168
5169 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
5170
5171 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
5172
5173 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
5174 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
5175
5176 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
5177 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
5178
5179 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005180 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07005181
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07005182 /* use index 1 context for tso */
5183 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07005184 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
5185 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005186 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07005187
5188 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
5189 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005190 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07005191
Yi Zoueacd73f2009-05-13 13:11:06 +00005192 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5193 olinfo_status |= IXGBE_ADVTXD_CC;
5194 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
5195 if (tx_flags & IXGBE_TX_FLAGS_FSO)
5196 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
5197 }
5198
Auke Kok9a799d72007-09-15 14:07:45 -07005199 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
5200
5201 i = tx_ring->next_to_use;
5202 while (count--) {
5203 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5204 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
5205 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
5206 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005207 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07005208 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07005209 i++;
5210 if (i == tx_ring->count)
5211 i = 0;
5212 }
5213
5214 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
5215
5216 /*
5217 * Force memory writes to complete before letting h/w
5218 * know there are new descriptors to fetch. (Only
5219 * applicable for weak-ordered memory model archs,
5220 * such as IA-64).
5221 */
5222 wmb();
5223
5224 tx_ring->next_to_use = i;
5225 writel(i, adapter->hw.hw_addr + tx_ring->tail);
5226}
5227
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005228static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
5229 int queue, u32 tx_flags)
5230{
5231 /* Right now, we support IPv4 only */
5232 struct ixgbe_atr_input atr_input;
5233 struct tcphdr *th;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005234 struct iphdr *iph = ip_hdr(skb);
5235 struct ethhdr *eth = (struct ethhdr *)skb->data;
5236 u16 vlan_id, src_port, dst_port, flex_bytes;
5237 u32 src_ipv4_addr, dst_ipv4_addr;
5238 u8 l4type = 0;
5239
5240 /* check if we're UDP or TCP */
5241 if (iph->protocol == IPPROTO_TCP) {
5242 th = tcp_hdr(skb);
5243 src_port = th->source;
5244 dst_port = th->dest;
5245 l4type |= IXGBE_ATR_L4TYPE_TCP;
5246 /* l4type IPv4 type is 0, no need to assign */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005247 } else {
5248 /* Unsupported L4 header, just bail here */
5249 return;
5250 }
5251
5252 memset(&atr_input, 0, sizeof(struct ixgbe_atr_input));
5253
5254 vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >>
5255 IXGBE_TX_FLAGS_VLAN_SHIFT;
5256 src_ipv4_addr = iph->saddr;
5257 dst_ipv4_addr = iph->daddr;
5258 flex_bytes = eth->h_proto;
5259
5260 ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
5261 ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
5262 ixgbe_atr_set_dst_port_82599(&atr_input, src_port);
5263 ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes);
5264 ixgbe_atr_set_l4type_82599(&atr_input, l4type);
5265 /* src and dst are inverted, think how the receiver sees them */
5266 ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr);
5267 ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr);
5268
5269 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
5270 ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue);
5271}
5272
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005273static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005274 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005275{
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005276 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005277 /* Herbert's original patch had:
5278 * smp_mb__after_netif_stop_queue();
5279 * but since that doesn't exist yet, just open code it. */
5280 smp_mb();
5281
5282 /* We need to check again in a case another CPU has just
5283 * made room available. */
5284 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
5285 return -EBUSY;
5286
5287 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07005288 netif_start_subqueue(netdev, tx_ring->queue_index);
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005289 ++tx_ring->restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005290 return 0;
5291}
5292
5293static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005294 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005295{
5296 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
5297 return 0;
5298 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
5299}
5300
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005301static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
5302{
5303 struct ixgbe_adapter *adapter = netdev_priv(dev);
Yi Zou5f715822009-12-03 11:32:44 +00005304 int txq = smp_processor_id();
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005305
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005306 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Yi Zou5f715822009-12-03 11:32:44 +00005307 return txq;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005308
Yi Zou5f715822009-12-03 11:32:44 +00005309#ifdef IXGBE_FCOE
5310 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
5311 (skb->protocol == htons(ETH_P_FCOE))) {
5312 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
5313 txq += adapter->ring_feature[RING_F_FCOE].mask;
5314 return txq;
5315 }
5316#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005317 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
Lucy Liu36e89d72009-08-05 13:06:34 -07005318 return (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) >> 13;
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005319
5320 return skb_tx_hash(dev, skb);
5321}
5322
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005323static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
5324 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07005325{
5326 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5327 struct ixgbe_ring *tx_ring;
Eric Dumazet60d51132009-12-08 07:22:03 +00005328 struct netdev_queue *txq;
Auke Kok9a799d72007-09-15 14:07:45 -07005329 unsigned int first;
5330 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005331 u8 hdr_len = 0;
Yi Zou5f715822009-12-03 11:32:44 +00005332 int tso;
Auke Kok9a799d72007-09-15 14:07:45 -07005333 int count = 0;
5334 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005335
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005336 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
5337 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005338 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5339 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
Yi Zou5f715822009-12-03 11:32:44 +00005340 tx_flags |= ((skb->queue_mapping & 0x7) << 13);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005341 }
5342 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5343 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5344 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Lucy Liu60127862009-07-22 14:07:33 +00005345 if (skb->priority != TC_PRIO_CONTROL) {
Yi Zou5f715822009-12-03 11:32:44 +00005346 tx_flags |= ((skb->queue_mapping & 0x7) << 13);
Lucy Liu60127862009-07-22 14:07:33 +00005347 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5348 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5349 } else {
5350 skb->queue_mapping =
5351 adapter->ring_feature[RING_F_DCB].indices-1;
5352 }
Auke Kok9a799d72007-09-15 14:07:45 -07005353 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005354
Yi Zou5f715822009-12-03 11:32:44 +00005355 tx_ring = &adapter->tx_ring[skb->queue_mapping];
Lucy Liu60127862009-07-22 14:07:33 +00005356
Yi Zoueacd73f2009-05-13 13:11:06 +00005357 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
Yi Zou09ad1cc2009-09-03 14:56:10 +00005358 (skb->protocol == htons(ETH_P_FCOE))) {
Yi Zoueacd73f2009-05-13 13:11:06 +00005359 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Yi Zou09ad1cc2009-09-03 14:56:10 +00005360#ifdef IXGBE_FCOE
Yi Zou61a0f422009-12-03 11:32:22 +00005361#ifdef CONFIG_IXGBE_DCB
5362 tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK
5363 << IXGBE_TX_FLAGS_VLAN_SHIFT);
5364 tx_flags |= ((adapter->fcoe.up << 13)
5365 << IXGBE_TX_FLAGS_VLAN_SHIFT);
5366#endif
Yi Zou09ad1cc2009-09-03 14:56:10 +00005367#endif
5368 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005369 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005370 if (skb_is_gso(skb) ||
5371 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00005372 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
5373 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07005374 count++;
5375
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005376 count += TXD_USE_COUNT(skb_headlen(skb));
5377 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07005378 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
5379
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005380 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07005381 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07005382 return NETDEV_TX_BUSY;
5383 }
Auke Kok9a799d72007-09-15 14:07:45 -07005384
Auke Kok9a799d72007-09-15 14:07:45 -07005385 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00005386 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5387#ifdef IXGBE_FCOE
5388 /* setup tx offload for FCoE */
5389 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5390 if (tso < 0) {
5391 dev_kfree_skb_any(skb);
5392 return NETDEV_TX_OK;
5393 }
5394 if (tso)
5395 tx_flags |= IXGBE_TX_FLAGS_FSO;
5396#endif /* IXGBE_FCOE */
5397 } else {
5398 if (skb->protocol == htons(ETH_P_IP))
5399 tx_flags |= IXGBE_TX_FLAGS_IPV4;
5400 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5401 if (tso < 0) {
5402 dev_kfree_skb_any(skb);
5403 return NETDEV_TX_OK;
5404 }
5405
5406 if (tso)
5407 tx_flags |= IXGBE_TX_FLAGS_TSO;
5408 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
5409 (skb->ip_summed == CHECKSUM_PARTIAL))
5410 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005411 }
5412
Yi Zoueacd73f2009-05-13 13:11:06 +00005413 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005414 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005415 /* add the ATR filter if ATR is on */
5416 if (tx_ring->atr_sample_rate) {
5417 ++tx_ring->atr_count;
5418 if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) &&
5419 test_bit(__IXGBE_FDIR_INIT_DONE,
5420 &tx_ring->reinit_state)) {
5421 ixgbe_atr(adapter, skb, tx_ring->queue_index,
5422 tx_flags);
5423 tx_ring->atr_count = 0;
5424 }
5425 }
Eric Dumazet60d51132009-12-08 07:22:03 +00005426 txq = netdev_get_tx_queue(netdev, tx_ring->queue_index);
5427 txq->tx_bytes += skb->len;
5428 txq->tx_packets++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00005429 ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
5430 hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005431 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07005432
Alexander Duyck44df32c2009-03-31 21:34:23 +00005433 } else {
5434 dev_kfree_skb_any(skb);
5435 tx_ring->tx_buffer_info[first].time_stamp = 0;
5436 tx_ring->next_to_use = first;
5437 }
Auke Kok9a799d72007-09-15 14:07:45 -07005438
5439 return NETDEV_TX_OK;
5440}
5441
5442/**
Auke Kok9a799d72007-09-15 14:07:45 -07005443 * ixgbe_set_mac - Change the Ethernet Address of the NIC
5444 * @netdev: network interface device structure
5445 * @p: pointer to an address structure
5446 *
5447 * Returns 0 on success, negative on failure
5448 **/
5449static int ixgbe_set_mac(struct net_device *netdev, void *p)
5450{
5451 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005452 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005453 struct sockaddr *addr = p;
5454
5455 if (!is_valid_ether_addr(addr->sa_data))
5456 return -EADDRNOTAVAIL;
5457
5458 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005459 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07005460
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005461 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07005462
5463 return 0;
5464}
5465
Ben Hutchings6b73e102009-04-29 08:08:58 +00005466static int
5467ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
5468{
5469 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5470 struct ixgbe_hw *hw = &adapter->hw;
5471 u16 value;
5472 int rc;
5473
5474 if (prtad != hw->phy.mdio.prtad)
5475 return -EINVAL;
5476 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
5477 if (!rc)
5478 rc = value;
5479 return rc;
5480}
5481
5482static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
5483 u16 addr, u16 value)
5484{
5485 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5486 struct ixgbe_hw *hw = &adapter->hw;
5487
5488 if (prtad != hw->phy.mdio.prtad)
5489 return -EINVAL;
5490 return hw->phy.ops.write_reg(hw, addr, devad, value);
5491}
5492
5493static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
5494{
5495 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5496
5497 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
5498}
5499
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005500/**
5501 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00005502 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005503 * @netdev: network interface device structure
5504 *
5505 * Returns non-zero on failure
5506 **/
5507static int ixgbe_add_sanmac_netdev(struct net_device *dev)
5508{
5509 int err = 0;
5510 struct ixgbe_adapter *adapter = netdev_priv(dev);
5511 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5512
5513 if (is_valid_ether_addr(mac->san_addr)) {
5514 rtnl_lock();
5515 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5516 rtnl_unlock();
5517 }
5518 return err;
5519}
5520
5521/**
5522 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00005523 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005524 * @netdev: network interface device structure
5525 *
5526 * Returns non-zero on failure
5527 **/
5528static int ixgbe_del_sanmac_netdev(struct net_device *dev)
5529{
5530 int err = 0;
5531 struct ixgbe_adapter *adapter = netdev_priv(dev);
5532 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5533
5534 if (is_valid_ether_addr(mac->san_addr)) {
5535 rtnl_lock();
5536 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5537 rtnl_unlock();
5538 }
5539 return err;
5540}
5541
Auke Kok9a799d72007-09-15 14:07:45 -07005542#ifdef CONFIG_NET_POLL_CONTROLLER
5543/*
5544 * Polling 'interrupt' - used by things like netconsole to send skbs
5545 * without having to re-enable interrupts. It's not called while
5546 * the interrupt routine is executing.
5547 */
5548static void ixgbe_netpoll(struct net_device *netdev)
5549{
5550 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00005551 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005552
Auke Kok9a799d72007-09-15 14:07:45 -07005553 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00005554 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5555 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
5556 for (i = 0; i < num_q_vectors; i++) {
5557 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
5558 ixgbe_msix_clean_many(0, q_vector);
5559 }
5560 } else {
5561 ixgbe_intr(adapter->pdev->irq, netdev);
5562 }
Auke Kok9a799d72007-09-15 14:07:45 -07005563 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07005564}
5565#endif
5566
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005567static const struct net_device_ops ixgbe_netdev_ops = {
5568 .ndo_open = ixgbe_open,
5569 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005570 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005571 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00005572 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005573 .ndo_set_multicast_list = ixgbe_set_rx_mode,
5574 .ndo_validate_addr = eth_validate_addr,
5575 .ndo_set_mac_address = ixgbe_set_mac,
5576 .ndo_change_mtu = ixgbe_change_mtu,
5577 .ndo_tx_timeout = ixgbe_tx_timeout,
5578 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
5579 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
5580 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00005581 .ndo_do_ioctl = ixgbe_ioctl,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005582#ifdef CONFIG_NET_POLL_CONTROLLER
5583 .ndo_poll_controller = ixgbe_netpoll,
5584#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005585#ifdef IXGBE_FCOE
5586 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
5587 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00005588 .ndo_fcoe_enable = ixgbe_fcoe_enable,
5589 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00005590 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00005591#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005592};
5593
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005594/**
Auke Kok9a799d72007-09-15 14:07:45 -07005595 * ixgbe_probe - Device Initialization Routine
5596 * @pdev: PCI device information struct
5597 * @ent: entry in ixgbe_pci_tbl
5598 *
5599 * Returns 0 on success, negative on failure
5600 *
5601 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
5602 * The OS initialization, configuring of the adapter private structure,
5603 * and a hardware reset occur.
5604 **/
5605static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005606 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07005607{
5608 struct net_device *netdev;
5609 struct ixgbe_adapter *adapter = NULL;
5610 struct ixgbe_hw *hw;
5611 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07005612 static int cards_found;
5613 int i, err, pci_using_dac;
Yi Zoueacd73f2009-05-13 13:11:06 +00005614#ifdef IXGBE_FCOE
5615 u16 device_caps;
5616#endif
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005617 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07005618
gouji-new9ce77662009-05-06 10:44:45 +00005619 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005620 if (err)
5621 return err;
5622
Yang Hongyang6a355282009-04-06 19:01:13 -07005623 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
5624 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07005625 pci_using_dac = 1;
5626 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07005627 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005628 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -07005629 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005630 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005631 dev_err(&pdev->dev, "No usable DMA "
5632 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005633 goto err_dma;
5634 }
5635 }
5636 pci_using_dac = 0;
5637 }
5638
gouji-new9ce77662009-05-06 10:44:45 +00005639 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
5640 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07005641 if (err) {
gouji-new9ce77662009-05-06 10:44:45 +00005642 dev_err(&pdev->dev,
5643 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07005644 goto err_pci_reg;
5645 }
5646
Frans Pop19d5afd2009-10-02 10:04:12 -07005647 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005648
Auke Kok9a799d72007-09-15 14:07:45 -07005649 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07005650 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005651
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005652 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07005653 if (!netdev) {
5654 err = -ENOMEM;
5655 goto err_alloc_etherdev;
5656 }
5657
Auke Kok9a799d72007-09-15 14:07:45 -07005658 SET_NETDEV_DEV(netdev, &pdev->dev);
5659
5660 pci_set_drvdata(pdev, netdev);
5661 adapter = netdev_priv(netdev);
5662
5663 adapter->netdev = netdev;
5664 adapter->pdev = pdev;
5665 hw = &adapter->hw;
5666 hw->back = adapter;
5667 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
5668
Jeff Kirsher05857982008-09-11 19:57:00 -07005669 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
5670 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07005671 if (!hw->hw_addr) {
5672 err = -EIO;
5673 goto err_ioremap;
5674 }
5675
5676 for (i = 1; i <= 5; i++) {
5677 if (pci_resource_len(pdev, i) == 0)
5678 continue;
5679 }
5680
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005681 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07005682 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005683 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07005684 strcpy(netdev->name, pci_name(pdev));
5685
Auke Kok9a799d72007-09-15 14:07:45 -07005686 adapter->bd_number = cards_found;
5687
Auke Kok9a799d72007-09-15 14:07:45 -07005688 /* Setup hw api */
5689 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005690 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07005691
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005692 /* EEPROM */
5693 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
5694 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
5695 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
5696 if (!(eec & (1 << 8)))
5697 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
5698
5699 /* PHY */
5700 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08005701 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00005702 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
5703 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
5704 hw->phy.mdio.mmds = 0;
5705 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
5706 hw->phy.mdio.dev = netdev;
5707 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
5708 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08005709
5710 /* set up this timer and work struct before calling get_invariants
5711 * which might start the timer
5712 */
5713 init_timer(&adapter->sfp_timer);
5714 adapter->sfp_timer.function = &ixgbe_sfp_timer;
5715 adapter->sfp_timer.data = (unsigned long) adapter;
5716
5717 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005718
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005719 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
5720 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
5721
5722 /* a new SFP+ module arrival, called from GPI SDP2 context */
5723 INIT_WORK(&adapter->sfp_config_module_task,
5724 ixgbe_sfp_config_module_task);
5725
Don Skidmore8ca783a2009-05-26 20:40:47 -07005726 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005727
5728 /* setup the private structure */
5729 err = ixgbe_sw_init(adapter);
5730 if (err)
5731 goto err_sw_init;
5732
Don Skidmorebf069c92009-05-07 10:39:54 +00005733 /*
5734 * If there is a fan on this device and it has failed log the
5735 * failure.
5736 */
5737 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5738 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5739 if (esdp & IXGBE_ESDP_SDP1)
5740 DPRINTK(PROBE, CRIT,
5741 "Fan has stopped, replace the adapter\n");
5742 }
5743
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005744 /* reset_hw fills in the perm_addr as well */
5745 err = hw->mac.ops.reset_hw(hw);
Don Skidmore8ca783a2009-05-26 20:40:47 -07005746 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
5747 hw->mac.type == ixgbe_mac_82598EB) {
5748 /*
5749 * Start a kernel thread to watch for a module to arrive.
5750 * Only do this for 82598, since 82599 will generate
5751 * interrupts on module arrival.
5752 */
5753 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5754 mod_timer(&adapter->sfp_timer,
5755 round_jiffies(jiffies + (2 * HZ)));
5756 err = 0;
5757 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00005758 dev_err(&adapter->pdev->dev, "failed to initialize because "
5759 "an unsupported SFP+ module type was detected.\n"
5760 "Reload the driver after installing a supported "
5761 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005762 goto err_sw_init;
5763 } else if (err) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005764 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
5765 goto err_sw_init;
5766 }
5767
Auke Kok9a799d72007-09-15 14:07:45 -07005768 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005769 NETIF_F_IP_CSUM |
5770 NETIF_F_HW_VLAN_TX |
5771 NETIF_F_HW_VLAN_RX |
5772 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07005773
Jesse Brandeburge9990a92008-08-26 04:27:24 -07005774 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005775 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07005776 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08005777 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005778
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00005779 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
5780 netdev->features |= NETIF_F_SCTP_CSUM;
5781
Jeff Kirsherad31c402008-06-05 04:05:30 -07005782 netdev->vlan_features |= NETIF_F_TSO;
5783 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07005784 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00005785 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005786 netdev->vlan_features |= NETIF_F_SG;
5787
Alexander Duyck2f90b862008-11-20 20:52:10 -08005788 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5789 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
5790
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005791#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005792 netdev->dcbnl_ops = &dcbnl_ops;
5793#endif
5794
Yi Zoueacd73f2009-05-13 13:11:06 +00005795#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005796 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00005797 if (hw->mac.ops.get_device_caps) {
5798 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00005799 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
5800 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00005801 }
5802 }
5803#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005804 if (pci_using_dac)
5805 netdev->features |= NETIF_F_HIGHDMA;
5806
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005807 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00005808 netdev->features |= NETIF_F_LRO;
5809
Auke Kok9a799d72007-09-15 14:07:45 -07005810 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005811 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07005812 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
5813 err = -EIO;
5814 goto err_eeprom;
5815 }
5816
5817 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
5818 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
5819
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005820 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
5821 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005822 err = -EIO;
5823 goto err_eeprom;
5824 }
5825
5826 init_timer(&adapter->watchdog_timer);
5827 adapter->watchdog_timer.function = &ixgbe_watchdog;
5828 adapter->watchdog_timer.data = (unsigned long)adapter;
5829
5830 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005831 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005832
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005833 err = ixgbe_init_interrupt_scheme(adapter);
5834 if (err)
5835 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07005836
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005837 switch (pdev->device) {
5838 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005839 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
5840 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
Peter P Waskiewicz Jrbdf0a552009-06-04 11:09:58 +00005841 /* Enable ACPI wakeup in GRC */
5842 IXGBE_WRITE_REG(hw, IXGBE_GRC,
5843 (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005844 break;
5845 default:
5846 adapter->wol = 0;
5847 break;
5848 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005849 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
5850
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005851 /* pick up the PCI bus settings for reporting later */
5852 hw->mac.ops.get_bus_info(hw);
5853
Auke Kok9a799d72007-09-15 14:07:45 -07005854 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07005855 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005856 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
5857 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
5858 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
5859 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
5860 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005861 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07005862 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005863 ixgbe_read_pba_num_generic(hw, &part_num);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005864 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
5865 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
5866 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
5867 (part_num >> 8), (part_num & 0xff));
5868 else
5869 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
5870 hw->mac.type, hw->phy.type,
5871 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07005872
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005873 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Auke Kok0c254d82008-02-11 09:25:56 -08005874 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005875 "this card is not sufficient for optimal "
5876 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005877 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005878 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005879 }
5880
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08005881 /* save off EEPROM version number */
5882 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
5883
Auke Kok9a799d72007-09-15 14:07:45 -07005884 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005885 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005886
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005887 if (err == IXGBE_ERR_EEPROM_VERSION) {
5888 /* We are running on a pre-production device, log a warning */
5889 dev_warn(&pdev->dev, "This device is a pre-production "
5890 "adapter/LOM. Please be aware there may be issues "
5891 "associated with your hardware. If you are "
5892 "experiencing problems please contact your Intel or "
5893 "hardware representative who provided you with this "
5894 "hardware.\n");
5895 }
Auke Kok9a799d72007-09-15 14:07:45 -07005896 strcpy(netdev->name, "eth%d");
5897 err = register_netdev(netdev);
5898 if (err)
5899 goto err_register;
5900
Jesse Brandeburg54386462009-04-17 20:44:27 +00005901 /* carrier off reporting is important to ethtool even BEFORE open */
5902 netif_carrier_off(netdev);
5903
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005904 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5905 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5906 INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
5907
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005908#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03005909 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005910 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005911 ixgbe_setup_dca(adapter);
5912 }
5913#endif
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005914 /* add san mac addr to netdev */
5915 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005916
5917 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
5918 cards_found++;
5919 return 0;
5920
5921err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005922 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005923 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005924err_sw_init:
5925err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08005926 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5927 del_timer_sync(&adapter->sfp_timer);
5928 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005929 cancel_work_sync(&adapter->multispeed_fiber_task);
5930 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005931 iounmap(hw->hw_addr);
5932err_ioremap:
5933 free_netdev(netdev);
5934err_alloc_etherdev:
gouji-new9ce77662009-05-06 10:44:45 +00005935 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5936 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005937err_pci_reg:
5938err_dma:
5939 pci_disable_device(pdev);
5940 return err;
5941}
5942
5943/**
5944 * ixgbe_remove - Device Removal Routine
5945 * @pdev: PCI device information struct
5946 *
5947 * ixgbe_remove is called by the PCI subsystem to alert the driver
5948 * that it should release a PCI device. The could be caused by a
5949 * Hot-Plug event, or because the driver is going to be removed from
5950 * memory.
5951 **/
5952static void __devexit ixgbe_remove(struct pci_dev *pdev)
5953{
5954 struct net_device *netdev = pci_get_drvdata(pdev);
5955 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5956
5957 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08005958 /* clear the module not found bit to make sure the worker won't
5959 * reschedule
5960 */
5961 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07005962 del_timer_sync(&adapter->watchdog_timer);
5963
Donald Skidmorec4900be2008-11-20 21:11:42 -08005964 del_timer_sync(&adapter->sfp_timer);
5965 cancel_work_sync(&adapter->watchdog_task);
5966 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005967 cancel_work_sync(&adapter->multispeed_fiber_task);
5968 cancel_work_sync(&adapter->sfp_config_module_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005969 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5970 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5971 cancel_work_sync(&adapter->fdir_reinit_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005972 flush_scheduled_work();
5973
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005974#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005975 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
5976 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
5977 dca_remove_requester(&pdev->dev);
5978 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
5979 }
5980
5981#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005982#ifdef IXGBE_FCOE
5983 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
5984 ixgbe_cleanup_fcoe(adapter);
5985
5986#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005987
5988 /* remove the added san mac */
5989 ixgbe_del_sanmac_netdev(netdev);
5990
Donald Skidmorec4900be2008-11-20 21:11:42 -08005991 if (netdev->reg_state == NETREG_REGISTERED)
5992 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005993
Alexander Duyck7a921c92009-05-06 10:43:28 +00005994 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005995
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005996 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005997
5998 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00005999 pci_release_selected_regions(pdev, pci_select_bars(pdev,
6000 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07006001
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006002 DPRINTK(PROBE, INFO, "complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006003
Auke Kok9a799d72007-09-15 14:07:45 -07006004 free_netdev(netdev);
6005
Frans Pop19d5afd2009-10-02 10:04:12 -07006006 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006007
Auke Kok9a799d72007-09-15 14:07:45 -07006008 pci_disable_device(pdev);
6009}
6010
6011/**
6012 * ixgbe_io_error_detected - called when PCI error is detected
6013 * @pdev: Pointer to PCI device
6014 * @state: The current pci connection state
6015 *
6016 * This function is called after a PCI bus error affecting
6017 * this device has been detected.
6018 */
6019static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006020 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07006021{
6022 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08006023 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006024
6025 netif_device_detach(netdev);
6026
Breno Leitao3044b8d2009-05-06 10:44:26 +00006027 if (state == pci_channel_io_perm_failure)
6028 return PCI_ERS_RESULT_DISCONNECT;
6029
Auke Kok9a799d72007-09-15 14:07:45 -07006030 if (netif_running(netdev))
6031 ixgbe_down(adapter);
6032 pci_disable_device(pdev);
6033
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006034 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07006035 return PCI_ERS_RESULT_NEED_RESET;
6036}
6037
6038/**
6039 * ixgbe_io_slot_reset - called after the pci bus has been reset.
6040 * @pdev: Pointer to PCI device
6041 *
6042 * Restart the card from scratch, as if from a cold-boot.
6043 */
6044static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
6045{
6046 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08006047 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006048 pci_ers_result_t result;
6049 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07006050
gouji-new9ce77662009-05-06 10:44:45 +00006051 if (pci_enable_device_mem(pdev)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006052 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006053 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006054 result = PCI_ERS_RESULT_DISCONNECT;
6055 } else {
6056 pci_set_master(pdev);
6057 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00006058 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006059
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006060 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006061
6062 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00006063 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006064 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07006065 }
Auke Kok9a799d72007-09-15 14:07:45 -07006066
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006067 err = pci_cleanup_aer_uncorrect_error_status(pdev);
6068 if (err) {
6069 dev_err(&pdev->dev,
6070 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
6071 /* non-fatal, continue */
6072 }
Auke Kok9a799d72007-09-15 14:07:45 -07006073
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006074 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07006075}
6076
6077/**
6078 * ixgbe_io_resume - called when traffic can start flowing again.
6079 * @pdev: Pointer to PCI device
6080 *
6081 * This callback is called when the error recovery driver tells us that
6082 * its OK to resume normal operation.
6083 */
6084static void ixgbe_io_resume(struct pci_dev *pdev)
6085{
6086 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08006087 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006088
6089 if (netif_running(netdev)) {
6090 if (ixgbe_up(adapter)) {
6091 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
6092 return;
6093 }
6094 }
6095
6096 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006097}
6098
6099static struct pci_error_handlers ixgbe_err_handler = {
6100 .error_detected = ixgbe_io_error_detected,
6101 .slot_reset = ixgbe_io_slot_reset,
6102 .resume = ixgbe_io_resume,
6103};
6104
6105static struct pci_driver ixgbe_driver = {
6106 .name = ixgbe_driver_name,
6107 .id_table = ixgbe_pci_tbl,
6108 .probe = ixgbe_probe,
6109 .remove = __devexit_p(ixgbe_remove),
6110#ifdef CONFIG_PM
6111 .suspend = ixgbe_suspend,
6112 .resume = ixgbe_resume,
6113#endif
6114 .shutdown = ixgbe_shutdown,
6115 .err_handler = &ixgbe_err_handler
6116};
6117
6118/**
6119 * ixgbe_init_module - Driver Registration Routine
6120 *
6121 * ixgbe_init_module is the first routine called when the driver is
6122 * loaded. All it does is register with the PCI subsystem.
6123 **/
6124static int __init ixgbe_init_module(void)
6125{
6126 int ret;
6127 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
6128 ixgbe_driver_string, ixgbe_driver_version);
6129
6130 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
6131
Jeff Garzik5dd2d332008-10-16 05:09:31 -04006132#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006133 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006134#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04006135
Auke Kok9a799d72007-09-15 14:07:45 -07006136 ret = pci_register_driver(&ixgbe_driver);
6137 return ret;
6138}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006139
Auke Kok9a799d72007-09-15 14:07:45 -07006140module_init(ixgbe_init_module);
6141
6142/**
6143 * ixgbe_exit_module - Driver Exit Cleanup Routine
6144 *
6145 * ixgbe_exit_module is called just before the driver is removed
6146 * from memory.
6147 **/
6148static void __exit ixgbe_exit_module(void)
6149{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04006150#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006151 dca_unregister_notify(&dca_notifier);
6152#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006153 pci_unregister_driver(&ixgbe_driver);
6154}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006155
Jeff Garzik5dd2d332008-10-16 05:09:31 -04006156#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006157static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006158 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006159{
6160 int ret_val;
6161
6162 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006163 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006164
6165 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
6166}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006167
Alexander Duyckb4533682009-03-31 21:32:42 +00006168#endif /* CONFIG_IXGBE_DCA */
6169#ifdef DEBUG
6170/**
6171 * ixgbe_get_hw_dev_name - return device name string
6172 * used by hardware layer to print debugging information
6173 **/
6174char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
6175{
6176 struct ixgbe_adapter *adapter = hw->back;
6177 return adapter->netdev->name;
6178}
6179
6180#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006181module_exit(ixgbe_exit_module);
6182
6183/* ixgbe_main.c */