blob: db05030a30ec5c01a7a342b9151884903d67ef91 [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 Rajput30b76832009-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;
Ajit Khaparde2d86f132009-10-07 02:43:49 +0000438 netdev->stats.tx_bytes += total_bytes;
439 netdev->stats.tx_packets += total_packets;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000440 return (count < tx_ring->work_limit);
Auke Kok9a799d72007-09-15 14:07:45 -0700441}
442
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400443#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800444static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700445 struct ixgbe_ring *rx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800446{
447 u32 rxctrl;
448 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700449 int q = rx_ring - adapter->rx_ring;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800450
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700451 if (rx_ring->cpu != cpu) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800452 rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000453 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
454 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
455 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
456 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
457 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
458 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
459 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
460 }
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800461 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
462 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
Don Skidmore15005a32009-01-19 16:54:13 -0800463 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
464 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000465 IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800466 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700467 rx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800468 }
469 put_cpu();
470}
471
472static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700473 struct ixgbe_ring *tx_ring)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800474{
475 u32 txctrl;
476 int cpu = get_cpu();
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700477 int q = tx_ring - adapter->tx_ring;
Don Skidmoreee5f7842009-11-06 12:56:20 +0000478 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800479
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700480 if (tx_ring->cpu != cpu) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000481 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Don Skidmoreee5f7842009-11-06 12:56:20 +0000482 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000483 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
484 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
Don Skidmoreee5f7842009-11-06 12:56:20 +0000485 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
486 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000487 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Don Skidmoreee5f7842009-11-06 12:56:20 +0000488 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q));
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000489 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
490 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
Don Skidmoreee5f7842009-11-06 12:56:20 +0000491 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
492 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
493 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000494 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700495 tx_ring->cpu = cpu;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800496 }
497 put_cpu();
498}
499
500static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
501{
502 int i;
503
504 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
505 return;
506
Alexander Duycke35ec122009-05-21 13:07:12 +0000507 /* always use CB2 mode, difference is masked in the CB driver */
508 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
509
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800510 for (i = 0; i < adapter->num_tx_queues; i++) {
511 adapter->tx_ring[i].cpu = -1;
512 ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]);
513 }
514 for (i = 0; i < adapter->num_rx_queues; i++) {
515 adapter->rx_ring[i].cpu = -1;
516 ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]);
517 }
518}
519
520static int __ixgbe_notify_dca(struct device *dev, void *data)
521{
522 struct net_device *netdev = dev_get_drvdata(dev);
523 struct ixgbe_adapter *adapter = netdev_priv(netdev);
524 unsigned long event = *(unsigned long *)data;
525
526 switch (event) {
527 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700528 /* if we're already enabled, don't do it again */
529 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
530 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300531 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700532 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800533 ixgbe_setup_dca(adapter);
534 break;
535 }
536 /* Fall Through since DCA is disabled. */
537 case DCA_PROVIDER_REMOVE:
538 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
539 dca_remove_requester(dev);
540 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
541 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
542 }
543 break;
544 }
545
Denis V. Lunev652f0932008-03-27 14:39:17 +0300546 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800547}
548
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400549#endif /* CONFIG_IXGBE_DCA */
Auke Kok9a799d72007-09-15 14:07:45 -0700550/**
551 * ixgbe_receive_skb - Send a completed packet up the stack
552 * @adapter: board private structure
553 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700554 * @status: hardware indication of status of receive
555 * @rx_ring: rx descriptor ring (for a specific queue) to setup
556 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -0700557 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800558static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700559 struct sk_buff *skb, u8 status,
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000560 struct ixgbe_ring *ring,
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700561 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -0700562{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800563 struct ixgbe_adapter *adapter = q_vector->adapter;
564 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700565 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
566 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -0700567
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000568 skb_record_rx_queue(skb, ring->queue_index);
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000569 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) {
Lucy Liu8a62bab2009-08-13 14:09:38 +0000570 if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800571 vlan_gro_receive(napi, adapter->vlgrp, tag, skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700572 else
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800573 napi_gro_receive(napi, skb);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700574 } else {
Lucy Liu8a62bab2009-08-13 14:09:38 +0000575 if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK))
Alexander Duyck182ff8d2009-04-27 22:35:33 +0000576 vlan_hwaccel_rx(skb, adapter->vlgrp, tag);
577 else
578 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -0700579 }
580}
581
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800582/**
583 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
584 * @adapter: address of board private structure
585 * @status_err: hardware indication of status of receive
586 * @skb: skb currently being received and modified
587 **/
Auke Kok9a799d72007-09-15 14:07:45 -0700588static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +0000589 union ixgbe_adv_rx_desc *rx_desc,
590 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700591{
Don Skidmore8bae1b22009-07-23 18:00:39 +0000592 u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
593
Auke Kok9a799d72007-09-15 14:07:45 -0700594 skb->ip_summed = CHECKSUM_NONE;
595
Jesse Brandeburg712744b2008-08-26 04:26:56 -0700596 /* Rx csum disabled */
597 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -0700598 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800599
600 /* if IP and error */
601 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
602 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -0700603 adapter->hw_csum_rx_error++;
604 return;
605 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800606
607 if (!(status_err & IXGBE_RXD_STAT_L4CS))
608 return;
609
610 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +0000611 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
612
613 /*
614 * 82599 errata, UDP frames with a 0 checksum can be marked as
615 * checksum errors.
616 */
617 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
618 (adapter->hw.mac.type == ixgbe_mac_82599EB))
619 return;
620
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800621 adapter->hw_csum_rx_error++;
622 return;
623 }
624
Auke Kok9a799d72007-09-15 14:07:45 -0700625 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -0800626 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -0700627}
628
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000629static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
630 struct ixgbe_ring *rx_ring, u32 val)
631{
632 /*
633 * Force memory writes to complete before letting h/w
634 * know there are new descriptors to fetch. (Only
635 * applicable for weak-ordered memory model archs,
636 * such as IA-64).
637 */
638 wmb();
639 IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
640}
641
Auke Kok9a799d72007-09-15 14:07:45 -0700642/**
643 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
644 * @adapter: address of board private structure
645 **/
646static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700647 struct ixgbe_ring *rx_ring,
648 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700649{
Auke Kok9a799d72007-09-15 14:07:45 -0700650 struct pci_dev *pdev = adapter->pdev;
651 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700652 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700653 unsigned int i;
Auke Kok9a799d72007-09-15 14:07:45 -0700654
655 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700656 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700657
658 while (cleaned_count--) {
659 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
660
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700661 if (!bi->page_dma &&
Yi Zou6e455b892009-08-06 13:05:44 +0000662 (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700663 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700664 bi->page = alloc_page(GFP_ATOMIC);
665 if (!bi->page) {
666 adapter->alloc_rx_page_failed++;
667 goto no_buffers;
668 }
669 bi->page_offset = 0;
670 } else {
671 /* use a half page if we're re-using */
672 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700673 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700674
675 bi->page_dma = pci_map_page(pdev, bi->page,
676 bi->page_offset,
677 (PAGE_SIZE / 2),
678 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700679 }
680
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700681 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800682 struct sk_buff *skb;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +0000683 /* netdev_alloc_skb reserves 32 bytes up front!! */
684 uint bufsz = rx_ring->rx_buf_len + SMP_CACHE_BYTES;
685 skb = netdev_alloc_skb(adapter->netdev, bufsz);
Auke Kok9a799d72007-09-15 14:07:45 -0700686
687 if (!skb) {
688 adapter->alloc_rx_buff_failed++;
689 goto no_buffers;
690 }
691
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +0000692 /* advance the data pointer to the next cache line */
693 skb_reserve(skb, (PTR_ALIGN(skb->data, SMP_CACHE_BYTES)
694 - skb->data));
695
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700696 bi->skb = skb;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000697 bi->dma = pci_map_single(pdev, skb->data,
698 rx_ring->rx_buf_len,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700699 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700700 }
701 /* Refresh the desc even if buffer_addrs didn't change because
702 * each write-back erases this info. */
Yi Zou6e455b892009-08-06 13:05:44 +0000703 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700704 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
705 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700706 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700707 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700708 }
709
710 i++;
711 if (i == rx_ring->count)
712 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700713 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700714 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700715
Auke Kok9a799d72007-09-15 14:07:45 -0700716no_buffers:
717 if (rx_ring->next_to_use != i) {
718 rx_ring->next_to_use = i;
719 if (i-- == 0)
720 i = (rx_ring->count - 1);
721
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000722 ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700723 }
724}
725
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700726static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
727{
728 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
729}
730
731static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
732{
733 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
734}
735
Alexander Duyckf8212f92009-04-27 22:42:37 +0000736static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
737{
738 return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
739 IXGBE_RXDADV_RSCCNT_MASK) >>
740 IXGBE_RXDADV_RSCCNT_SHIFT;
741}
742
743/**
744 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
745 * @skb: pointer to the last skb in the rsc queue
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +0000746 * @count: pointer to number of packets coalesced in this context
Alexander Duyckf8212f92009-04-27 22:42:37 +0000747 *
748 * This function changes a queue full of hw rsc buffers into a completed
749 * packet. It uses the ->prev pointers to find the first packet and then
750 * turns it into the frag list owner.
751 **/
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +0000752static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb,
753 u64 *count)
Alexander Duyckf8212f92009-04-27 22:42:37 +0000754{
755 unsigned int frag_list_size = 0;
756
757 while (skb->prev) {
758 struct sk_buff *prev = skb->prev;
759 frag_list_size += skb->len;
760 skb->prev = NULL;
761 skb = prev;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +0000762 *count += 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000763 }
764
765 skb_shinfo(skb)->frag_list = skb->next;
766 skb->next = NULL;
767 skb->len += frag_list_size;
768 skb->data_len += frag_list_size;
769 skb->truesize += frag_list_size;
770 return skb;
771}
772
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800773static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700774 struct ixgbe_ring *rx_ring,
775 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700776{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800777 struct ixgbe_adapter *adapter = q_vector->adapter;
Ajit Khaparde2d86f132009-10-07 02:43:49 +0000778 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -0700779 struct pci_dev *pdev = adapter->pdev;
780 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
781 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
782 struct sk_buff *skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000783 unsigned int i, rsc_count = 0;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700784 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700785 u16 hdr_info;
786 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700787 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800788 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +0000789#ifdef IXGBE_FCOE
790 int ddp_bytes = 0;
791#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -0700792
793 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700794 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
795 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
796 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700797
798 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700799 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700800 if (*work_done >= work_to_do)
801 break;
802 (*work_done)++;
803
Yi Zou6e455b892009-08-06 13:05:44 +0000804 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700805 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
806 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700807 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700808 if (len > IXGBE_RX_HDR_SIZE)
809 len = IXGBE_RX_HDR_SIZE;
810 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700811 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700812 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700813 }
Auke Kok9a799d72007-09-15 14:07:45 -0700814
815 cleaned = true;
816 skb = rx_buffer_info->skb;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +0000817 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -0700818 rx_buffer_info->skb = NULL;
819
Alexander Duyck21fa4e62009-06-04 15:59:49 +0000820 if (rx_buffer_info->dma) {
Auke Kok9a799d72007-09-15 14:07:45 -0700821 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800822 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700823 PCI_DMA_FROMDEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000824 rx_buffer_info->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700825 skb_put(skb, len);
826 }
827
828 if (upper_len) {
829 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700830 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700831 rx_buffer_info->page_dma = 0;
832 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700833 rx_buffer_info->page,
834 rx_buffer_info->page_offset,
835 upper_len);
836
837 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
838 (page_count(rx_buffer_info->page) != 1))
839 rx_buffer_info->page = NULL;
840 else
841 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700842
843 skb->len += upper_len;
844 skb->data_len += upper_len;
845 skb->truesize += upper_len;
846 }
847
848 i++;
849 if (i == rx_ring->count)
850 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700851
852 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
853 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -0700854 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000855
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +0000856 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
Alexander Duyckf8212f92009-04-27 22:42:37 +0000857 rsc_count = ixgbe_get_rsc_count(rx_desc);
858
859 if (rsc_count) {
860 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
861 IXGBE_RXDADV_NEXTP_SHIFT;
862 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +0000863 } else {
864 next_buffer = &rx_ring->rx_buffer_info[i];
865 }
866
Auke Kok9a799d72007-09-15 14:07:45 -0700867 if (staterr & IXGBE_RXD_STAT_EOP) {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000868 if (skb->prev)
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +0000869 skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count));
870 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
871 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)
872 rx_ring->rsc_count += skb_shinfo(skb)->nr_frags;
873 else
874 rx_ring->rsc_count++;
875 rx_ring->rsc_flush++;
876 }
Auke Kok9a799d72007-09-15 14:07:45 -0700877 rx_ring->stats.packets++;
878 rx_ring->stats.bytes += skb->len;
879 } else {
Yi Zou6e455b892009-08-06 13:05:44 +0000880 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000881 rx_buffer_info->skb = next_buffer->skb;
882 rx_buffer_info->dma = next_buffer->dma;
883 next_buffer->skb = skb;
884 next_buffer->dma = 0;
885 } else {
886 skb->next = next_buffer->skb;
887 skb->next->prev = skb;
888 }
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +0000889 rx_ring->non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -0700890 goto next_desc;
891 }
892
893 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
894 dev_kfree_skb_irq(skb);
895 goto next_desc;
896 }
897
Don Skidmore8bae1b22009-07-23 18:00:39 +0000898 ixgbe_rx_checksum(adapter, rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800899
900 /* probably a little skewed due to removing CRC */
901 total_rx_bytes += skb->len;
902 total_rx_packets++;
903
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700904 skb->protocol = eth_type_trans(skb, adapter->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +0000905#ifdef IXGBE_FCOE
906 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +0000907 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
908 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
909 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +0000910 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +0000911 }
Yi Zou332d4a72009-05-13 13:11:53 +0000912#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000913 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700914
915next_desc:
916 rx_desc->wb.upper.status_error = 0;
917
918 /* return some buffers to hardware, one at a time is too slow */
919 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
920 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
921 cleaned_count = 0;
922 }
923
924 /* use prefetched values */
925 rx_desc = next_rxd;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000926 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700927
928 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700929 }
930
Auke Kok9a799d72007-09-15 14:07:45 -0700931 rx_ring->next_to_clean = i;
932 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
933
934 if (cleaned_count)
935 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
936
Yi Zou3d8fd382009-06-08 14:38:44 +0000937#ifdef IXGBE_FCOE
938 /* include DDPed FCoE data */
939 if (ddp_bytes > 0) {
940 unsigned int mss;
941
942 mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) -
943 sizeof(struct fc_frame_header) -
944 sizeof(struct fcoe_crc_eof);
945 if (mss > 512)
946 mss &= ~511;
947 total_rx_bytes += ddp_bytes;
948 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
949 }
950#endif /* IXGBE_FCOE */
951
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800952 rx_ring->total_packets += total_rx_packets;
953 rx_ring->total_bytes += total_rx_bytes;
Ajit Khaparde2d86f132009-10-07 02:43:49 +0000954 netdev->stats.rx_bytes += total_rx_bytes;
955 netdev->stats.rx_packets += total_rx_packets;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800956
Auke Kok9a799d72007-09-15 14:07:45 -0700957 return cleaned;
958}
959
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800960static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700961/**
962 * ixgbe_configure_msix - Configure MSI-X hardware
963 * @adapter: board private structure
964 *
965 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
966 * interrupts.
967 **/
968static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
969{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800970 struct ixgbe_q_vector *q_vector;
971 int i, j, q_vectors, v_idx, r_idx;
972 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700973
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800974 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
975
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000976 /*
977 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800978 * corresponding register.
979 */
980 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +0000981 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800982 /* XXX for_each_bit(...) */
983 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700984 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800985
986 for (i = 0; i < q_vector->rxr_count; i++) {
987 j = adapter->rx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000988 ixgbe_set_ivar(adapter, 0, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800989 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700990 adapter->num_rx_queues,
991 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800992 }
993 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700994 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800995
996 for (i = 0; i < q_vector->txr_count; i++) {
997 j = adapter->tx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000998 ixgbe_set_ivar(adapter, 1, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800999 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001000 adapter->num_tx_queues,
1001 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001002 }
1003
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001004 if (q_vector->txr_count && !q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001005 /* tx only */
1006 q_vector->eitr = adapter->tx_eitr_param;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001007 else if (q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001008 /* rx or mixed */
1009 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001010
Alexander Duyckfe49f042009-06-04 16:00:09 +00001011 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001012 }
1013
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001014 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
1015 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
1016 v_idx);
1017 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
1018 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001019 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001020
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001021 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001022 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001023 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001024 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001025}
1026
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001027enum latency_range {
1028 lowest_latency = 0,
1029 low_latency = 1,
1030 bulk_latency = 2,
1031 latency_invalid = 255
1032};
1033
1034/**
1035 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1036 * @adapter: pointer to adapter
1037 * @eitr: eitr setting (ints per sec) to give last timeslice
1038 * @itr_setting: current throttle rate in ints/second
1039 * @packets: the number of packets during this measurement interval
1040 * @bytes: the number of bytes during this measurement interval
1041 *
1042 * Stores a new ITR value based on packets and byte
1043 * counts during the last interrupt. The advantage of per interrupt
1044 * computation is faster updates and more accurate ITR for the current
1045 * traffic pattern. Constants in this function were computed
1046 * based on theoretical maximum wire speed and thresholds were set based
1047 * on testing data as well as attempting to minimize response time
1048 * while increasing bulk throughput.
1049 * this functionality is controlled by the InterruptThrottleRate module
1050 * parameter (see ixgbe_param.c)
1051 **/
1052static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001053 u32 eitr, u8 itr_setting,
1054 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001055{
1056 unsigned int retval = itr_setting;
1057 u32 timepassed_us;
1058 u64 bytes_perint;
1059
1060 if (packets == 0)
1061 goto update_itr_done;
1062
1063
1064 /* simple throttlerate management
1065 * 0-20MB/s lowest (100000 ints/s)
1066 * 20-100MB/s low (20000 ints/s)
1067 * 100-1249MB/s bulk (8000 ints/s)
1068 */
1069 /* what was last interrupt timeslice? */
1070 timepassed_us = 1000000/eitr;
1071 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1072
1073 switch (itr_setting) {
1074 case lowest_latency:
1075 if (bytes_perint > adapter->eitr_low)
1076 retval = low_latency;
1077 break;
1078 case low_latency:
1079 if (bytes_perint > adapter->eitr_high)
1080 retval = bulk_latency;
1081 else if (bytes_perint <= adapter->eitr_low)
1082 retval = lowest_latency;
1083 break;
1084 case bulk_latency:
1085 if (bytes_perint <= adapter->eitr_high)
1086 retval = low_latency;
1087 break;
1088 }
1089
1090update_itr_done:
1091 return retval;
1092}
1093
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001094/**
1095 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001096 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001097 *
1098 * This function is made to be called by ethtool and by the driver
1099 * when it needs to update EITR registers at runtime. Hardware
1100 * specific quirks/differences are taken care of here.
1101 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001102void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001103{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001104 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001105 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001106 int v_idx = q_vector->v_idx;
1107 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1108
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001109 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1110 /* must write high and low 16 bits to reset counter */
1111 itr_reg |= (itr_reg << 16);
1112 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1113 /*
1114 * set the WDIS bit to not clear the timer bits and cause an
1115 * immediate assertion of the interrupt
1116 */
1117 itr_reg |= IXGBE_EITR_CNT_WDIS;
1118 }
1119 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1120}
1121
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001122static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1123{
1124 struct ixgbe_adapter *adapter = q_vector->adapter;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001125 u32 new_itr;
1126 u8 current_itr, ret_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001127 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001128 struct ixgbe_ring *rx_ring, *tx_ring;
1129
1130 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1131 for (i = 0; i < q_vector->txr_count; i++) {
1132 tx_ring = &(adapter->tx_ring[r_idx]);
1133 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001134 q_vector->tx_itr,
1135 tx_ring->total_packets,
1136 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001137 /* if the result for this queue would decrease interrupt
1138 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001139 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001140 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001141 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001142 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001143 }
1144
1145 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1146 for (i = 0; i < q_vector->rxr_count; i++) {
1147 rx_ring = &(adapter->rx_ring[r_idx]);
1148 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001149 q_vector->rx_itr,
1150 rx_ring->total_packets,
1151 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001152 /* if the result for this queue would decrease interrupt
1153 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001154 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001155 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001156 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001157 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001158 }
1159
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001160 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001161
1162 switch (current_itr) {
1163 /* counts and packets in update_itr are dependent on these numbers */
1164 case lowest_latency:
1165 new_itr = 100000;
1166 break;
1167 case low_latency:
1168 new_itr = 20000; /* aka hwitr = ~200 */
1169 break;
1170 case bulk_latency:
1171 default:
1172 new_itr = 8000;
1173 break;
1174 }
1175
1176 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001177 /* do an exponential smoothing */
1178 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001179
1180 /* save the algorithm value here, not the smoothed one */
1181 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001182
1183 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001184 }
1185
1186 return;
1187}
1188
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001189static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1190{
1191 struct ixgbe_hw *hw = &adapter->hw;
1192
1193 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1194 (eicr & IXGBE_EICR_GPI_SDP1)) {
1195 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
1196 /* write to clear the interrupt */
1197 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1198 }
1199}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001200
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001201static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1202{
1203 struct ixgbe_hw *hw = &adapter->hw;
1204
1205 if (eicr & IXGBE_EICR_GPI_SDP1) {
1206 /* Clear the interrupt */
1207 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1208 schedule_work(&adapter->multispeed_fiber_task);
1209 } else if (eicr & IXGBE_EICR_GPI_SDP2) {
1210 /* Clear the interrupt */
1211 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1212 schedule_work(&adapter->sfp_config_module_task);
1213 } else {
1214 /* Interrupt isn't for us... */
1215 return;
1216 }
1217}
1218
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001219static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1220{
1221 struct ixgbe_hw *hw = &adapter->hw;
1222
1223 adapter->lsc_int++;
1224 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1225 adapter->link_check_timeout = jiffies;
1226 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1227 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001228 IXGBE_WRITE_FLUSH(hw);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001229 schedule_work(&adapter->watchdog_task);
1230 }
1231}
1232
Auke Kok9a799d72007-09-15 14:07:45 -07001233static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1234{
1235 struct net_device *netdev = data;
1236 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1237 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001238 u32 eicr;
1239
1240 /*
1241 * Workaround for Silicon errata. Use clear-by-write instead
1242 * of clear-by-read. Reading with EICS will return the
1243 * interrupt causes without clearing, which later be done
1244 * with the write to EICR.
1245 */
1246 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1247 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001248
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001249 if (eicr & IXGBE_EICR_LSC)
1250 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001251
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001252 if (hw->mac.type == ixgbe_mac_82598EB)
1253 ixgbe_check_fan_failure(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001254
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001255 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001256 ixgbe_check_sfp_event(adapter, eicr);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001257
1258 /* Handle Flow Director Full threshold interrupt */
1259 if (eicr & IXGBE_EICR_FLOW_DIR) {
1260 int i;
1261 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
1262 /* Disable transmits before FDIR Re-initialization */
1263 netif_tx_stop_all_queues(netdev);
1264 for (i = 0; i < adapter->num_tx_queues; i++) {
1265 struct ixgbe_ring *tx_ring =
1266 &adapter->tx_ring[i];
1267 if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE,
1268 &tx_ring->reinit_state))
1269 schedule_work(&adapter->fdir_reinit_task);
1270 }
1271 }
1272 }
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001273 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1274 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -07001275
1276 return IRQ_HANDLED;
1277}
1278
Alexander Duyckfe49f042009-06-04 16:00:09 +00001279static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1280 u64 qmask)
1281{
1282 u32 mask;
1283
1284 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1285 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1286 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1287 } else {
1288 mask = (qmask & 0xFFFFFFFF);
1289 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
1290 mask = (qmask >> 32);
1291 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
1292 }
1293 /* skip the flush */
1294}
1295
1296static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
1297 u64 qmask)
1298{
1299 u32 mask;
1300
1301 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1302 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1303 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
1304 } else {
1305 mask = (qmask & 0xFFFFFFFF);
1306 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
1307 mask = (qmask >> 32);
1308 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
1309 }
1310 /* skip the flush */
1311}
1312
Auke Kok9a799d72007-09-15 14:07:45 -07001313static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1314{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001315 struct ixgbe_q_vector *q_vector = data;
1316 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001317 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001318 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001319
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001320 if (!q_vector->txr_count)
1321 return IRQ_HANDLED;
1322
1323 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1324 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001325 tx_ring = &(adapter->tx_ring[r_idx]);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001326 tx_ring->total_bytes = 0;
1327 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001328 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001329 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001330 }
1331
Alexander Duyck91281fd2009-06-04 16:00:27 +00001332 /* disable interrupts on this vector only */
1333 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1334 napi_schedule(&q_vector->napi);
1335
Auke Kok9a799d72007-09-15 14:07:45 -07001336 return IRQ_HANDLED;
1337}
1338
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001339/**
1340 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1341 * @irq: unused
1342 * @data: pointer to our q_vector struct for this interrupt vector
1343 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001344static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1345{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001346 struct ixgbe_q_vector *q_vector = data;
1347 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001348 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001349 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001350 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001351
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001352 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001353 for (i = 0; i < q_vector->rxr_count; i++) {
1354 rx_ring = &(adapter->rx_ring[r_idx]);
1355 rx_ring->total_bytes = 0;
1356 rx_ring->total_packets = 0;
1357 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1358 r_idx + 1);
1359 }
1360
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001361 if (!q_vector->rxr_count)
1362 return IRQ_HANDLED;
1363
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001364 /* disable interrupts on this vector only */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001365 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
Ben Hutchings288379f2009-01-19 16:43:59 -08001366 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001367
Auke Kok9a799d72007-09-15 14:07:45 -07001368 return IRQ_HANDLED;
1369}
1370
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001371static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1372{
Alexander Duyck91281fd2009-06-04 16:00:27 +00001373 struct ixgbe_q_vector *q_vector = data;
1374 struct ixgbe_adapter *adapter = q_vector->adapter;
1375 struct ixgbe_ring *ring;
1376 int r_idx;
1377 int i;
1378
1379 if (!q_vector->txr_count && !q_vector->rxr_count)
1380 return IRQ_HANDLED;
1381
1382 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1383 for (i = 0; i < q_vector->txr_count; i++) {
1384 ring = &(adapter->tx_ring[r_idx]);
1385 ring->total_bytes = 0;
1386 ring->total_packets = 0;
1387 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1388 r_idx + 1);
1389 }
1390
1391 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1392 for (i = 0; i < q_vector->rxr_count; i++) {
1393 ring = &(adapter->rx_ring[r_idx]);
1394 ring->total_bytes = 0;
1395 ring->total_packets = 0;
1396 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1397 r_idx + 1);
1398 }
1399
1400 /* disable interrupts on this vector only */
1401 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1402 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001403
1404 return IRQ_HANDLED;
1405}
1406
1407/**
1408 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1409 * @napi: napi struct with our devices info in it
1410 * @budget: amount of work driver is allowed to do this pass, in packets
1411 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001412 * This function is optimized for cleaning one queue only on a single
1413 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001414 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001415static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1416{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001417 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001418 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001419 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001420 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001421 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001422 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001423
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001424 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001425 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001426#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001427 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001428 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001429#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001430
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001431 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001432
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001433 /* If all Rx work done, exit the polling mode */
1434 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001435 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001436 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001437 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001438 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001439 ixgbe_irq_enable_queues(adapter,
1440 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07001441 }
1442
1443 return work_done;
1444}
1445
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001446/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00001447 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001448 * @napi: napi struct with our devices info in it
1449 * @budget: amount of work driver is allowed to do this pass, in packets
1450 *
1451 * This function will clean more than one rx queue associated with a
1452 * q_vector.
1453 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00001454static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001455{
1456 struct ixgbe_q_vector *q_vector =
1457 container_of(napi, struct ixgbe_q_vector, napi);
1458 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001459 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001460 int work_done = 0, i;
1461 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001462 bool tx_clean_complete = true;
1463
1464 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1465 for (i = 0; i < q_vector->txr_count; i++) {
1466 ring = &(adapter->tx_ring[r_idx]);
1467#ifdef CONFIG_IXGBE_DCA
1468 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1469 ixgbe_update_tx_dca(adapter, ring);
1470#endif
1471 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
1472 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1473 r_idx + 1);
1474 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001475
1476 /* attempt to distribute budget to each queue fairly, but don't allow
1477 * the budget to go below 1 because we'll exit polling */
1478 budget /= (q_vector->rxr_count ?: 1);
1479 budget = max(budget, 1);
1480 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1481 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck91281fd2009-06-04 16:00:27 +00001482 ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001483#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001484 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck91281fd2009-06-04 16:00:27 +00001485 ixgbe_update_rx_dca(adapter, ring);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001486#endif
Alexander Duyck91281fd2009-06-04 16:00:27 +00001487 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001488 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1489 r_idx + 1);
1490 }
1491
1492 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck91281fd2009-06-04 16:00:27 +00001493 ring = &(adapter->rx_ring[r_idx]);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001494 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001495 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001496 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001497 if (adapter->rx_itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001498 ixgbe_set_itr_msix(q_vector);
1499 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001500 ixgbe_irq_enable_queues(adapter,
1501 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001502 return 0;
1503 }
1504
1505 return work_done;
1506}
Alexander Duyck91281fd2009-06-04 16:00:27 +00001507
1508/**
1509 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
1510 * @napi: napi struct with our devices info in it
1511 * @budget: amount of work driver is allowed to do this pass, in packets
1512 *
1513 * This function is optimized for cleaning one queue only on a single
1514 * q_vector!!!
1515 **/
1516static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
1517{
1518 struct ixgbe_q_vector *q_vector =
1519 container_of(napi, struct ixgbe_q_vector, napi);
1520 struct ixgbe_adapter *adapter = q_vector->adapter;
1521 struct ixgbe_ring *tx_ring = NULL;
1522 int work_done = 0;
1523 long r_idx;
1524
1525 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1526 tx_ring = &(adapter->tx_ring[r_idx]);
1527#ifdef CONFIG_IXGBE_DCA
1528 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1529 ixgbe_update_tx_dca(adapter, tx_ring);
1530#endif
1531
1532 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
1533 work_done = budget;
1534
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001535 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00001536 if (work_done < budget) {
1537 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001538 if (adapter->tx_itr_setting & 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00001539 ixgbe_set_itr_msix(q_vector);
1540 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1541 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
1542 }
1543
1544 return work_done;
1545}
1546
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001547static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001548 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001549{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001550 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1551
1552 set_bit(r_idx, q_vector->rxr_idx);
1553 q_vector->rxr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001554}
Auke Kok9a799d72007-09-15 14:07:45 -07001555
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001556static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001557 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001558{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001559 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1560
1561 set_bit(t_idx, q_vector->txr_idx);
1562 q_vector->txr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001563}
Auke Kok9a799d72007-09-15 14:07:45 -07001564
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001565/**
1566 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1567 * @adapter: board private structure to initialize
1568 * @vectors: allotted vector count for descriptor rings
1569 *
1570 * This function maps descriptor rings to the queue-specific vectors
1571 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1572 * one vector per ring/queue, but on a constrained vector budget, we
1573 * group the rings as "efficiently" as possible. You would add new
1574 * mapping configurations in here.
1575 **/
1576static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001577 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001578{
1579 int v_start = 0;
1580 int rxr_idx = 0, txr_idx = 0;
1581 int rxr_remaining = adapter->num_rx_queues;
1582 int txr_remaining = adapter->num_tx_queues;
1583 int i, j;
1584 int rqpv, tqpv;
1585 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001586
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001587 /* No mapping required if MSI-X is disabled. */
1588 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001589 goto out;
1590
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001591 /*
1592 * The ideal configuration...
1593 * We have enough vectors to map one per queue.
1594 */
1595 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1596 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1597 map_vector_to_rxq(adapter, v_start, rxr_idx);
1598
1599 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1600 map_vector_to_txq(adapter, v_start, txr_idx);
1601
1602 goto out;
1603 }
1604
1605 /*
1606 * If we don't have enough vectors for a 1-to-1
1607 * mapping, we'll have to group them so there are
1608 * multiple queues per vector.
1609 */
1610 /* Re-adjusting *qpv takes care of the remainder. */
1611 for (i = v_start; i < vectors; i++) {
1612 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1613 for (j = 0; j < rqpv; j++) {
1614 map_vector_to_rxq(adapter, i, rxr_idx);
1615 rxr_idx++;
1616 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001617 }
Auke Kok9a799d72007-09-15 14:07:45 -07001618 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001619 for (i = v_start; i < vectors; i++) {
1620 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1621 for (j = 0; j < tqpv; j++) {
1622 map_vector_to_txq(adapter, i, txr_idx);
1623 txr_idx++;
1624 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001625 }
Auke Kok9a799d72007-09-15 14:07:45 -07001626 }
1627
Auke Kok9a799d72007-09-15 14:07:45 -07001628out:
Auke Kok9a799d72007-09-15 14:07:45 -07001629 return err;
1630}
1631
1632/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001633 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1634 * @adapter: board private structure
1635 *
1636 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1637 * interrupts from the kernel.
1638 **/
1639static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1640{
1641 struct net_device *netdev = adapter->netdev;
1642 irqreturn_t (*handler)(int, void *);
1643 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001644 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001645
1646 /* Decrement for Other and TCP Timer vectors */
1647 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1648
1649 /* Map the Tx/Rx rings to the vectors we were allotted. */
1650 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1651 if (err)
1652 goto out;
1653
1654#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001655 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1656 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001657 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001658 handler = SET_HANDLER(adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001659
1660 if(handler == &ixgbe_msix_clean_rx) {
1661 sprintf(adapter->name[vector], "%s-%s-%d",
1662 netdev->name, "rx", ri++);
1663 }
1664 else if(handler == &ixgbe_msix_clean_tx) {
1665 sprintf(adapter->name[vector], "%s-%s-%d",
1666 netdev->name, "tx", ti++);
1667 }
1668 else
1669 sprintf(adapter->name[vector], "%s-%s-%d",
1670 netdev->name, "TxRx", vector);
1671
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001672 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001673 handler, 0, adapter->name[vector],
Alexander Duyck7a921c92009-05-06 10:43:28 +00001674 adapter->q_vector[vector]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001675 if (err) {
1676 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001677 "request_irq failed for MSIX interrupt "
1678 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001679 goto free_queue_irqs;
1680 }
1681 }
1682
1683 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1684 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001685 ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001686 if (err) {
1687 DPRINTK(PROBE, ERR,
1688 "request_irq for msix_lsc failed: %d\n", err);
1689 goto free_queue_irqs;
1690 }
1691
1692 return 0;
1693
1694free_queue_irqs:
1695 for (i = vector - 1; i >= 0; i--)
1696 free_irq(adapter->msix_entries[--vector].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001697 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001698 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1699 pci_disable_msix(adapter->pdev);
1700 kfree(adapter->msix_entries);
1701 adapter->msix_entries = NULL;
1702out:
1703 return err;
1704}
1705
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001706static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1707{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001708 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001709 u8 current_itr;
1710 u32 new_itr = q_vector->eitr;
1711 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1712 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1713
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001714 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001715 q_vector->tx_itr,
1716 tx_ring->total_packets,
1717 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001718 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001719 q_vector->rx_itr,
1720 rx_ring->total_packets,
1721 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001722
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001723 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001724
1725 switch (current_itr) {
1726 /* counts and packets in update_itr are dependent on these numbers */
1727 case lowest_latency:
1728 new_itr = 100000;
1729 break;
1730 case low_latency:
1731 new_itr = 20000; /* aka hwitr = ~200 */
1732 break;
1733 case bulk_latency:
1734 new_itr = 8000;
1735 break;
1736 default:
1737 break;
1738 }
1739
1740 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001741 /* do an exponential smoothing */
1742 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001743
1744 /* save the algorithm value here, not the smoothed one */
1745 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001746
1747 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001748 }
1749
1750 return;
1751}
1752
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001753/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001754 * ixgbe_irq_enable - Enable default interrupt generation settings
1755 * @adapter: board private structure
1756 **/
1757static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1758{
1759 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00001760
1761 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
David S. Miller6ab33d52008-11-20 16:44:00 -08001762 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1763 mask |= IXGBE_EIMS_GPI_SDP1;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001764 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001765 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001766 mask |= IXGBE_EIMS_GPI_SDP1;
1767 mask |= IXGBE_EIMS_GPI_SDP2;
1768 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001769 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
1770 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
1771 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001772
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001773 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Nelson, Shannon835462f2009-04-27 22:42:54 +00001774 ixgbe_irq_enable_queues(adapter, ~0);
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001775 IXGBE_WRITE_FLUSH(&adapter->hw);
1776}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001777
1778/**
1779 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001780 * @irq: interrupt number
1781 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001782 **/
1783static irqreturn_t ixgbe_intr(int irq, void *data)
1784{
1785 struct net_device *netdev = data;
1786 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1787 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001788 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07001789 u32 eicr;
1790
Don Skidmore54037502009-02-21 15:42:56 -08001791 /*
1792 * Workaround for silicon errata. Mask the interrupts
1793 * before the read of EICR.
1794 */
1795 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1796
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001797 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1798 * therefore no explict interrupt disable is necessary */
1799 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001800 if (!eicr) {
1801 /* shared interrupt alert!
1802 * make sure interrupts are enabled because the read will
1803 * have disabled interrupts due to EIAM */
1804 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001805 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001806 }
Auke Kok9a799d72007-09-15 14:07:45 -07001807
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001808 if (eicr & IXGBE_EICR_LSC)
1809 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001810
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001811 if (hw->mac.type == ixgbe_mac_82599EB)
1812 ixgbe_check_sfp_event(adapter, eicr);
1813
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001814 ixgbe_check_fan_failure(adapter, eicr);
1815
Alexander Duyck7a921c92009-05-06 10:43:28 +00001816 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001817 adapter->tx_ring[0].total_packets = 0;
1818 adapter->tx_ring[0].total_bytes = 0;
1819 adapter->rx_ring[0].total_packets = 0;
1820 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001821 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00001822 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07001823 }
1824
1825 return IRQ_HANDLED;
1826}
1827
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001828static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1829{
1830 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1831
1832 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001833 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001834 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1835 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1836 q_vector->rxr_count = 0;
1837 q_vector->txr_count = 0;
1838 }
1839}
1840
Auke Kok9a799d72007-09-15 14:07:45 -07001841/**
1842 * ixgbe_request_irq - initialize interrupts
1843 * @adapter: board private structure
1844 *
1845 * Attempts to configure interrupts using the best available
1846 * capabilities of the hardware and kernel.
1847 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001848static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001849{
1850 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001851 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001852
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001853 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1854 err = ixgbe_request_msix_irqs(adapter);
1855 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001856 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001857 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001858 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001859 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001860 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001861 }
1862
Auke Kok9a799d72007-09-15 14:07:45 -07001863 if (err)
1864 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1865
Auke Kok9a799d72007-09-15 14:07:45 -07001866 return err;
1867}
1868
1869static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1870{
1871 struct net_device *netdev = adapter->netdev;
1872
1873 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001874 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001875
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001876 q_vectors = adapter->num_msix_vectors;
1877
1878 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001879 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001880
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001881 i--;
1882 for (; i >= 0; i--) {
1883 free_irq(adapter->msix_entries[i].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001884 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001885 }
1886
1887 ixgbe_reset_q_vectors(adapter);
1888 } else {
1889 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001890 }
1891}
1892
1893/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001894 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1895 * @adapter: board private structure
1896 **/
1897static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1898{
Nelson, Shannon835462f2009-04-27 22:42:54 +00001899 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1900 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1901 } else {
1902 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
1903 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001904 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001905 }
1906 IXGBE_WRITE_FLUSH(&adapter->hw);
1907 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1908 int i;
1909 for (i = 0; i < adapter->num_msix_vectors; i++)
1910 synchronize_irq(adapter->msix_entries[i].vector);
1911 } else {
1912 synchronize_irq(adapter->pdev->irq);
1913 }
1914}
1915
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001916/**
Auke Kok9a799d72007-09-15 14:07:45 -07001917 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1918 *
1919 **/
1920static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1921{
Auke Kok9a799d72007-09-15 14:07:45 -07001922 struct ixgbe_hw *hw = &adapter->hw;
1923
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001924 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001925 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001926
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001927 ixgbe_set_ivar(adapter, 0, 0, 0);
1928 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001929
1930 map_vector_to_rxq(adapter, 0, 0);
1931 map_vector_to_txq(adapter, 0, 0);
1932
1933 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001934}
1935
1936/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001937 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001938 * @adapter: board private structure
1939 *
1940 * Configure the Tx unit of the MAC after a reset.
1941 **/
1942static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1943{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001944 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001945 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001946 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001947
1948 /* Setup the HW Tx Head and Tail descriptor pointers */
1949 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001950 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1951 j = ring->reg_idx;
1952 tdba = ring->dma;
1953 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001954 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Yang Hongyang284901a2009-04-06 19:01:15 -07001955 (tdba & DMA_BIT_MASK(32)));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001956 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1957 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1958 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1959 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1960 adapter->tx_ring[i].head = IXGBE_TDH(j);
1961 adapter->tx_ring[i].tail = IXGBE_TDT(j);
Peter P Waskiewicz Jr84f62d42009-09-30 12:07:16 +00001962 /*
1963 * Disable Tx Head Writeback RO bit, since this hoses
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001964 * bookkeeping if things aren't delivered in order.
1965 */
Peter P Waskiewicz Jr84f62d42009-09-30 12:07:16 +00001966 switch (hw->mac.type) {
1967 case ixgbe_mac_82598EB:
1968 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
1969 break;
1970 case ixgbe_mac_82599EB:
1971 default:
1972 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j));
1973 break;
1974 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001975 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Peter P Waskiewicz Jr84f62d42009-09-30 12:07:16 +00001976 switch (hw->mac.type) {
1977 case ixgbe_mac_82598EB:
1978 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
1979 break;
1980 case ixgbe_mac_82599EB:
1981 default:
1982 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl);
1983 break;
1984 }
Auke Kok9a799d72007-09-15 14:07:45 -07001985 }
Don Skidmoreee5f7842009-11-06 12:56:20 +00001986
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001987 if (hw->mac.type == ixgbe_mac_82599EB) {
Don Skidmoreee5f7842009-11-06 12:56:20 +00001988 u32 rttdcs;
1989
1990 /* disable the arbiter while setting MTQC */
1991 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
1992 rttdcs |= IXGBE_RTTDCS_ARBDIS;
1993 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
1994
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001995 /* We enable 8 traffic classes, DCB only */
1996 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1997 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1998 IXGBE_MTQC_8TC_8TQ));
Don Skidmoreee5f7842009-11-06 12:56:20 +00001999 else
2000 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
2001
2002 /* re-eable the arbiter */
2003 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2004 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002005 }
Auke Kok9a799d72007-09-15 14:07:45 -07002006}
2007
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002008#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002009
Yi Zoua6616b42009-08-06 13:05:23 +00002010static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
2011 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002012{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002013 u32 srrctl;
Yi Zoua6616b42009-08-06 13:05:23 +00002014 int index;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002015 struct ixgbe_ring_feature *feature = adapter->ring_feature;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002016
Yi Zoua6616b42009-08-06 13:05:23 +00002017 index = rx_ring->reg_idx;
2018 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
2019 unsigned long mask;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002020 mask = (unsigned long) feature[RING_F_RSS].mask;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07002021 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002022 }
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002023 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
2024
2025 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2026 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
2027
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002028 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2029 IXGBE_SRRCTL_BSIZEHDR_MASK;
2030
Yi Zou6e455b892009-08-06 13:05:44 +00002031 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002032#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2033 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2034#else
2035 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2036#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002037 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002038 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002039 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2040 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002041 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002042 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002043
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002044 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
2045}
2046
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002047static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
2048{
2049 u32 mrqc = 0;
2050 int mask;
2051
2052 if (!(adapter->hw.mac.type == ixgbe_mac_82599EB))
2053 return mrqc;
2054
2055 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2056#ifdef CONFIG_IXGBE_DCB
2057 | IXGBE_FLAG_DCB_ENABLED
2058#endif
2059 );
2060
2061 switch (mask) {
2062 case (IXGBE_FLAG_RSS_ENABLED):
2063 mrqc = IXGBE_MRQC_RSSEN;
2064 break;
2065#ifdef CONFIG_IXGBE_DCB
2066 case (IXGBE_FLAG_DCB_ENABLED):
2067 mrqc = IXGBE_MRQC_RT8TCEN;
2068 break;
2069#endif /* CONFIG_IXGBE_DCB */
2070 default:
2071 break;
2072 }
2073
2074 return mrqc;
2075}
2076
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002077/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002078 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2079 * @adapter: address of board private structure
2080 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002081 **/
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002082static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002083{
2084 struct ixgbe_ring *rx_ring;
2085 struct ixgbe_hw *hw = &adapter->hw;
2086 int j;
2087 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002088 int rx_buf_len;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002089
2090 rx_ring = &adapter->rx_ring[index];
2091 j = rx_ring->reg_idx;
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002092 rx_buf_len = rx_ring->rx_buf_len;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002093 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j));
2094 rscctrl |= IXGBE_RSCCTL_RSCEN;
2095 /*
2096 * we must limit the number of descriptors so that the
2097 * total size of max desc * buf_len is not greater
2098 * than 65535
2099 */
2100 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
2101#if (MAX_SKB_FRAGS > 16)
2102 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2103#elif (MAX_SKB_FRAGS > 8)
2104 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2105#elif (MAX_SKB_FRAGS > 4)
2106 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2107#else
2108 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2109#endif
2110 } else {
2111 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2112 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2113 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2114 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2115 else
2116 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2117 }
2118 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl);
2119}
2120
2121/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002122 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002123 * @adapter: board private structure
2124 *
2125 * Configure the Rx unit of the MAC after a reset.
2126 **/
2127static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
2128{
2129 u64 rdba;
2130 struct ixgbe_hw *hw = &adapter->hw;
Yi Zoua6616b42009-08-06 13:05:23 +00002131 struct ixgbe_ring *rx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07002132 struct net_device *netdev = adapter->netdev;
2133 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002134 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002135 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002136 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2137 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2138 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07002139 u32 fctrl, hlreg0;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002140 u32 reta = 0, mrqc = 0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002141 u32 rdrxctl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002142 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07002143
2144 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002145 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07002146
2147 /* Set the RX buffer length according to the mode */
2148 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002149 rx_buf_len = IXGBE_RX_HDR_SIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002150 if (hw->mac.type == ixgbe_mac_82599EB) {
2151 /* PSRTYPE must be initialized in 82599 */
2152 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
2153 IXGBE_PSRTYPE_UDPHDR |
2154 IXGBE_PSRTYPE_IPV4HDR |
Yi Zoudfa12f02009-05-07 10:39:35 +00002155 IXGBE_PSRTYPE_IPV6HDR |
2156 IXGBE_PSRTYPE_L2HDR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002157 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
2158 }
Auke Kok9a799d72007-09-15 14:07:45 -07002159 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00002160 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00002161 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002162 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07002163 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002164 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07002165 }
2166
2167 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
2168 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002169 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002170 fctrl |= IXGBE_FCTRL_PMCF;
Auke Kok9a799d72007-09-15 14:07:45 -07002171 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
2172
2173 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2174 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2175 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
2176 else
2177 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Yi Zou63f39bd2009-05-17 12:34:35 +00002178#ifdef IXGBE_FCOE
Yi Zouf34c5c82009-08-14 12:42:17 +00002179 if (netdev->features & NETIF_F_FCOE_MTU)
Yi Zou63f39bd2009-05-17 12:34:35 +00002180 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2181#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002182 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2183
Auke Kok9a799d72007-09-15 14:07:45 -07002184 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
2185 /* disable receives while setting up the descriptors */
2186 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2187 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
2188
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002189 /*
2190 * Setup the HW Rx Head and Tail Descriptor Pointers and
2191 * the Base and Length of the Rx Descriptor Ring
2192 */
Auke Kok9a799d72007-09-15 14:07:45 -07002193 for (i = 0; i < adapter->num_rx_queues; i++) {
Yi Zoua6616b42009-08-06 13:05:23 +00002194 rx_ring = &adapter->rx_ring[i];
2195 rdba = rx_ring->dma;
2196 j = rx_ring->reg_idx;
Yang Hongyang284901a2009-04-06 19:01:15 -07002197 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32)));
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002198 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
2199 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
2200 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
2201 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
Yi Zoua6616b42009-08-06 13:05:23 +00002202 rx_ring->head = IXGBE_RDH(j);
2203 rx_ring->tail = IXGBE_RDT(j);
2204 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002205
Yi Zou6e455b892009-08-06 13:05:44 +00002206 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
2207 rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED;
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00002208 else
2209 rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002210
Yi Zou63f39bd2009-05-17 12:34:35 +00002211#ifdef IXGBE_FCOE
Yi Zouf34c5c82009-08-14 12:42:17 +00002212 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00002213 struct ixgbe_ring_feature *f;
2214 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00002215 if ((i >= f->mask) && (i < f->mask + f->indices)) {
2216 rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
2217 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
2218 rx_ring->rx_buf_len =
2219 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2220 }
Yi Zou63f39bd2009-05-17 12:34:35 +00002221 }
2222
2223#endif /* IXGBE_FCOE */
Yi Zoua6616b42009-08-06 13:05:23 +00002224 ixgbe_configure_srrctl(adapter, rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002225 }
2226
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002227 if (hw->mac.type == ixgbe_mac_82598EB) {
2228 /*
2229 * For VMDq support of different descriptor types or
2230 * buffer sizes through the use of multiple SRRCTL
2231 * registers, RDRXCTL.MVMEN must be set to 1
2232 *
2233 * also, the manual doesn't mention it clearly but DCA hints
2234 * will only use queue 0's tags unless this bit is set. Side
2235 * effects of setting this bit are only that SRRCTL must be
2236 * fully programmed [0..15]
2237 */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002238 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2239 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
2240 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
Alexander Duyck2f90b862008-11-20 20:52:10 -08002241 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002242
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002243 /* Program MRQC for the distribution of queues */
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002244 mrqc = ixgbe_setup_mrqc(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002245
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002246 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07002247 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002248 for (i = 0, j = 0; i < 128; i++, j++) {
2249 if (j == adapter->ring_feature[RING_F_RSS].indices)
2250 j = 0;
2251 /* reta = 4-byte sliding window of
2252 * 0x00..(indices-1)(indices-1)00..etc. */
2253 reta = (reta << 8) | (j * 0x11);
2254 if ((i & 3) == 3)
2255 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07002256 }
2257
2258 /* Fill out hash function seeds */
2259 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002260 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002261
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002262 if (hw->mac.type == ixgbe_mac_82598EB)
2263 mrqc |= IXGBE_MRQC_RSSEN;
Auke Kok9a799d72007-09-15 14:07:45 -07002264 /* Perform hash on these packet types */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002265 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2266 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2267 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
2268 | IXGBE_MRQC_RSS_FIELD_IPV6
2269 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
2270 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07002271 }
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002272 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002273
2274 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2275
2276 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
2277 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
2278 /* Disable indicating checksum in descriptor, enables
2279 * RSS hash */
2280 rxcsum |= IXGBE_RXCSUM_PCSD;
2281 }
2282 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
2283 /* Enable IPv4 payload checksum for UDP fragments
2284 * if PCSD is not set */
2285 rxcsum |= IXGBE_RXCSUM_IPPCSE;
2286 }
2287
2288 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002289
2290 if (hw->mac.type == ixgbe_mac_82599EB) {
2291 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2292 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002293 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002294 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
2295 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002296
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00002297 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002298 /* Enable 82599 HW-RSC */
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002299 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002300 ixgbe_configure_rscctl(adapter, i);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002301
Alexander Duyckf8212f92009-04-27 22:42:37 +00002302 /* Disable RSC for ACK packets */
2303 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
2304 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
2305 }
Auke Kok9a799d72007-09-15 14:07:45 -07002306}
2307
Auke Kok9a799d72007-09-15 14:07:45 -07002308static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2309{
2310 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002311 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002312
2313 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002314 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002315}
2316
2317static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2318{
2319 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002320 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002321
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002322 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2323 ixgbe_irq_disable(adapter);
2324
Auke Kok9a799d72007-09-15 14:07:45 -07002325 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002326
2327 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2328 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002329
2330 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002331 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07002332}
2333
Don Skidmore068c89b2009-01-19 16:54:36 -08002334static void ixgbe_vlan_rx_register(struct net_device *netdev,
2335 struct vlan_group *grp)
2336{
2337 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2338 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002339 int i, j;
Don Skidmore068c89b2009-01-19 16:54:36 -08002340
2341 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2342 ixgbe_irq_disable(adapter);
2343 adapter->vlgrp = grp;
2344
2345 /*
2346 * For a DCB driver, always enable VLAN tag stripping so we can
2347 * still receive traffic from a DCB-enabled host even if we're
2348 * not in DCB mode.
2349 */
2350 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
Alexander Duyckdc63d372009-11-23 06:32:57 +00002351
2352 /* Disable CFI check */
2353 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2354
2355 /* enable VLAN tag stripping */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002356 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckdc63d372009-11-23 06:32:57 +00002357 ctrl |= IXGBE_VLNCTRL_VME;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002358 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002359 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckdc63d372009-11-23 06:32:57 +00002360 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002361 j = adapter->rx_ring[i].reg_idx;
2362 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
2363 ctrl |= IXGBE_RXDCTL_VME;
2364 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
2365 }
Don Skidmore068c89b2009-01-19 16:54:36 -08002366 }
Alexander Duyckdc63d372009-11-23 06:32:57 +00002367
2368 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
2369
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002370 ixgbe_vlan_rx_add_vid(netdev, 0);
Don Skidmore068c89b2009-01-19 16:54:36 -08002371
2372 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2373 ixgbe_irq_enable(adapter);
2374}
2375
Auke Kok9a799d72007-09-15 14:07:45 -07002376static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
2377{
2378 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2379
2380 if (adapter->vlgrp) {
2381 u16 vid;
2382 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2383 if (!vlan_group_get_device(adapter->vlgrp, vid))
2384 continue;
2385 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
2386 }
2387 }
2388}
2389
Christopher Leech2c5645c2008-08-26 04:27:02 -07002390static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
2391{
2392 struct dev_mc_list *mc_ptr;
2393 u8 *addr = *mc_addr_ptr;
2394 *vmdq = 0;
2395
2396 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
2397 if (mc_ptr->next)
2398 *mc_addr_ptr = mc_ptr->next->dmi_addr;
2399 else
2400 *mc_addr_ptr = NULL;
2401
2402 return addr;
2403}
2404
Auke Kok9a799d72007-09-15 14:07:45 -07002405/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07002406 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07002407 * @netdev: network interface device structure
2408 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07002409 * The set_rx_method entry point is called whenever the unicast/multicast
2410 * address list or the network interface flags are updated. This routine is
2411 * responsible for configuring the hardware for proper unicast, multicast and
2412 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07002413 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07002414static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07002415{
2416 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2417 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07002418 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002419 u8 *addr_list = NULL;
2420 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002421
2422 /* Check for Promiscuous and All Multicast modes */
2423
2424 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07002425 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07002426
2427 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07002428 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002429 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07002430 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07002431 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002432 if (netdev->flags & IFF_ALLMULTI) {
2433 fctrl |= IXGBE_FCTRL_MPE;
2434 fctrl &= ~IXGBE_FCTRL_UPE;
2435 } else {
2436 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2437 }
Alexander Duyck3d016252008-08-26 18:30:04 -07002438 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002439 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002440 }
2441
2442 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07002443 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07002444
Christopher Leech2c5645c2008-08-26 04:27:02 -07002445 /* reprogram secondary unicast list */
Jiri Pirko31278e72009-06-17 01:12:19 +00002446 hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list);
Auke Kok9a799d72007-09-15 14:07:45 -07002447
Christopher Leech2c5645c2008-08-26 04:27:02 -07002448 /* reprogram multicast list */
2449 addr_count = netdev->mc_count;
2450 if (addr_count)
2451 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002452 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2453 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002454}
2455
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002456static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2457{
2458 int q_idx;
2459 struct ixgbe_q_vector *q_vector;
2460 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2461
2462 /* legacy and MSI only use one vector */
2463 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2464 q_vectors = 1;
2465
2466 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002467 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002468 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002469 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002470 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2471 if (!q_vector->rxr_count || !q_vector->txr_count) {
2472 if (q_vector->txr_count == 1)
2473 napi->poll = &ixgbe_clean_txonly;
2474 else if (q_vector->rxr_count == 1)
2475 napi->poll = &ixgbe_clean_rxonly;
2476 }
2477 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002478
2479 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002480 }
2481}
2482
2483static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2484{
2485 int q_idx;
2486 struct ixgbe_q_vector *q_vector;
2487 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2488
2489 /* legacy and MSI only use one vector */
2490 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2491 q_vectors = 1;
2492
2493 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002494 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002495 napi_disable(&q_vector->napi);
2496 }
2497}
2498
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002499#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002500/*
2501 * ixgbe_configure_dcb - Configure DCB hardware
2502 * @adapter: ixgbe adapter struct
2503 *
2504 * This is called by the driver on open to configure the DCB hardware.
2505 * This is also called by the gennetlink interface when reconfiguring
2506 * the DCB state.
2507 */
2508static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2509{
2510 struct ixgbe_hw *hw = &adapter->hw;
2511 u32 txdctl, vlnctrl;
2512 int i, j;
2513
2514 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2515 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2516 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2517
2518 /* reconfigure the hardware */
2519 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2520
2521 for (i = 0; i < adapter->num_tx_queues; i++) {
2522 j = adapter->tx_ring[i].reg_idx;
2523 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2524 /* PThresh workaround for Tx hang with DFP enabled. */
2525 txdctl |= 32;
2526 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2527 }
2528 /* Enable VLAN tag insert/strip */
2529 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002530 if (hw->mac.type == ixgbe_mac_82598EB) {
2531 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2532 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2533 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2534 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2535 vlnctrl |= IXGBE_VLNCTRL_VFE;
2536 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2537 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2538 for (i = 0; i < adapter->num_rx_queues; i++) {
2539 j = adapter->rx_ring[i].reg_idx;
2540 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2541 vlnctrl |= IXGBE_RXDCTL_VME;
2542 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2543 }
2544 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08002545 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2546}
2547
2548#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002549static void ixgbe_configure(struct ixgbe_adapter *adapter)
2550{
2551 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002552 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002553 int i;
2554
Christopher Leech2c5645c2008-08-26 04:27:02 -07002555 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002556
2557 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002558#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002559 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Yi Zoub352e402009-11-06 12:55:38 +00002560 if (hw->mac.type == ixgbe_mac_82598EB)
2561 netif_set_gso_max_size(netdev, 32768);
2562 else
2563 netif_set_gso_max_size(netdev, 65536);
Alexander Duyck2f90b862008-11-20 20:52:10 -08002564 ixgbe_configure_dcb(adapter);
2565 } else {
2566 netif_set_gso_max_size(netdev, 65536);
2567 }
2568#else
2569 netif_set_gso_max_size(netdev, 65536);
2570#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002571
Yi Zoueacd73f2009-05-13 13:11:06 +00002572#ifdef IXGBE_FCOE
2573 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2574 ixgbe_configure_fcoe(adapter);
2575
2576#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002577 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2578 for (i = 0; i < adapter->num_tx_queues; i++)
2579 adapter->tx_ring[i].atr_sample_rate =
2580 adapter->atr_sample_rate;
2581 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
2582 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
2583 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
2584 }
2585
Auke Kok9a799d72007-09-15 14:07:45 -07002586 ixgbe_configure_tx(adapter);
2587 ixgbe_configure_rx(adapter);
2588 for (i = 0; i < adapter->num_rx_queues; i++)
2589 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002590 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07002591}
2592
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002593static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2594{
2595 switch (hw->phy.type) {
2596 case ixgbe_phy_sfp_avago:
2597 case ixgbe_phy_sfp_ftl:
2598 case ixgbe_phy_sfp_intel:
2599 case ixgbe_phy_sfp_unknown:
2600 case ixgbe_phy_tw_tyco:
2601 case ixgbe_phy_tw_unknown:
2602 return true;
2603 default:
2604 return false;
2605 }
2606}
2607
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002608/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002609 * ixgbe_sfp_link_config - set up SFP+ link
2610 * @adapter: pointer to private adapter struct
2611 **/
2612static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2613{
2614 struct ixgbe_hw *hw = &adapter->hw;
2615
2616 if (hw->phy.multispeed_fiber) {
2617 /*
2618 * In multispeed fiber setups, the device may not have
2619 * had a physical connection when the driver loaded.
2620 * If that's the case, the initial link configuration
2621 * couldn't get the MAC into 10G or 1G mode, so we'll
2622 * never have a link status change interrupt fire.
2623 * We need to try and force an autonegotiation
2624 * session, then bring up link.
2625 */
2626 hw->mac.ops.setup_sfp(hw);
2627 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2628 schedule_work(&adapter->multispeed_fiber_task);
2629 } else {
2630 /*
2631 * Direct Attach Cu and non-multispeed fiber modules
2632 * still need to be configured properly prior to
2633 * attempting link.
2634 */
2635 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2636 schedule_work(&adapter->sfp_config_module_task);
2637 }
2638}
2639
2640/**
2641 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002642 * @hw: pointer to private hardware struct
2643 *
2644 * Returns 0 on success, negative on failure
2645 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002646static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002647{
2648 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00002649 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002650 u32 ret = IXGBE_ERR_LINK_SETUP;
2651
2652 if (hw->mac.ops.check_link)
2653 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2654
2655 if (ret)
2656 goto link_cfg_out;
2657
2658 if (hw->mac.ops.get_link_capabilities)
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00002659 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002660 if (ret)
2661 goto link_cfg_out;
2662
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00002663 if (hw->mac.ops.setup_link)
2664 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002665link_cfg_out:
2666 return ret;
2667}
2668
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002669#define IXGBE_MAX_RX_DESC_POLL 10
2670static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2671 int rxr)
2672{
2673 int j = adapter->rx_ring[rxr].reg_idx;
2674 int k;
2675
2676 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2677 if (IXGBE_READ_REG(&adapter->hw,
2678 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2679 break;
2680 else
2681 msleep(1);
2682 }
2683 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2684 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2685 "not set within the polling period\n", rxr);
2686 }
2687 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2688 (adapter->rx_ring[rxr].count - 1));
2689}
2690
Auke Kok9a799d72007-09-15 14:07:45 -07002691static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2692{
2693 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07002694 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002695 int i, j = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002696 int num_rx_rings = adapter->num_rx_queues;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002697 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002698 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002699 u32 txdctl, rxdctl, mhadd;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002700 u32 dmatxctl;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002701 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002702
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002703 ixgbe_get_hw_control(adapter);
2704
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002705 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2706 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002707 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2708 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002709 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002710 } else {
2711 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002712 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002713 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002714 /* XXX: to interrupt immediately for EICS writes, enable this */
2715 /* gpie |= IXGBE_GPIE_EIMEN; */
2716 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2717 }
2718
2719 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2720 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2721 * specifically only auto mask tx and rx interrupts */
2722 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002723 }
2724
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002725 /* Enable fan failure interrupt if media type is copper */
2726 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2727 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2728 gpie |= IXGBE_SDP1_GPIEN;
2729 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2730 }
2731
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002732 if (hw->mac.type == ixgbe_mac_82599EB) {
2733 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2734 gpie |= IXGBE_SDP1_GPIEN;
2735 gpie |= IXGBE_SDP2_GPIEN;
2736 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2737 }
2738
Yi Zou63f39bd2009-05-17 12:34:35 +00002739#ifdef IXGBE_FCOE
2740 /* adjust max frame to be able to do baby jumbo for FCoE */
Yi Zouf34c5c82009-08-14 12:42:17 +00002741 if ((netdev->features & NETIF_F_FCOE_MTU) &&
Yi Zou63f39bd2009-05-17 12:34:35 +00002742 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
2743 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
2744
2745#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07002746 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002747 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2748 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2749 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2750
2751 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2752 }
2753
2754 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002755 j = adapter->tx_ring[i].reg_idx;
2756 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002757 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2758 txdctl |= (8 << 16);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002759 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2760 }
2761
2762 if (hw->mac.type == ixgbe_mac_82599EB) {
2763 /* DMATXCTL.EN must be set after all Tx queue config is done */
2764 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2765 dmatxctl |= IXGBE_DMATXCTL_TE;
2766 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2767 }
2768 for (i = 0; i < adapter->num_tx_queues; i++) {
2769 j = adapter->tx_ring[i].reg_idx;
2770 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Auke Kok9a799d72007-09-15 14:07:45 -07002771 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002772 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002773 }
2774
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002775 for (i = 0; i < num_rx_rings; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002776 j = adapter->rx_ring[i].reg_idx;
2777 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2778 /* enable PTHRESH=32 descriptors (half the internal cache)
2779 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2780 * this also removes a pesky rx_no_buffer_count increment */
2781 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002782 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002783 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002784 if (hw->mac.type == ixgbe_mac_82599EB)
2785 ixgbe_rx_desc_queue_enable(adapter, i);
Auke Kok9a799d72007-09-15 14:07:45 -07002786 }
2787 /* enable all receives */
2788 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002789 if (hw->mac.type == ixgbe_mac_82598EB)
2790 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2791 else
2792 rxdctl |= IXGBE_RXCTRL_RXEN;
2793 hw->mac.ops.enable_rx_dma(hw, rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002794
2795 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2796 ixgbe_configure_msix(adapter);
2797 else
2798 ixgbe_configure_msi_and_legacy(adapter);
2799
2800 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002801 ixgbe_napi_enable_all(adapter);
2802
2803 /* clear any pending interrupts, may auto mask */
2804 IXGBE_READ_REG(hw, IXGBE_EICR);
2805
Auke Kok9a799d72007-09-15 14:07:45 -07002806 ixgbe_irq_enable(adapter);
2807
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002808 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00002809 * If this adapter has a fan, check to see if we had a failure
2810 * before we enabled the interrupt.
2811 */
2812 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2813 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2814 if (esdp & IXGBE_ESDP_SDP1)
2815 DPRINTK(DRV, CRIT,
2816 "Fan has stopped, replace the adapter\n");
2817 }
2818
2819 /*
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002820 * For hot-pluggable SFP+ devices, a new SFP+ module may have
Don Skidmore19343de2009-07-02 12:50:31 +00002821 * arrived before interrupts were enabled but after probe. Such
2822 * devices wouldn't have their type identified yet. We need to
2823 * kick off the SFP+ module setup first, then try to bring up link.
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002824 * If we're not hot-pluggable SFP+, we just need to configure link
2825 * and bring it up.
2826 */
Don Skidmore19343de2009-07-02 12:50:31 +00002827 if (hw->phy.type == ixgbe_phy_unknown) {
2828 err = hw->phy.ops.identify(hw);
2829 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore5da43c12009-07-02 12:50:52 +00002830 /*
2831 * Take the device down and schedule the sfp tasklet
2832 * which will unregister_netdev and log it.
2833 */
Don Skidmore19343de2009-07-02 12:50:31 +00002834 ixgbe_down(adapter);
Don Skidmore5da43c12009-07-02 12:50:52 +00002835 schedule_work(&adapter->sfp_config_module_task);
Don Skidmore19343de2009-07-02 12:50:31 +00002836 return err;
2837 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002838 }
2839
2840 if (ixgbe_is_sfp(hw)) {
2841 ixgbe_sfp_link_config(adapter);
2842 } else {
2843 err = ixgbe_non_sfp_link_config(hw);
2844 if (err)
2845 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2846 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002847
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002848 for (i = 0; i < adapter->num_tx_queues; i++)
2849 set_bit(__IXGBE_FDIR_INIT_DONE,
2850 &(adapter->tx_ring[i].reinit_state));
2851
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002852 /* enable transmits */
2853 netif_tx_start_all_queues(netdev);
2854
Auke Kok9a799d72007-09-15 14:07:45 -07002855 /* bring the link up in the watchdog, this could race with our first
2856 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002857 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2858 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002859 mod_timer(&adapter->watchdog_timer, jiffies);
2860 return 0;
2861}
2862
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002863void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2864{
2865 WARN_ON(in_interrupt());
2866 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2867 msleep(1);
2868 ixgbe_down(adapter);
2869 ixgbe_up(adapter);
2870 clear_bit(__IXGBE_RESETTING, &adapter->state);
2871}
2872
Auke Kok9a799d72007-09-15 14:07:45 -07002873int ixgbe_up(struct ixgbe_adapter *adapter)
2874{
2875 /* hardware has been reset, we need to reload some things */
2876 ixgbe_configure(adapter);
2877
2878 return ixgbe_up_complete(adapter);
2879}
2880
2881void ixgbe_reset(struct ixgbe_adapter *adapter)
2882{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002883 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07002884 int err;
2885
2886 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002887 switch (err) {
2888 case 0:
2889 case IXGBE_ERR_SFP_NOT_PRESENT:
2890 break;
2891 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
2892 dev_err(&adapter->pdev->dev, "master disable timed out\n");
2893 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00002894 case IXGBE_ERR_EEPROM_VERSION:
2895 /* We are running on a pre-production device, log a warning */
2896 dev_warn(&adapter->pdev->dev, "This device is a pre-production "
2897 "adapter/LOM. Please be aware there may be issues "
2898 "associated with your hardware. If you are "
2899 "experiencing problems please contact your Intel or "
2900 "hardware representative who provided you with this "
2901 "hardware.\n");
2902 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002903 default:
2904 dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err);
2905 }
Auke Kok9a799d72007-09-15 14:07:45 -07002906
2907 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002908 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002909}
2910
Auke Kok9a799d72007-09-15 14:07:45 -07002911/**
2912 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2913 * @adapter: board private structure
2914 * @rx_ring: ring to free buffers from
2915 **/
2916static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002917 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002918{
2919 struct pci_dev *pdev = adapter->pdev;
2920 unsigned long size;
2921 unsigned int i;
2922
2923 /* Free all the Rx ring sk_buffs */
2924
2925 for (i = 0; i < rx_ring->count; i++) {
2926 struct ixgbe_rx_buffer *rx_buffer_info;
2927
2928 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2929 if (rx_buffer_info->dma) {
2930 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002931 rx_ring->rx_buf_len,
2932 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002933 rx_buffer_info->dma = 0;
2934 }
2935 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002936 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002937 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002938 do {
2939 struct sk_buff *this = skb;
2940 skb = skb->prev;
2941 dev_kfree_skb(this);
2942 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002943 }
2944 if (!rx_buffer_info->page)
2945 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00002946 if (rx_buffer_info->page_dma) {
2947 pci_unmap_page(pdev, rx_buffer_info->page_dma,
2948 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
2949 rx_buffer_info->page_dma = 0;
2950 }
Auke Kok9a799d72007-09-15 14:07:45 -07002951 put_page(rx_buffer_info->page);
2952 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002953 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002954 }
2955
2956 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2957 memset(rx_ring->rx_buffer_info, 0, size);
2958
2959 /* Zero out the descriptor ring */
2960 memset(rx_ring->desc, 0, rx_ring->size);
2961
2962 rx_ring->next_to_clean = 0;
2963 rx_ring->next_to_use = 0;
2964
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002965 if (rx_ring->head)
2966 writel(0, adapter->hw.hw_addr + rx_ring->head);
2967 if (rx_ring->tail)
2968 writel(0, adapter->hw.hw_addr + rx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002969}
2970
2971/**
2972 * ixgbe_clean_tx_ring - Free Tx Buffers
2973 * @adapter: board private structure
2974 * @tx_ring: ring to be cleaned
2975 **/
2976static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002977 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002978{
2979 struct ixgbe_tx_buffer *tx_buffer_info;
2980 unsigned long size;
2981 unsigned int i;
2982
2983 /* Free all the Tx ring sk_buffs */
2984
2985 for (i = 0; i < tx_ring->count; i++) {
2986 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2987 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2988 }
2989
2990 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2991 memset(tx_ring->tx_buffer_info, 0, size);
2992
2993 /* Zero out the descriptor ring */
2994 memset(tx_ring->desc, 0, tx_ring->size);
2995
2996 tx_ring->next_to_use = 0;
2997 tx_ring->next_to_clean = 0;
2998
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002999 if (tx_ring->head)
3000 writel(0, adapter->hw.hw_addr + tx_ring->head);
3001 if (tx_ring->tail)
3002 writel(0, adapter->hw.hw_addr + tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07003003}
3004
3005/**
Auke Kok9a799d72007-09-15 14:07:45 -07003006 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
3007 * @adapter: board private structure
3008 **/
3009static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
3010{
3011 int i;
3012
3013 for (i = 0; i < adapter->num_rx_queues; i++)
3014 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
3015}
3016
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003017/**
3018 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
3019 * @adapter: board private structure
3020 **/
3021static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
3022{
3023 int i;
3024
3025 for (i = 0; i < adapter->num_tx_queues; i++)
3026 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
3027}
3028
Auke Kok9a799d72007-09-15 14:07:45 -07003029void ixgbe_down(struct ixgbe_adapter *adapter)
3030{
3031 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003032 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003033 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003034 u32 txdctl;
3035 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07003036
3037 /* signal that we are down to the interrupt handler */
3038 set_bit(__IXGBE_DOWN, &adapter->state);
3039
3040 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003041 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3042 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07003043
3044 netif_tx_disable(netdev);
3045
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003046 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07003047 msleep(10);
3048
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003049 netif_tx_stop_all_queues(netdev);
3050
Auke Kok9a799d72007-09-15 14:07:45 -07003051 ixgbe_irq_disable(adapter);
3052
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003053 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003054
Don Skidmore0a1f87c2009-09-18 09:45:43 +00003055 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3056 del_timer_sync(&adapter->sfp_timer);
Auke Kok9a799d72007-09-15 14:07:45 -07003057 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003058 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07003059
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003060 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3061 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3062 cancel_work_sync(&adapter->fdir_reinit_task);
3063
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003064 /* disable transmits in the hardware now that interrupts are off */
3065 for (i = 0; i < adapter->num_tx_queues; i++) {
3066 j = adapter->tx_ring[i].reg_idx;
3067 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
3068 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
3069 (txdctl & ~IXGBE_TXDCTL_ENABLE));
3070 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00003071 /* Disable the Tx DMA engine on 82599 */
3072 if (hw->mac.type == ixgbe_mac_82599EB)
3073 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
3074 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
3075 ~IXGBE_DMATXCTL_TE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003076
Auke Kok9a799d72007-09-15 14:07:45 -07003077 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003078
Paul Larson6f4a0e42008-06-24 17:00:56 -07003079 if (!pci_channel_offline(adapter->pdev))
3080 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003081 ixgbe_clean_all_tx_rings(adapter);
3082 ixgbe_clean_all_rx_rings(adapter);
3083
Jeff Garzik5dd2d332008-10-16 05:09:31 -04003084#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07003085 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00003086 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07003087#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003088}
3089
Auke Kok9a799d72007-09-15 14:07:45 -07003090/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003091 * ixgbe_poll - NAPI Rx polling callback
3092 * @napi: structure for representing this polling device
3093 * @budget: how many packets driver is allowed to clean
3094 *
3095 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07003096 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003097static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07003098{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00003099 struct ixgbe_q_vector *q_vector =
3100 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003101 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00003102 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003103
Jeff Garzik5dd2d332008-10-16 05:09:31 -04003104#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08003105 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
3106 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
3107 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
3108 }
3109#endif
3110
Alexander Duyckfe49f042009-06-04 16:00:09 +00003111 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08003112 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07003113
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00003114 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003115 work_done = budget;
3116
David S. Miller53e52c72008-01-07 21:06:12 -08003117 /* If budget not fully consumed, exit the polling mode */
3118 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08003119 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00003120 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08003121 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003122 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00003123 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003124 }
Auke Kok9a799d72007-09-15 14:07:45 -07003125 return work_done;
3126}
3127
3128/**
3129 * ixgbe_tx_timeout - Respond to a Tx Hang
3130 * @netdev: network interface device structure
3131 **/
3132static void ixgbe_tx_timeout(struct net_device *netdev)
3133{
3134 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3135
3136 /* Do the reset outside of interrupt context */
3137 schedule_work(&adapter->reset_task);
3138}
3139
3140static void ixgbe_reset_task(struct work_struct *work)
3141{
3142 struct ixgbe_adapter *adapter;
3143 adapter = container_of(work, struct ixgbe_adapter, reset_task);
3144
Alexander Duyck2f90b862008-11-20 20:52:10 -08003145 /* If we're already down or resetting, just bail */
3146 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
3147 test_bit(__IXGBE_RESETTING, &adapter->state))
3148 return;
3149
Auke Kok9a799d72007-09-15 14:07:45 -07003150 adapter->tx_timeout_count++;
3151
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003152 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003153}
3154
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003155#ifdef CONFIG_IXGBE_DCB
3156static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003157{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003158 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003159 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003160
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003161 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
3162 return ret;
3163
3164 f->mask = 0x7 << 3;
3165 adapter->num_rx_queues = f->indices;
3166 adapter->num_tx_queues = f->indices;
3167 ret = true;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003168
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003169 return ret;
3170}
3171#endif
3172
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003173/**
3174 * ixgbe_set_rss_queues: Allocate queues for RSS
3175 * @adapter: board private structure to initialize
3176 *
3177 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
3178 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
3179 *
3180 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003181static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
3182{
3183 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003184 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003185
3186 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003187 f->mask = 0xF;
3188 adapter->num_rx_queues = f->indices;
3189 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003190 ret = true;
3191 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003192 ret = false;
3193 }
3194
3195 return ret;
3196}
3197
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003198/**
3199 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
3200 * @adapter: board private structure to initialize
3201 *
3202 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
3203 * to the original CPU that initiated the Tx session. This runs in addition
3204 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
3205 * Rx load across CPUs using RSS.
3206 *
3207 **/
3208static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
3209{
3210 bool ret = false;
3211 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
3212
3213 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
3214 f_fdir->mask = 0;
3215
3216 /* Flow Director must have RSS enabled */
3217 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3218 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3219 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
3220 adapter->num_tx_queues = f_fdir->indices;
3221 adapter->num_rx_queues = f_fdir->indices;
3222 ret = true;
3223 } else {
3224 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3225 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3226 }
3227 return ret;
3228}
3229
Yi Zou0331a832009-05-17 12:33:52 +00003230#ifdef IXGBE_FCOE
3231/**
3232 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
3233 * @adapter: board private structure to initialize
3234 *
3235 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
3236 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
3237 * rx queues out of the max number of rx queues, instead, it is used as the
3238 * index of the first rx queue used by FCoE.
3239 *
3240 **/
3241static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
3242{
3243 bool ret = false;
3244 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3245
3246 f->indices = min((int)num_online_cpus(), f->indices);
3247 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003248 adapter->num_rx_queues = 1;
3249 adapter->num_tx_queues = 1;
Yi Zou0331a832009-05-17 12:33:52 +00003250#ifdef CONFIG_IXGBE_DCB
3251 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003252 DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n");
Yi Zou0331a832009-05-17 12:33:52 +00003253 ixgbe_set_dcb_queues(adapter);
3254 }
3255#endif
3256 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003257 DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n");
Yi Zou8faa2a72009-07-09 02:29:50 +00003258 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3259 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
3260 ixgbe_set_fdir_queues(adapter);
3261 else
3262 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00003263 }
3264 /* adding FCoE rx rings to the end */
3265 f->mask = adapter->num_rx_queues;
3266 adapter->num_rx_queues += f->indices;
Yi Zou8de8b2e2009-09-03 14:55:50 +00003267 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00003268
3269 ret = true;
3270 }
3271
3272 return ret;
3273}
3274
3275#endif /* IXGBE_FCOE */
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003276/*
3277 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
3278 * @adapter: board private structure to initialize
3279 *
3280 * This is the top level queue allocation routine. The order here is very
3281 * important, starting with the "most" number of features turned on at once,
3282 * and ending with the smallest set of features. This way large combinations
3283 * can be allocated if they're turned on, and smaller combinations are the
3284 * fallthrough conditions.
3285 *
3286 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003287static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
3288{
Yi Zou0331a832009-05-17 12:33:52 +00003289#ifdef IXGBE_FCOE
3290 if (ixgbe_set_fcoe_queues(adapter))
3291 goto done;
3292
3293#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003294#ifdef CONFIG_IXGBE_DCB
3295 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003296 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003297
3298#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003299 if (ixgbe_set_fdir_queues(adapter))
3300 goto done;
3301
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003302 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003303 goto done;
3304
3305 /* fallback to base case */
3306 adapter->num_rx_queues = 1;
3307 adapter->num_tx_queues = 1;
3308
3309done:
3310 /* Notify the stack of the (possibly) reduced Tx Queue count. */
3311 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003312}
3313
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003314static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003315 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003316{
3317 int err, vector_threshold;
3318
3319 /* We'll want at least 3 (vector_threshold):
3320 * 1) TxQ[0] Cleanup
3321 * 2) RxQ[0] Cleanup
3322 * 3) Other (Link Status Change, etc.)
3323 * 4) TCP Timer (optional)
3324 */
3325 vector_threshold = MIN_MSIX_COUNT;
3326
3327 /* The more we get, the more we will assign to Tx/Rx Cleanup
3328 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
3329 * Right now, we simply care about how many we'll get; we'll
3330 * set them up later while requesting irq's.
3331 */
3332 while (vectors >= vector_threshold) {
3333 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003334 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003335 if (!err) /* Success in acquiring all requested vectors. */
3336 break;
3337 else if (err < 0)
3338 vectors = 0; /* Nasty failure, quit now */
3339 else /* err == number of vectors we should try again with */
3340 vectors = err;
3341 }
3342
3343 if (vectors < vector_threshold) {
3344 /* Can't allocate enough MSI-X interrupts? Oh well.
3345 * This just means we'll go with either a single MSI
3346 * vector or fall back to legacy interrupts.
3347 */
3348 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
3349 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3350 kfree(adapter->msix_entries);
3351 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003352 } else {
3353 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08003354 /*
3355 * Adjust for only the vectors we'll use, which is minimum
3356 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
3357 * vectors we were allocated.
3358 */
3359 adapter->num_msix_vectors = min(vectors,
3360 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003361 }
3362}
3363
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003364/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003365 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003366 * @adapter: board private structure to initialize
3367 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003368 * Cache the descriptor ring offsets for RSS to the assigned rings.
3369 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003370 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003371static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003372{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003373 int i;
3374 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003375
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003376 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3377 for (i = 0; i < adapter->num_rx_queues; i++)
3378 adapter->rx_ring[i].reg_idx = i;
3379 for (i = 0; i < adapter->num_tx_queues; i++)
3380 adapter->tx_ring[i].reg_idx = i;
3381 ret = true;
3382 } else {
3383 ret = false;
3384 }
3385
3386 return ret;
3387}
3388
3389#ifdef CONFIG_IXGBE_DCB
3390/**
3391 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
3392 * @adapter: board private structure to initialize
3393 *
3394 * Cache the descriptor ring offsets for DCB to the assigned rings.
3395 *
3396 **/
3397static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
3398{
3399 int i;
3400 bool ret = false;
3401 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
3402
3403 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3404 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08003405 /* the number of queues is assumed to be symmetric */
3406 for (i = 0; i < dcb_i; i++) {
3407 adapter->rx_ring[i].reg_idx = i << 3;
3408 adapter->tx_ring[i].reg_idx = i << 2;
3409 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003410 ret = true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003411 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
PJ Waskiewiczf92ef202009-04-16 15:00:20 +00003412 if (dcb_i == 8) {
3413 /*
3414 * Tx TC0 starts at: descriptor queue 0
3415 * Tx TC1 starts at: descriptor queue 32
3416 * Tx TC2 starts at: descriptor queue 64
3417 * Tx TC3 starts at: descriptor queue 80
3418 * Tx TC4 starts at: descriptor queue 96
3419 * Tx TC5 starts at: descriptor queue 104
3420 * Tx TC6 starts at: descriptor queue 112
3421 * Tx TC7 starts at: descriptor queue 120
3422 *
3423 * Rx TC0-TC7 are offset by 16 queues each
3424 */
3425 for (i = 0; i < 3; i++) {
3426 adapter->tx_ring[i].reg_idx = i << 5;
3427 adapter->rx_ring[i].reg_idx = i << 4;
3428 }
3429 for ( ; i < 5; i++) {
3430 adapter->tx_ring[i].reg_idx =
3431 ((i + 2) << 4);
3432 adapter->rx_ring[i].reg_idx = i << 4;
3433 }
3434 for ( ; i < dcb_i; i++) {
3435 adapter->tx_ring[i].reg_idx =
3436 ((i + 8) << 3);
3437 adapter->rx_ring[i].reg_idx = i << 4;
3438 }
3439
3440 ret = true;
3441 } else if (dcb_i == 4) {
3442 /*
3443 * Tx TC0 starts at: descriptor queue 0
3444 * Tx TC1 starts at: descriptor queue 64
3445 * Tx TC2 starts at: descriptor queue 96
3446 * Tx TC3 starts at: descriptor queue 112
3447 *
3448 * Rx TC0-TC3 are offset by 32 queues each
3449 */
3450 adapter->tx_ring[0].reg_idx = 0;
3451 adapter->tx_ring[1].reg_idx = 64;
3452 adapter->tx_ring[2].reg_idx = 96;
3453 adapter->tx_ring[3].reg_idx = 112;
3454 for (i = 0 ; i < dcb_i; i++)
3455 adapter->rx_ring[i].reg_idx = i << 5;
3456
3457 ret = true;
3458 } else {
3459 ret = false;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003460 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003461 } else {
3462 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003463 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003464 } else {
3465 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003466 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003467
3468 return ret;
3469}
3470#endif
3471
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003472/**
3473 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
3474 * @adapter: board private structure to initialize
3475 *
3476 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
3477 *
3478 **/
3479static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
3480{
3481 int i;
3482 bool ret = false;
3483
3484 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3485 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3486 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
3487 for (i = 0; i < adapter->num_rx_queues; i++)
3488 adapter->rx_ring[i].reg_idx = i;
3489 for (i = 0; i < adapter->num_tx_queues; i++)
3490 adapter->tx_ring[i].reg_idx = i;
3491 ret = true;
3492 }
3493
3494 return ret;
3495}
3496
Yi Zou0331a832009-05-17 12:33:52 +00003497#ifdef IXGBE_FCOE
3498/**
3499 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
3500 * @adapter: board private structure to initialize
3501 *
3502 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
3503 *
3504 */
3505static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
3506{
Yi Zou8de8b2e2009-09-03 14:55:50 +00003507 int i, fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00003508 bool ret = false;
3509 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3510
3511 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3512#ifdef CONFIG_IXGBE_DCB
3513 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003514 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
3515
Yi Zou0331a832009-05-17 12:33:52 +00003516 ixgbe_cache_ring_dcb(adapter);
Yi Zou8de8b2e2009-09-03 14:55:50 +00003517 /* find out queues in TC for FCoE */
3518 fcoe_rx_i = adapter->rx_ring[fcoe->tc].reg_idx + 1;
3519 fcoe_tx_i = adapter->tx_ring[fcoe->tc].reg_idx + 1;
3520 /*
3521 * In 82599, the number of Tx queues for each traffic
3522 * class for both 8-TC and 4-TC modes are:
3523 * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7
3524 * 8 TCs: 32 32 16 16 8 8 8 8
3525 * 4 TCs: 64 64 32 32
3526 * We have max 8 queues for FCoE, where 8 the is
3527 * FCoE redirection table size. If TC for FCoE is
3528 * less than or equal to TC3, we have enough queues
3529 * to add max of 8 queues for FCoE, so we start FCoE
3530 * tx descriptor from the next one, i.e., reg_idx + 1.
3531 * If TC for FCoE is above TC3, implying 8 TC mode,
3532 * and we need 8 for FCoE, we have to take all queues
3533 * in that traffic class for FCoE.
3534 */
3535 if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3))
3536 fcoe_tx_i--;
Yi Zou0331a832009-05-17 12:33:52 +00003537 }
3538#endif /* CONFIG_IXGBE_DCB */
3539 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Yi Zou8faa2a72009-07-09 02:29:50 +00003540 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3541 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
3542 ixgbe_cache_ring_fdir(adapter);
3543 else
3544 ixgbe_cache_ring_rss(adapter);
3545
Yi Zou8de8b2e2009-09-03 14:55:50 +00003546 fcoe_rx_i = f->mask;
3547 fcoe_tx_i = f->mask;
Yi Zou0331a832009-05-17 12:33:52 +00003548 }
Yi Zou8de8b2e2009-09-03 14:55:50 +00003549 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
3550 adapter->rx_ring[f->mask + i].reg_idx = fcoe_rx_i;
3551 adapter->tx_ring[f->mask + i].reg_idx = fcoe_tx_i;
3552 }
Yi Zou0331a832009-05-17 12:33:52 +00003553 ret = true;
3554 }
3555 return ret;
3556}
3557
3558#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003559/**
3560 * ixgbe_cache_ring_register - Descriptor ring to register mapping
3561 * @adapter: board private structure to initialize
3562 *
3563 * Once we know the feature-set enabled for the device, we'll cache
3564 * the register offset the descriptor ring is assigned to.
3565 *
3566 * Note, the order the various feature calls is important. It must start with
3567 * the "most" features enabled at the same time, then trickle down to the
3568 * least amount of features turned on at once.
3569 **/
3570static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
3571{
3572 /* start with default case */
3573 adapter->rx_ring[0].reg_idx = 0;
3574 adapter->tx_ring[0].reg_idx = 0;
3575
Yi Zou0331a832009-05-17 12:33:52 +00003576#ifdef IXGBE_FCOE
3577 if (ixgbe_cache_ring_fcoe(adapter))
3578 return;
3579
3580#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003581#ifdef CONFIG_IXGBE_DCB
3582 if (ixgbe_cache_ring_dcb(adapter))
3583 return;
3584
3585#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003586 if (ixgbe_cache_ring_fdir(adapter))
3587 return;
3588
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003589 if (ixgbe_cache_ring_rss(adapter))
3590 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003591}
3592
Auke Kok9a799d72007-09-15 14:07:45 -07003593/**
3594 * ixgbe_alloc_queues - Allocate memory for all rings
3595 * @adapter: board private structure to initialize
3596 *
3597 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003598 * number of queues at compile-time. The polling_netdev array is
3599 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07003600 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003601static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003602{
3603 int i;
3604
3605 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003606 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07003607 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003608 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07003609
3610 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003611 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003612 if (!adapter->rx_ring)
3613 goto err_rx_ring_allocation;
3614
3615 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003616 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003617 adapter->tx_ring[i].queue_index = i;
3618 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003619
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003620 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003621 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003622 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07003623 }
3624
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003625 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003626
3627 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003628
3629err_rx_ring_allocation:
3630 kfree(adapter->tx_ring);
3631err_tx_ring_allocation:
3632 return -ENOMEM;
3633}
3634
3635/**
3636 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3637 * @adapter: board private structure to initialize
3638 *
3639 * Attempt to configure the interrupts using the best available
3640 * capabilities of the hardware and the kernel.
3641 **/
Al Virofeea6a52008-11-27 15:34:07 -08003642static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003643{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003644 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003645 int err = 0;
3646 int vector, v_budget;
3647
3648 /*
3649 * It's easy to be greedy for MSI-X vectors, but it really
3650 * doesn't do us much good if we have a lot more vectors
3651 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00003652 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003653 */
3654 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
PJ Waskiewicz342bde12009-11-12 23:50:43 +00003655 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003656
3657 /*
3658 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003659 * hw.mac->max_msix_vectors vectors. With features
3660 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3661 * descriptor queues supported by our device. Thus, we cap it off in
3662 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003663 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003664 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003665
3666 /* A failure in MSI-X entry allocation isn't fatal, but it does
3667 * mean we disable MSI-X capabilities of the adapter. */
3668 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003669 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003670 if (adapter->msix_entries) {
3671 for (vector = 0; vector < v_budget; vector++)
3672 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003673
Alexander Duyck7a921c92009-05-06 10:43:28 +00003674 ixgbe_acquire_msix_vectors(adapter, v_budget);
3675
3676 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3677 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003678 }
3679
Alexander Duyck7a921c92009-05-06 10:43:28 +00003680 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
3681 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003682 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3683 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3684 adapter->atr_sample_rate = 0;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003685 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003686
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003687 err = pci_enable_msi(adapter->pdev);
3688 if (!err) {
3689 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
3690 } else {
3691 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003692 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003693 /* reset err */
3694 err = 0;
3695 }
3696
3697out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003698 return err;
3699}
3700
Alexander Duyck7a921c92009-05-06 10:43:28 +00003701/**
3702 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
3703 * @adapter: board private structure to initialize
3704 *
3705 * We allocate one q_vector per queue interrupt. If allocation fails we
3706 * return -ENOMEM.
3707 **/
3708static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
3709{
3710 int q_idx, num_q_vectors;
3711 struct ixgbe_q_vector *q_vector;
3712 int napi_vectors;
3713 int (*poll)(struct napi_struct *, int);
3714
3715 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3716 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3717 napi_vectors = adapter->num_rx_queues;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003718 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003719 } else {
3720 num_q_vectors = 1;
3721 napi_vectors = 1;
3722 poll = &ixgbe_poll;
3723 }
3724
3725 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3726 q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL);
3727 if (!q_vector)
3728 goto err_out;
3729 q_vector->adapter = adapter;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00003730 if (q_vector->txr_count && !q_vector->rxr_count)
3731 q_vector->eitr = adapter->tx_eitr_param;
3732 else
3733 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00003734 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003735 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003736 adapter->q_vector[q_idx] = q_vector;
3737 }
3738
3739 return 0;
3740
3741err_out:
3742 while (q_idx) {
3743 q_idx--;
3744 q_vector = adapter->q_vector[q_idx];
3745 netif_napi_del(&q_vector->napi);
3746 kfree(q_vector);
3747 adapter->q_vector[q_idx] = NULL;
3748 }
3749 return -ENOMEM;
3750}
3751
3752/**
3753 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
3754 * @adapter: board private structure to initialize
3755 *
3756 * This function frees the memory allocated to the q_vectors. In addition if
3757 * NAPI is enabled it will delete any references to the NAPI struct prior
3758 * to freeing the q_vector.
3759 **/
3760static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
3761{
3762 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003763
Alexander Duyck91281fd2009-06-04 16:00:27 +00003764 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00003765 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003766 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00003767 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003768
3769 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3770 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00003771 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003772 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003773 kfree(q_vector);
3774 }
3775}
3776
Don Skidmore7b25cdb2009-08-25 04:47:32 +00003777static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003778{
3779 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3780 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3781 pci_disable_msix(adapter->pdev);
3782 kfree(adapter->msix_entries);
3783 adapter->msix_entries = NULL;
3784 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
3785 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
3786 pci_disable_msi(adapter->pdev);
3787 }
3788 return;
3789}
3790
3791/**
3792 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3793 * @adapter: board private structure to initialize
3794 *
3795 * We determine which interrupt scheme to use based on...
3796 * - Kernel support (MSI, MSI-X)
3797 * - which can be user-defined (via MODULE_PARAM)
3798 * - Hardware queue count (num_*_queues)
3799 * - defined by miscellaneous hardware support/features (RSS, etc.)
3800 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003801int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003802{
3803 int err;
3804
3805 /* Number of supported queues */
3806 ixgbe_set_num_queues(adapter);
3807
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003808 err = ixgbe_set_interrupt_capability(adapter);
3809 if (err) {
3810 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3811 goto err_set_interrupt;
3812 }
3813
Alexander Duyck7a921c92009-05-06 10:43:28 +00003814 err = ixgbe_alloc_q_vectors(adapter);
3815 if (err) {
3816 DPRINTK(PROBE, ERR, "Unable to allocate memory for queue "
3817 "vectors\n");
3818 goto err_alloc_q_vectors;
3819 }
3820
3821 err = ixgbe_alloc_queues(adapter);
3822 if (err) {
3823 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3824 goto err_alloc_queues;
3825 }
3826
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003827 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003828 "Tx Queue count = %u\n",
3829 (adapter->num_rx_queues > 1) ? "Enabled" :
3830 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003831
3832 set_bit(__IXGBE_DOWN, &adapter->state);
3833
3834 return 0;
3835
Alexander Duyck7a921c92009-05-06 10:43:28 +00003836err_alloc_queues:
3837 ixgbe_free_q_vectors(adapter);
3838err_alloc_q_vectors:
3839 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003840err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00003841 return err;
3842}
3843
3844/**
3845 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
3846 * @adapter: board private structure to clear interrupt scheme on
3847 *
3848 * We go through and clear interrupt specific resources and reset the structure
3849 * to pre-load conditions
3850 **/
3851void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
3852{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003853 kfree(adapter->tx_ring);
3854 kfree(adapter->rx_ring);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003855 adapter->tx_ring = NULL;
3856 adapter->rx_ring = NULL;
3857
3858 ixgbe_free_q_vectors(adapter);
3859 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003860}
3861
3862/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08003863 * ixgbe_sfp_timer - worker thread to find a missing module
3864 * @data: pointer to our adapter struct
3865 **/
3866static void ixgbe_sfp_timer(unsigned long data)
3867{
3868 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3869
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003870 /*
3871 * Do the sfp_timer outside of interrupt context due to the
Donald Skidmorec4900be2008-11-20 21:11:42 -08003872 * delays that sfp+ detection requires
3873 */
3874 schedule_work(&adapter->sfp_task);
3875}
3876
3877/**
3878 * ixgbe_sfp_task - worker thread to find a missing module
3879 * @work: pointer to work_struct containing our data
3880 **/
3881static void ixgbe_sfp_task(struct work_struct *work)
3882{
3883 struct ixgbe_adapter *adapter = container_of(work,
3884 struct ixgbe_adapter,
3885 sfp_task);
3886 struct ixgbe_hw *hw = &adapter->hw;
3887
3888 if ((hw->phy.type == ixgbe_phy_nl) &&
3889 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3890 s32 ret = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00003891 if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
Donald Skidmorec4900be2008-11-20 21:11:42 -08003892 goto reschedule;
3893 ret = hw->phy.ops.reset(hw);
3894 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00003895 dev_err(&adapter->pdev->dev, "failed to initialize "
3896 "because an unsupported SFP+ module type "
3897 "was detected.\n"
3898 "Reload the driver after installing a "
3899 "supported module.\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08003900 unregister_netdev(adapter->netdev);
3901 } else {
3902 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3903 hw->phy.sfp_type);
3904 }
3905 /* don't need this routine any more */
3906 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3907 }
3908 return;
3909reschedule:
3910 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3911 mod_timer(&adapter->sfp_timer,
3912 round_jiffies(jiffies + (2 * HZ)));
3913}
3914
3915/**
Auke Kok9a799d72007-09-15 14:07:45 -07003916 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3917 * @adapter: board private structure to initialize
3918 *
3919 * ixgbe_sw_init initializes the Adapter private data structure.
3920 * Fields are initialized based on PCI device information and
3921 * OS network device settings (MTU size).
3922 **/
3923static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3924{
3925 struct ixgbe_hw *hw = &adapter->hw;
3926 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003927 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003928#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003929 int j;
3930 struct tc_configuration *tc;
3931#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003932
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003933 /* PCI config space info */
3934
3935 hw->vendor_id = pdev->vendor;
3936 hw->device_id = pdev->device;
3937 hw->revision_id = pdev->revision;
3938 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3939 hw->subsystem_device_id = pdev->subsystem_device;
3940
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003941 /* Set capability flags */
3942 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3943 adapter->ring_feature[RING_F_RSS].indices = rss;
3944 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003945 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Don Skidmorebf069c92009-05-07 10:39:54 +00003946 if (hw->mac.type == ixgbe_mac_82598EB) {
3947 if (hw->device_id == IXGBE_DEV_ID_82598AT)
3948 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003949 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Don Skidmorebf069c92009-05-07 10:39:54 +00003950 } else if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003951 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003952 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
3953 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003954 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
3955 adapter->ring_feature[RING_F_FDIR].indices =
3956 IXGBE_MAX_FDIR_INDICES;
3957 adapter->atr_sample_rate = 20;
3958 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00003959#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00003960 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
3961 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
3962 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00003963#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00003964 /* Default traffic class to use for FCoE */
3965 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00003966#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00003967#endif /* IXGBE_FCOE */
Alexander Duyckf8212f92009-04-27 22:42:37 +00003968 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003969
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003970#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003971 /* Configure DCB traffic classes */
3972 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3973 tc = &adapter->dcb_cfg.tc_config[j];
3974 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3975 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3976 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3977 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3978 tc->dcb_pfc = pfc_disabled;
3979 }
3980 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3981 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3982 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003983 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003984 adapter->dcb_cfg.round_robin_enable = false;
3985 adapter->dcb_set_bitmap = 0x00;
3986 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3987 adapter->ring_feature[RING_F_DCB].indices);
3988
3989#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003990
3991 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00003992 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00003993 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003994#ifdef CONFIG_DCB
3995 adapter->last_lfc_mode = hw->fc.current_mode;
3996#endif
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07003997 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3998 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3999 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4000 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00004001 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07004002
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004003 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004004 adapter->rx_itr_setting = 1;
4005 adapter->rx_eitr_param = 20000;
4006 adapter->tx_itr_setting = 1;
4007 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004008
4009 /* set defaults for eitr in MegaBytes */
4010 adapter->eitr_low = 10;
4011 adapter->eitr_high = 20;
4012
4013 /* set default ring sizes */
4014 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4015 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4016
Auke Kok9a799d72007-09-15 14:07:45 -07004017 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004018 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004019 dev_err(&pdev->dev, "EEPROM initialization failed\n");
4020 return -EIO;
4021 }
4022
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004023 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07004024 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
4025
Auke Kok9a799d72007-09-15 14:07:45 -07004026 set_bit(__IXGBE_DOWN, &adapter->state);
4027
4028 return 0;
4029}
4030
4031/**
4032 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
4033 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004034 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004035 *
4036 * Return 0 on success, negative on failure
4037 **/
4038int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004039 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004040{
4041 struct pci_dev *pdev = adapter->pdev;
4042 int size;
4043
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004044 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4045 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004046 if (!tx_ring->tx_buffer_info)
4047 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004048 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07004049
4050 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004051 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004052 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004053
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004054 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
4055 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004056 if (!tx_ring->desc)
4057 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004058
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004059 tx_ring->next_to_use = 0;
4060 tx_ring->next_to_clean = 0;
4061 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07004062 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004063
4064err:
4065 vfree(tx_ring->tx_buffer_info);
4066 tx_ring->tx_buffer_info = NULL;
4067 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
4068 "descriptor ring\n");
4069 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004070}
4071
4072/**
Alexander Duyck69888672008-09-11 20:05:39 -07004073 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4074 * @adapter: board private structure
4075 *
4076 * If this function returns with an error, then it's possible one or
4077 * more of the rings is populated (while the rest are not). It is the
4078 * callers duty to clean those orphaned rings.
4079 *
4080 * Return 0 on success, negative on failure
4081 **/
4082static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4083{
4084 int i, err = 0;
4085
4086 for (i = 0; i < adapter->num_tx_queues; i++) {
4087 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
4088 if (!err)
4089 continue;
4090 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
4091 break;
4092 }
4093
4094 return err;
4095}
4096
4097/**
Auke Kok9a799d72007-09-15 14:07:45 -07004098 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
4099 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004100 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004101 *
4102 * Returns 0 on success, negative on failure
4103 **/
4104int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004105 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004106{
4107 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004108 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004109
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004110 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4111 rx_ring->rx_buffer_info = vmalloc(size);
4112 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07004113 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004114 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004115 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07004116 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004117 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07004118
Auke Kok9a799d72007-09-15 14:07:45 -07004119 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004120 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4121 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004122
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004123 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004124
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004125 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07004126 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004127 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004128 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004129 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07004130 }
4131
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004132 rx_ring->next_to_clean = 0;
4133 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004134
4135 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004136
4137alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004138 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004139}
4140
4141/**
Alexander Duyck69888672008-09-11 20:05:39 -07004142 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4143 * @adapter: board private structure
4144 *
4145 * If this function returns with an error, then it's possible one or
4146 * more of the rings is populated (while the rest are not). It is the
4147 * callers duty to clean those orphaned rings.
4148 *
4149 * Return 0 on success, negative on failure
4150 **/
4151
4152static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4153{
4154 int i, err = 0;
4155
4156 for (i = 0; i < adapter->num_rx_queues; i++) {
4157 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
4158 if (!err)
4159 continue;
4160 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
4161 break;
4162 }
4163
4164 return err;
4165}
4166
4167/**
Auke Kok9a799d72007-09-15 14:07:45 -07004168 * ixgbe_free_tx_resources - Free Tx Resources per Queue
4169 * @adapter: board private structure
4170 * @tx_ring: Tx descriptor ring for a specific queue
4171 *
4172 * Free all transmit software resources
4173 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07004174void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
4175 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004176{
4177 struct pci_dev *pdev = adapter->pdev;
4178
4179 ixgbe_clean_tx_ring(adapter, tx_ring);
4180
4181 vfree(tx_ring->tx_buffer_info);
4182 tx_ring->tx_buffer_info = NULL;
4183
4184 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
4185
4186 tx_ring->desc = NULL;
4187}
4188
4189/**
4190 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4191 * @adapter: board private structure
4192 *
4193 * Free all transmit software resources
4194 **/
4195static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4196{
4197 int i;
4198
4199 for (i = 0; i < adapter->num_tx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004200 if (adapter->tx_ring[i].desc)
4201 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004202}
4203
4204/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004205 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004206 * @adapter: board private structure
4207 * @rx_ring: ring to clean the resources from
4208 *
4209 * Free all receive software resources
4210 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07004211void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
4212 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004213{
4214 struct pci_dev *pdev = adapter->pdev;
4215
4216 ixgbe_clean_rx_ring(adapter, rx_ring);
4217
4218 vfree(rx_ring->rx_buffer_info);
4219 rx_ring->rx_buffer_info = NULL;
4220
4221 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
4222
4223 rx_ring->desc = NULL;
4224}
4225
4226/**
4227 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4228 * @adapter: board private structure
4229 *
4230 * Free all receive software resources
4231 **/
4232static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4233{
4234 int i;
4235
4236 for (i = 0; i < adapter->num_rx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004237 if (adapter->rx_ring[i].desc)
4238 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004239}
4240
4241/**
Auke Kok9a799d72007-09-15 14:07:45 -07004242 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4243 * @netdev: network interface device structure
4244 * @new_mtu: new value for maximum frame size
4245 *
4246 * Returns 0 on success, negative on failure
4247 **/
4248static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4249{
4250 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4251 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4252
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004253 /* MTU < 68 is an error and causes problems on some kernels */
4254 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07004255 return -EINVAL;
4256
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004257 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004258 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004259 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004260 netdev->mtu = new_mtu;
4261
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004262 if (netif_running(netdev))
4263 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004264
4265 return 0;
4266}
4267
4268/**
4269 * ixgbe_open - Called when a network interface is made active
4270 * @netdev: network interface device structure
4271 *
4272 * Returns 0 on success, negative value on failure
4273 *
4274 * The open entry point is called when a network interface is made
4275 * active by the system (IFF_UP). At this point all resources needed
4276 * for transmit and receive operations are allocated, the interrupt
4277 * handler is registered with the OS, the watchdog timer is started,
4278 * and the stack is notified that the interface is ready.
4279 **/
4280static int ixgbe_open(struct net_device *netdev)
4281{
4282 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4283 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004284
Auke Kok4bebfaa2008-02-11 09:26:01 -08004285 /* disallow open during test */
4286 if (test_bit(__IXGBE_TESTING, &adapter->state))
4287 return -EBUSY;
4288
Jesse Brandeburg54386462009-04-17 20:44:27 +00004289 netif_carrier_off(netdev);
4290
Auke Kok9a799d72007-09-15 14:07:45 -07004291 /* allocate transmit descriptors */
4292 err = ixgbe_setup_all_tx_resources(adapter);
4293 if (err)
4294 goto err_setup_tx;
4295
Auke Kok9a799d72007-09-15 14:07:45 -07004296 /* allocate receive descriptors */
4297 err = ixgbe_setup_all_rx_resources(adapter);
4298 if (err)
4299 goto err_setup_rx;
4300
4301 ixgbe_configure(adapter);
4302
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004303 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004304 if (err)
4305 goto err_req_irq;
4306
Auke Kok9a799d72007-09-15 14:07:45 -07004307 err = ixgbe_up_complete(adapter);
4308 if (err)
4309 goto err_up;
4310
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004311 netif_tx_start_all_queues(netdev);
4312
Auke Kok9a799d72007-09-15 14:07:45 -07004313 return 0;
4314
4315err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004316 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004317 ixgbe_free_irq(adapter);
4318err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07004319err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004320 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004321err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004322 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004323 ixgbe_reset(adapter);
4324
4325 return err;
4326}
4327
4328/**
4329 * ixgbe_close - Disables a network interface
4330 * @netdev: network interface device structure
4331 *
4332 * Returns 0, this is not allowed to fail
4333 *
4334 * The close entry point is called when an interface is de-activated
4335 * by the OS. The hardware is still under the drivers control, but
4336 * needs to be disabled. A global MAC reset is issued to stop the
4337 * hardware, and all transmit and receive resources are freed.
4338 **/
4339static int ixgbe_close(struct net_device *netdev)
4340{
4341 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004342
4343 ixgbe_down(adapter);
4344 ixgbe_free_irq(adapter);
4345
4346 ixgbe_free_all_tx_resources(adapter);
4347 ixgbe_free_all_rx_resources(adapter);
4348
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004349 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004350
4351 return 0;
4352}
4353
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004354#ifdef CONFIG_PM
4355static int ixgbe_resume(struct pci_dev *pdev)
4356{
4357 struct net_device *netdev = pci_get_drvdata(pdev);
4358 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4359 u32 err;
4360
4361 pci_set_power_state(pdev, PCI_D0);
4362 pci_restore_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004363
4364 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004365 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07004366 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004367 "suspend\n");
4368 return err;
4369 }
4370 pci_set_master(pdev);
4371
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004372 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004373
4374 err = ixgbe_init_interrupt_scheme(adapter);
4375 if (err) {
4376 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
4377 "device\n");
4378 return err;
4379 }
4380
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004381 ixgbe_reset(adapter);
4382
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00004383 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4384
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004385 if (netif_running(netdev)) {
4386 err = ixgbe_open(adapter->netdev);
4387 if (err)
4388 return err;
4389 }
4390
4391 netif_device_attach(netdev);
4392
4393 return 0;
4394}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004395#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004396
4397static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004398{
4399 struct net_device *netdev = pci_get_drvdata(pdev);
4400 struct ixgbe_adapter *adapter = netdev_priv(netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004401 struct ixgbe_hw *hw = &adapter->hw;
4402 u32 ctrl, fctrl;
4403 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004404#ifdef CONFIG_PM
4405 int retval = 0;
4406#endif
4407
4408 netif_device_detach(netdev);
4409
4410 if (netif_running(netdev)) {
4411 ixgbe_down(adapter);
4412 ixgbe_free_irq(adapter);
4413 ixgbe_free_all_tx_resources(adapter);
4414 ixgbe_free_all_rx_resources(adapter);
4415 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00004416 ixgbe_clear_interrupt_scheme(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004417
4418#ifdef CONFIG_PM
4419 retval = pci_save_state(pdev);
4420 if (retval)
4421 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004422
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004423#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004424 if (wufc) {
4425 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004426
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004427 /* turn on all-multi mode if wake on multicast is enabled */
4428 if (wufc & IXGBE_WUFC_MC) {
4429 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4430 fctrl |= IXGBE_FCTRL_MPE;
4431 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4432 }
4433
4434 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4435 ctrl |= IXGBE_CTRL_GIO_DIS;
4436 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4437
4438 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4439 } else {
4440 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4441 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4442 }
4443
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004444 if (wufc && hw->mac.type == ixgbe_mac_82599EB)
4445 pci_wake_from_d3(pdev, true);
4446 else
4447 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004448
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004449 *enable_wake = !!wufc;
4450
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004451 ixgbe_release_hw_control(adapter);
4452
4453 pci_disable_device(pdev);
4454
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004455 return 0;
4456}
4457
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004458#ifdef CONFIG_PM
4459static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4460{
4461 int retval;
4462 bool wake;
4463
4464 retval = __ixgbe_shutdown(pdev, &wake);
4465 if (retval)
4466 return retval;
4467
4468 if (wake) {
4469 pci_prepare_to_sleep(pdev);
4470 } else {
4471 pci_wake_from_d3(pdev, false);
4472 pci_set_power_state(pdev, PCI_D3hot);
4473 }
4474
4475 return 0;
4476}
4477#endif /* CONFIG_PM */
4478
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004479static void ixgbe_shutdown(struct pci_dev *pdev)
4480{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004481 bool wake;
4482
4483 __ixgbe_shutdown(pdev, &wake);
4484
4485 if (system_state == SYSTEM_POWER_OFF) {
4486 pci_wake_from_d3(pdev, wake);
4487 pci_set_power_state(pdev, PCI_D3hot);
4488 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004489}
4490
4491/**
Auke Kok9a799d72007-09-15 14:07:45 -07004492 * ixgbe_update_stats - Update the board statistics counters.
4493 * @adapter: board private structure
4494 **/
4495void ixgbe_update_stats(struct ixgbe_adapter *adapter)
4496{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004497 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07004498 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004499 u64 total_mpc = 0;
4500 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004501
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004502 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004503 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004504 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004505 for (i = 0; i < 16; i++)
4506 adapter->hw_rx_no_dma_resources +=
4507 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004508 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004509 rsc_count += adapter->rx_ring[i].rsc_count;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004510 rsc_flush += adapter->rx_ring[i].rsc_flush;
4511 }
4512 adapter->rsc_total_count = rsc_count;
4513 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004514 }
4515
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00004516 /* gather some stats to the adapter struct that are per queue */
4517 for (i = 0; i < adapter->num_tx_queues; i++)
4518 adapter->restart_queue += adapter->tx_ring[i].restart_queue;
4519
4520 for (i = 0; i < adapter->num_rx_queues; i++)
4521 adapter->non_eop_descs += adapter->tx_ring[i].non_eop_descs;
4522
Auke Kok9a799d72007-09-15 14:07:45 -07004523 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004524 for (i = 0; i < 8; i++) {
4525 /* for packet buffers not used, the register should read 0 */
4526 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
4527 missed_rx += mpc;
4528 adapter->stats.mpc[i] += mpc;
4529 total_mpc += adapter->stats.mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004530 if (hw->mac.type == ixgbe_mac_82598EB)
4531 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004532 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
4533 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
4534 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
4535 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004536 if (hw->mac.type == ixgbe_mac_82599EB) {
4537 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4538 IXGBE_PXONRXCNT(i));
4539 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4540 IXGBE_PXOFFRXCNT(i));
4541 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004542 } else {
4543 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4544 IXGBE_PXONRXC(i));
4545 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4546 IXGBE_PXOFFRXC(i));
4547 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004548 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
4549 IXGBE_PXONTXC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004550 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004551 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004552 }
4553 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
4554 /* work around hardware counting issue */
4555 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07004556
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004557 /* 82598 hardware only has a 32 bit counter in the high register */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004558 if (hw->mac.type == ixgbe_mac_82599EB) {
Ben Greearaad71912009-09-30 12:08:16 +00004559 u64 tmp;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004560 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Ben Greearaad71912009-09-30 12:08:16 +00004561 tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */
4562 adapter->stats.gorc += (tmp << 32);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004563 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Ben Greearaad71912009-09-30 12:08:16 +00004564 tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */
4565 adapter->stats.gotc += (tmp << 32);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004566 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
4567 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
4568 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
4569 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004570 adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
4571 adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00004572#ifdef IXGBE_FCOE
4573 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
4574 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
4575 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
4576 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
4577 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
4578 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
4579#endif /* IXGBE_FCOE */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004580 } else {
4581 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
4582 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
4583 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
4584 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
4585 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
4586 }
Auke Kok9a799d72007-09-15 14:07:45 -07004587 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
4588 adapter->stats.bprc += bprc;
4589 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004590 if (hw->mac.type == ixgbe_mac_82598EB)
4591 adapter->stats.mprc -= bprc;
Auke Kok9a799d72007-09-15 14:07:45 -07004592 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
4593 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
4594 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
4595 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
4596 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
4597 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
4598 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004599 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004600 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
4601 adapter->stats.lxontxc += lxon;
4602 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
4603 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07004604 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4605 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004606 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
4607 /*
4608 * 82598 errata - tx of flow control packets is included in tx counters
4609 */
4610 xon_off_tot = lxon + lxoff;
4611 adapter->stats.gptc -= xon_off_tot;
4612 adapter->stats.mptc -= xon_off_tot;
4613 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07004614 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4615 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
4616 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07004617 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
4618 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004619 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004620 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
4621 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
4622 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
4623 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
4624 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004625 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
4626
4627 /* Fill out the OS statistics structure */
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004628 netdev->stats.multicast = adapter->stats.mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07004629
4630 /* Rx Errors */
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004631 netdev->stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004632 adapter->stats.rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004633 netdev->stats.rx_dropped = 0;
4634 netdev->stats.rx_length_errors = adapter->stats.rlec;
4635 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4636 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07004637}
4638
4639/**
4640 * ixgbe_watchdog - Timer Call-back
4641 * @data: pointer to adapter cast into an unsigned long
4642 **/
4643static void ixgbe_watchdog(unsigned long data)
4644{
4645 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004646 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004647 u64 eics = 0;
4648 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004649
Alexander Duyckfe49f042009-06-04 16:00:09 +00004650 /*
4651 * Do the watchdog outside of interrupt context due to the lovely
4652 * delays that some of the newer hardware requires
4653 */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004654
Alexander Duyckfe49f042009-06-04 16:00:09 +00004655 if (test_bit(__IXGBE_DOWN, &adapter->state))
4656 goto watchdog_short_circuit;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004657
Alexander Duyckfe49f042009-06-04 16:00:09 +00004658 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
4659 /*
4660 * for legacy and MSI interrupts don't set any bits
4661 * that are enabled for EIAM, because this operation
4662 * would set *both* EIMS and EICS for any bit in EIAM
4663 */
4664 IXGBE_WRITE_REG(hw, IXGBE_EICS,
4665 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
4666 goto watchdog_reschedule;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004667 }
4668
Alexander Duyckfe49f042009-06-04 16:00:09 +00004669 /* get one bit for every active tx/rx interrupt vector */
4670 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
4671 struct ixgbe_q_vector *qv = adapter->q_vector[i];
4672 if (qv->rxr_count || qv->txr_count)
4673 eics |= ((u64)1 << i);
4674 }
4675
4676 /* Cause software interrupt to ensure rx rings are cleaned */
4677 ixgbe_irq_rearm_queues(adapter, eics);
4678
4679watchdog_reschedule:
4680 /* Reset the timer */
4681 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
4682
4683watchdog_short_circuit:
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004684 schedule_work(&adapter->watchdog_task);
4685}
4686
4687/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004688 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
4689 * @work: pointer to work_struct containing our data
4690 **/
4691static void ixgbe_multispeed_fiber_task(struct work_struct *work)
4692{
4693 struct ixgbe_adapter *adapter = container_of(work,
4694 struct ixgbe_adapter,
4695 multispeed_fiber_task);
4696 struct ixgbe_hw *hw = &adapter->hw;
4697 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004698 bool negotiation;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004699
4700 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
Mallikarjuna R Chilakalaa1f25322009-06-30 11:44:36 +00004701 autoneg = hw->phy.autoneg_advertised;
4702 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004703 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
4704 if (hw->mac.ops.setup_link)
4705 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004706 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4707 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
4708}
4709
4710/**
4711 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
4712 * @work: pointer to work_struct containing our data
4713 **/
4714static void ixgbe_sfp_config_module_task(struct work_struct *work)
4715{
4716 struct ixgbe_adapter *adapter = container_of(work,
4717 struct ixgbe_adapter,
4718 sfp_config_module_task);
4719 struct ixgbe_hw *hw = &adapter->hw;
4720 u32 err;
4721
4722 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004723
4724 /* Time for electrical oscillations to settle down */
4725 msleep(100);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004726 err = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004727
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004728 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00004729 dev_err(&adapter->pdev->dev, "failed to initialize because "
4730 "an unsupported SFP+ module type was detected.\n"
4731 "Reload the driver after installing a supported "
4732 "module.\n");
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004733 unregister_netdev(adapter->netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004734 return;
4735 }
4736 hw->mac.ops.setup_sfp(hw);
4737
Tony Breeds8d1c3c02009-04-09 22:29:10 +00004738 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004739 /* This will also work for DA Twinax connections */
4740 schedule_work(&adapter->multispeed_fiber_task);
4741 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
4742}
4743
4744/**
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004745 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
4746 * @work: pointer to work_struct containing our data
4747 **/
4748static void ixgbe_fdir_reinit_task(struct work_struct *work)
4749{
4750 struct ixgbe_adapter *adapter = container_of(work,
4751 struct ixgbe_adapter,
4752 fdir_reinit_task);
4753 struct ixgbe_hw *hw = &adapter->hw;
4754 int i;
4755
4756 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
4757 for (i = 0; i < adapter->num_tx_queues; i++)
4758 set_bit(__IXGBE_FDIR_INIT_DONE,
4759 &(adapter->tx_ring[i].reinit_state));
4760 } else {
4761 DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, "
4762 "ignored adding FDIR ATR filters \n");
4763 }
4764 /* Done FDIR Re-initialization, enable transmits */
4765 netif_tx_start_all_queues(adapter->netdev);
4766}
4767
4768/**
Alexander Duyck69888672008-09-11 20:05:39 -07004769 * ixgbe_watchdog_task - worker thread to bring link up
4770 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004771 **/
4772static void ixgbe_watchdog_task(struct work_struct *work)
4773{
4774 struct ixgbe_adapter *adapter = container_of(work,
4775 struct ixgbe_adapter,
4776 watchdog_task);
4777 struct net_device *netdev = adapter->netdev;
4778 struct ixgbe_hw *hw = &adapter->hw;
4779 u32 link_speed = adapter->link_speed;
4780 bool link_up = adapter->link_up;
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004781 int i;
4782 struct ixgbe_ring *tx_ring;
4783 int some_tx_pending = 0;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004784
4785 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
4786
4787 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4788 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004789 if (link_up) {
4790#ifdef CONFIG_DCB
4791 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4792 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004793 hw->mac.ops.fc_enable(hw, i);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004794 } else {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004795 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004796 }
4797#else
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004798 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004799#endif
4800 }
4801
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004802 if (link_up ||
4803 time_after(jiffies, (adapter->link_check_timeout +
4804 IXGBE_TRY_LINK_TIMEOUT))) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004805 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004806 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004807 }
4808 adapter->link_up = link_up;
4809 adapter->link_speed = link_speed;
4810 }
Auke Kok9a799d72007-09-15 14:07:45 -07004811
4812 if (link_up) {
4813 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004814 bool flow_rx, flow_tx;
4815
4816 if (hw->mac.type == ixgbe_mac_82599EB) {
4817 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4818 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
Peter P Waskiewicz Jr078788b2009-07-16 15:50:32 +00004819 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
4820 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004821 } else {
4822 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4823 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
Peter P Waskiewicz Jr078788b2009-07-16 15:50:32 +00004824 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
4825 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004826 }
4827
Jeff Kirshera46e5342008-11-27 00:22:21 -08004828 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
4829 "Flow Control: %s\n",
4830 netdev->name,
4831 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
4832 "10 Gbps" :
4833 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
4834 "1 Gbps" : "unknown speed")),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004835 ((flow_rx && flow_tx) ? "RX/TX" :
4836 (flow_rx ? "RX" :
4837 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07004838
4839 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004840 } else {
4841 /* Force detection of hung controller */
4842 adapter->detect_tx_hung = true;
4843 }
4844 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004845 adapter->link_up = false;
4846 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004847 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08004848 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
4849 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07004850 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004851 }
4852 }
4853
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004854 if (!netif_carrier_ok(netdev)) {
4855 for (i = 0; i < adapter->num_tx_queues; i++) {
4856 tx_ring = &adapter->tx_ring[i];
4857 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
4858 some_tx_pending = 1;
4859 break;
4860 }
4861 }
4862
4863 if (some_tx_pending) {
4864 /* We've lost link, so the controller stops DMA,
4865 * but we've got queued Tx work that's never going
4866 * to get done, so reset controller to flush Tx.
4867 * (Do the reset outside of interrupt context).
4868 */
4869 schedule_work(&adapter->reset_task);
4870 }
4871 }
4872
Auke Kok9a799d72007-09-15 14:07:45 -07004873 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004874 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07004875}
4876
Auke Kok9a799d72007-09-15 14:07:45 -07004877static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004878 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
4879 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004880{
4881 struct ixgbe_adv_tx_context_desc *context_desc;
4882 unsigned int i;
4883 int err;
4884 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004885 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
4886 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07004887
4888 if (skb_is_gso(skb)) {
4889 if (skb_header_cloned(skb)) {
4890 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4891 if (err)
4892 return err;
4893 }
4894 l4len = tcp_hdrlen(skb);
4895 *hdr_len += l4len;
4896
Al Viro8327d002007-12-10 18:54:12 +00004897 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004898 struct iphdr *iph = ip_hdr(skb);
4899 iph->tot_len = 0;
4900 iph->check = 0;
4901 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004902 iph->daddr, 0,
4903 IPPROTO_TCP,
4904 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004905 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
4906 ipv6_hdr(skb)->payload_len = 0;
4907 tcp_hdr(skb)->check =
4908 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004909 &ipv6_hdr(skb)->daddr,
4910 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004911 }
4912
4913 i = tx_ring->next_to_use;
4914
4915 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4916 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4917
4918 /* VLAN MACLEN IPLEN */
4919 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4920 vlan_macip_lens |=
4921 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4922 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004923 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004924 *hdr_len += skb_network_offset(skb);
4925 vlan_macip_lens |=
4926 (skb_transport_header(skb) - skb_network_header(skb));
4927 *hdr_len +=
4928 (skb_transport_header(skb) - skb_network_header(skb));
4929 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4930 context_desc->seqnum_seed = 0;
4931
4932 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004933 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004934 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004935
Al Viro8327d002007-12-10 18:54:12 +00004936 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004937 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4938 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
4939 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4940
4941 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004942 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07004943 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
4944 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004945 /* use index 1 for TSO */
4946 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004947 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4948
4949 tx_buffer_info->time_stamp = jiffies;
4950 tx_buffer_info->next_to_watch = i;
4951
4952 i++;
4953 if (i == tx_ring->count)
4954 i = 0;
4955 tx_ring->next_to_use = i;
4956
4957 return true;
4958 }
4959 return false;
4960}
4961
4962static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004963 struct ixgbe_ring *tx_ring,
4964 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07004965{
4966 struct ixgbe_adv_tx_context_desc *context_desc;
4967 unsigned int i;
4968 struct ixgbe_tx_buffer *tx_buffer_info;
4969 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4970
4971 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4972 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4973 i = tx_ring->next_to_use;
4974 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4975 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4976
4977 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4978 vlan_macip_lens |=
4979 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4980 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004981 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004982 if (skb->ip_summed == CHECKSUM_PARTIAL)
4983 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004984 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07004985
4986 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4987 context_desc->seqnum_seed = 0;
4988
4989 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004990 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004991
4992 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08004993 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004994 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07004995 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08004996 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4997 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004998 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004999 else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
5000 type_tucmd_mlhl |=
5001 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08005002 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08005003 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08005004 /* XXX what about other V6 headers?? */
5005 if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
5006 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005007 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00005008 else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
5009 type_tucmd_mlhl |=
5010 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08005011 break;
Auke Kok41825d72008-02-12 15:20:33 -08005012 default:
5013 if (unlikely(net_ratelimit())) {
5014 DPRINTK(PROBE, WARNING,
5015 "partial checksum but proto=%x!\n",
5016 skb->protocol);
5017 }
5018 break;
5019 }
Auke Kok9a799d72007-09-15 14:07:45 -07005020 }
5021
5022 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07005023 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07005024 context_desc->mss_l4len_idx = 0;
5025
5026 tx_buffer_info->time_stamp = jiffies;
5027 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005028
Auke Kok9a799d72007-09-15 14:07:45 -07005029 i++;
5030 if (i == tx_ring->count)
5031 i = 0;
5032 tx_ring->next_to_use = i;
5033
5034 return true;
5035 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005036
Auke Kok9a799d72007-09-15 14:07:45 -07005037 return false;
5038}
5039
5040static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005041 struct ixgbe_ring *tx_ring,
Yi Zoueacd73f2009-05-13 13:11:06 +00005042 struct sk_buff *skb, u32 tx_flags,
5043 unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07005044{
Alexander Duycke5a43542009-12-02 16:46:56 +00005045 struct pci_dev *pdev = adapter->pdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005046 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00005047 unsigned int len;
5048 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07005049 unsigned int offset = 0, size, count = 0, i;
5050 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
5051 unsigned int f;
Auke Kok9a799d72007-09-15 14:07:45 -07005052
5053 i = tx_ring->next_to_use;
5054
Yi Zoueacd73f2009-05-13 13:11:06 +00005055 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
5056 /* excluding fcoe_crc_eof for FCoE */
5057 total -= sizeof(struct fcoe_crc_eof);
5058
5059 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07005060 while (len) {
5061 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5062 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
5063
5064 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00005065 tx_buffer_info->mapped_as_page = false;
5066 tx_buffer_info->dma = pci_map_single(pdev,
5067 skb->data + offset,
5068 size, PCI_DMA_TODEVICE);
5069 if (pci_dma_mapping_error(pdev, tx_buffer_info->dma))
5070 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07005071 tx_buffer_info->time_stamp = jiffies;
5072 tx_buffer_info->next_to_watch = i;
5073
5074 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00005075 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07005076 offset += size;
5077 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00005078
5079 if (len) {
5080 i++;
5081 if (i == tx_ring->count)
5082 i = 0;
5083 }
Auke Kok9a799d72007-09-15 14:07:45 -07005084 }
5085
5086 for (f = 0; f < nr_frags; f++) {
5087 struct skb_frag_struct *frag;
5088
5089 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00005090 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00005091 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07005092
5093 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00005094 i++;
5095 if (i == tx_ring->count)
5096 i = 0;
5097
Auke Kok9a799d72007-09-15 14:07:45 -07005098 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5099 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
5100
5101 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00005102 tx_buffer_info->dma = pci_map_page(adapter->pdev,
5103 frag->page,
5104 offset, size,
5105 PCI_DMA_TODEVICE);
5106 tx_buffer_info->mapped_as_page = true;
5107 if (pci_dma_mapping_error(pdev, tx_buffer_info->dma))
5108 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07005109 tx_buffer_info->time_stamp = jiffies;
5110 tx_buffer_info->next_to_watch = i;
5111
5112 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00005113 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07005114 offset += size;
5115 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07005116 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005117 if (total == 0)
5118 break;
Auke Kok9a799d72007-09-15 14:07:45 -07005119 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00005120
Auke Kok9a799d72007-09-15 14:07:45 -07005121 tx_ring->tx_buffer_info[i].skb = skb;
5122 tx_ring->tx_buffer_info[first].next_to_watch = i;
5123
5124 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00005125
5126dma_error:
5127 dev_err(&pdev->dev, "TX DMA map failed\n");
5128
5129 /* clear timestamp and dma mappings for failed tx_buffer_info map */
5130 tx_buffer_info->dma = 0;
5131 tx_buffer_info->time_stamp = 0;
5132 tx_buffer_info->next_to_watch = 0;
5133 count--;
5134
5135 /* clear timestamp and dma mappings for remaining portion of packet */
5136 while (count >= 0) {
5137 count--;
5138 i--;
5139 if (i < 0)
5140 i += tx_ring->count;
5141 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5142 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
5143 }
5144
5145 return count;
Auke Kok9a799d72007-09-15 14:07:45 -07005146}
5147
5148static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005149 struct ixgbe_ring *tx_ring,
5150 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07005151{
5152 union ixgbe_adv_tx_desc *tx_desc = NULL;
5153 struct ixgbe_tx_buffer *tx_buffer_info;
5154 u32 olinfo_status = 0, cmd_type_len = 0;
5155 unsigned int i;
5156 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
5157
5158 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
5159
5160 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
5161
5162 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
5163 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
5164
5165 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
5166 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
5167
5168 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005169 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07005170
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07005171 /* use index 1 context for tso */
5172 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07005173 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
5174 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005175 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07005176
5177 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
5178 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005179 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07005180
Yi Zoueacd73f2009-05-13 13:11:06 +00005181 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5182 olinfo_status |= IXGBE_ADVTXD_CC;
5183 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
5184 if (tx_flags & IXGBE_TX_FLAGS_FSO)
5185 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
5186 }
5187
Auke Kok9a799d72007-09-15 14:07:45 -07005188 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
5189
5190 i = tx_ring->next_to_use;
5191 while (count--) {
5192 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5193 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
5194 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
5195 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005196 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07005197 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07005198 i++;
5199 if (i == tx_ring->count)
5200 i = 0;
5201 }
5202
5203 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
5204
5205 /*
5206 * Force memory writes to complete before letting h/w
5207 * know there are new descriptors to fetch. (Only
5208 * applicable for weak-ordered memory model archs,
5209 * such as IA-64).
5210 */
5211 wmb();
5212
5213 tx_ring->next_to_use = i;
5214 writel(i, adapter->hw.hw_addr + tx_ring->tail);
5215}
5216
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005217static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
5218 int queue, u32 tx_flags)
5219{
5220 /* Right now, we support IPv4 only */
5221 struct ixgbe_atr_input atr_input;
5222 struct tcphdr *th;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005223 struct iphdr *iph = ip_hdr(skb);
5224 struct ethhdr *eth = (struct ethhdr *)skb->data;
5225 u16 vlan_id, src_port, dst_port, flex_bytes;
5226 u32 src_ipv4_addr, dst_ipv4_addr;
5227 u8 l4type = 0;
5228
5229 /* check if we're UDP or TCP */
5230 if (iph->protocol == IPPROTO_TCP) {
5231 th = tcp_hdr(skb);
5232 src_port = th->source;
5233 dst_port = th->dest;
5234 l4type |= IXGBE_ATR_L4TYPE_TCP;
5235 /* l4type IPv4 type is 0, no need to assign */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005236 } else {
5237 /* Unsupported L4 header, just bail here */
5238 return;
5239 }
5240
5241 memset(&atr_input, 0, sizeof(struct ixgbe_atr_input));
5242
5243 vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >>
5244 IXGBE_TX_FLAGS_VLAN_SHIFT;
5245 src_ipv4_addr = iph->saddr;
5246 dst_ipv4_addr = iph->daddr;
5247 flex_bytes = eth->h_proto;
5248
5249 ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
5250 ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
5251 ixgbe_atr_set_dst_port_82599(&atr_input, src_port);
5252 ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes);
5253 ixgbe_atr_set_l4type_82599(&atr_input, l4type);
5254 /* src and dst are inverted, think how the receiver sees them */
5255 ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr);
5256 ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr);
5257
5258 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
5259 ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue);
5260}
5261
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005262static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005263 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005264{
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005265 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005266 /* Herbert's original patch had:
5267 * smp_mb__after_netif_stop_queue();
5268 * but since that doesn't exist yet, just open code it. */
5269 smp_mb();
5270
5271 /* We need to check again in a case another CPU has just
5272 * made room available. */
5273 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
5274 return -EBUSY;
5275
5276 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07005277 netif_start_subqueue(netdev, tx_ring->queue_index);
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005278 ++tx_ring->restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005279 return 0;
5280}
5281
5282static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005283 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005284{
5285 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
5286 return 0;
5287 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
5288}
5289
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005290static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
5291{
5292 struct ixgbe_adapter *adapter = netdev_priv(dev);
Yi Zou5f715822009-12-03 11:32:44 +00005293 int txq = smp_processor_id();
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005294
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005295 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Yi Zou5f715822009-12-03 11:32:44 +00005296 return txq;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005297
Yi Zou5f715822009-12-03 11:32:44 +00005298#ifdef IXGBE_FCOE
5299 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
5300 (skb->protocol == htons(ETH_P_FCOE))) {
5301 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
5302 txq += adapter->ring_feature[RING_F_FCOE].mask;
5303 return txq;
5304 }
5305#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005306 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
Lucy Liu36e89d72009-08-05 13:06:34 -07005307 return (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) >> 13;
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005308
5309 return skb_tx_hash(dev, skb);
5310}
5311
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005312static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
5313 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07005314{
5315 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5316 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07005317 unsigned int first;
5318 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005319 u8 hdr_len = 0;
Yi Zou5f715822009-12-03 11:32:44 +00005320 int tso;
Auke Kok9a799d72007-09-15 14:07:45 -07005321 int count = 0;
5322 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005323
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005324 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
5325 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005326 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5327 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
Yi Zou5f715822009-12-03 11:32:44 +00005328 tx_flags |= ((skb->queue_mapping & 0x7) << 13);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005329 }
5330 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5331 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5332 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Lucy Liu60127862009-07-22 14:07:33 +00005333 if (skb->priority != TC_PRIO_CONTROL) {
Yi Zou5f715822009-12-03 11:32:44 +00005334 tx_flags |= ((skb->queue_mapping & 0x7) << 13);
Lucy Liu60127862009-07-22 14:07:33 +00005335 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5336 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5337 } else {
5338 skb->queue_mapping =
5339 adapter->ring_feature[RING_F_DCB].indices-1;
5340 }
Auke Kok9a799d72007-09-15 14:07:45 -07005341 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005342
Yi Zou5f715822009-12-03 11:32:44 +00005343 tx_ring = &adapter->tx_ring[skb->queue_mapping];
Lucy Liu60127862009-07-22 14:07:33 +00005344
Yi Zoueacd73f2009-05-13 13:11:06 +00005345 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
Yi Zou09ad1cc2009-09-03 14:56:10 +00005346 (skb->protocol == htons(ETH_P_FCOE))) {
Yi Zoueacd73f2009-05-13 13:11:06 +00005347 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Yi Zou09ad1cc2009-09-03 14:56:10 +00005348#ifdef IXGBE_FCOE
Yi Zou61a0f422009-12-03 11:32:22 +00005349#ifdef CONFIG_IXGBE_DCB
5350 tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK
5351 << IXGBE_TX_FLAGS_VLAN_SHIFT);
5352 tx_flags |= ((adapter->fcoe.up << 13)
5353 << IXGBE_TX_FLAGS_VLAN_SHIFT);
5354#endif
Yi Zou09ad1cc2009-09-03 14:56:10 +00005355#endif
5356 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005357 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005358 if (skb_is_gso(skb) ||
5359 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00005360 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
5361 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07005362 count++;
5363
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005364 count += TXD_USE_COUNT(skb_headlen(skb));
5365 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07005366 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
5367
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005368 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07005369 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07005370 return NETDEV_TX_BUSY;
5371 }
Auke Kok9a799d72007-09-15 14:07:45 -07005372
Auke Kok9a799d72007-09-15 14:07:45 -07005373 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00005374 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5375#ifdef IXGBE_FCOE
5376 /* setup tx offload for FCoE */
5377 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5378 if (tso < 0) {
5379 dev_kfree_skb_any(skb);
5380 return NETDEV_TX_OK;
5381 }
5382 if (tso)
5383 tx_flags |= IXGBE_TX_FLAGS_FSO;
5384#endif /* IXGBE_FCOE */
5385 } else {
5386 if (skb->protocol == htons(ETH_P_IP))
5387 tx_flags |= IXGBE_TX_FLAGS_IPV4;
5388 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5389 if (tso < 0) {
5390 dev_kfree_skb_any(skb);
5391 return NETDEV_TX_OK;
5392 }
5393
5394 if (tso)
5395 tx_flags |= IXGBE_TX_FLAGS_TSO;
5396 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
5397 (skb->ip_summed == CHECKSUM_PARTIAL))
5398 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005399 }
5400
Yi Zoueacd73f2009-05-13 13:11:06 +00005401 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005402 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005403 /* add the ATR filter if ATR is on */
5404 if (tx_ring->atr_sample_rate) {
5405 ++tx_ring->atr_count;
5406 if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) &&
5407 test_bit(__IXGBE_FDIR_INIT_DONE,
5408 &tx_ring->reinit_state)) {
5409 ixgbe_atr(adapter, skb, tx_ring->queue_index,
5410 tx_flags);
5411 tx_ring->atr_count = 0;
5412 }
5413 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00005414 ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
5415 hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005416 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07005417
Alexander Duyck44df32c2009-03-31 21:34:23 +00005418 } else {
5419 dev_kfree_skb_any(skb);
5420 tx_ring->tx_buffer_info[first].time_stamp = 0;
5421 tx_ring->next_to_use = first;
5422 }
Auke Kok9a799d72007-09-15 14:07:45 -07005423
5424 return NETDEV_TX_OK;
5425}
5426
5427/**
5428 * ixgbe_get_stats - Get System Network Statistics
5429 * @netdev: network interface device structure
5430 *
5431 * Returns the address of the device statistics structure.
5432 * The statistics are actually updated from the timer callback.
5433 **/
5434static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
5435{
Auke Kok9a799d72007-09-15 14:07:45 -07005436 /* only return the current stats */
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005437 return &netdev->stats;
Auke Kok9a799d72007-09-15 14:07:45 -07005438}
5439
5440/**
5441 * ixgbe_set_mac - Change the Ethernet Address of the NIC
5442 * @netdev: network interface device structure
5443 * @p: pointer to an address structure
5444 *
5445 * Returns 0 on success, negative on failure
5446 **/
5447static int ixgbe_set_mac(struct net_device *netdev, void *p)
5448{
5449 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005450 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005451 struct sockaddr *addr = p;
5452
5453 if (!is_valid_ether_addr(addr->sa_data))
5454 return -EADDRNOTAVAIL;
5455
5456 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005457 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07005458
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005459 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07005460
5461 return 0;
5462}
5463
Ben Hutchings6b73e102009-04-29 08:08:58 +00005464static int
5465ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
5466{
5467 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5468 struct ixgbe_hw *hw = &adapter->hw;
5469 u16 value;
5470 int rc;
5471
5472 if (prtad != hw->phy.mdio.prtad)
5473 return -EINVAL;
5474 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
5475 if (!rc)
5476 rc = value;
5477 return rc;
5478}
5479
5480static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
5481 u16 addr, u16 value)
5482{
5483 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5484 struct ixgbe_hw *hw = &adapter->hw;
5485
5486 if (prtad != hw->phy.mdio.prtad)
5487 return -EINVAL;
5488 return hw->phy.ops.write_reg(hw, addr, devad, value);
5489}
5490
5491static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
5492{
5493 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5494
5495 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
5496}
5497
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005498/**
5499 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00005500 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005501 * @netdev: network interface device structure
5502 *
5503 * Returns non-zero on failure
5504 **/
5505static int ixgbe_add_sanmac_netdev(struct net_device *dev)
5506{
5507 int err = 0;
5508 struct ixgbe_adapter *adapter = netdev_priv(dev);
5509 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5510
5511 if (is_valid_ether_addr(mac->san_addr)) {
5512 rtnl_lock();
5513 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5514 rtnl_unlock();
5515 }
5516 return err;
5517}
5518
5519/**
5520 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00005521 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005522 * @netdev: network interface device structure
5523 *
5524 * Returns non-zero on failure
5525 **/
5526static int ixgbe_del_sanmac_netdev(struct net_device *dev)
5527{
5528 int err = 0;
5529 struct ixgbe_adapter *adapter = netdev_priv(dev);
5530 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5531
5532 if (is_valid_ether_addr(mac->san_addr)) {
5533 rtnl_lock();
5534 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5535 rtnl_unlock();
5536 }
5537 return err;
5538}
5539
Auke Kok9a799d72007-09-15 14:07:45 -07005540#ifdef CONFIG_NET_POLL_CONTROLLER
5541/*
5542 * Polling 'interrupt' - used by things like netconsole to send skbs
5543 * without having to re-enable interrupts. It's not called while
5544 * the interrupt routine is executing.
5545 */
5546static void ixgbe_netpoll(struct net_device *netdev)
5547{
5548 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00005549 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005550
Auke Kok9a799d72007-09-15 14:07:45 -07005551 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00005552 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5553 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
5554 for (i = 0; i < num_q_vectors; i++) {
5555 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
5556 ixgbe_msix_clean_many(0, q_vector);
5557 }
5558 } else {
5559 ixgbe_intr(adapter->pdev->irq, netdev);
5560 }
Auke Kok9a799d72007-09-15 14:07:45 -07005561 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07005562}
5563#endif
5564
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005565static const struct net_device_ops ixgbe_netdev_ops = {
5566 .ndo_open = ixgbe_open,
5567 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005568 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005569 .ndo_select_queue = ixgbe_select_queue,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005570 .ndo_get_stats = ixgbe_get_stats,
Chris Leeche90d4002009-03-10 16:00:24 +00005571 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005572 .ndo_set_multicast_list = ixgbe_set_rx_mode,
5573 .ndo_validate_addr = eth_validate_addr,
5574 .ndo_set_mac_address = ixgbe_set_mac,
5575 .ndo_change_mtu = ixgbe_change_mtu,
5576 .ndo_tx_timeout = ixgbe_tx_timeout,
5577 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
5578 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
5579 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00005580 .ndo_do_ioctl = ixgbe_ioctl,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005581#ifdef CONFIG_NET_POLL_CONTROLLER
5582 .ndo_poll_controller = ixgbe_netpoll,
5583#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005584#ifdef IXGBE_FCOE
5585 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
5586 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00005587 .ndo_fcoe_enable = ixgbe_fcoe_enable,
5588 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00005589 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00005590#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005591};
5592
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005593/**
Auke Kok9a799d72007-09-15 14:07:45 -07005594 * ixgbe_probe - Device Initialization Routine
5595 * @pdev: PCI device information struct
5596 * @ent: entry in ixgbe_pci_tbl
5597 *
5598 * Returns 0 on success, negative on failure
5599 *
5600 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
5601 * The OS initialization, configuring of the adapter private structure,
5602 * and a hardware reset occur.
5603 **/
5604static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005605 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07005606{
5607 struct net_device *netdev;
5608 struct ixgbe_adapter *adapter = NULL;
5609 struct ixgbe_hw *hw;
5610 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07005611 static int cards_found;
5612 int i, err, pci_using_dac;
Yi Zoueacd73f2009-05-13 13:11:06 +00005613#ifdef IXGBE_FCOE
5614 u16 device_caps;
5615#endif
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005616 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07005617
gouji-new9ce77662009-05-06 10:44:45 +00005618 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005619 if (err)
5620 return err;
5621
Yang Hongyang6a355282009-04-06 19:01:13 -07005622 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
5623 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07005624 pci_using_dac = 1;
5625 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07005626 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005627 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -07005628 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005629 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005630 dev_err(&pdev->dev, "No usable DMA "
5631 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005632 goto err_dma;
5633 }
5634 }
5635 pci_using_dac = 0;
5636 }
5637
gouji-new9ce77662009-05-06 10:44:45 +00005638 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
5639 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07005640 if (err) {
gouji-new9ce77662009-05-06 10:44:45 +00005641 dev_err(&pdev->dev,
5642 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07005643 goto err_pci_reg;
5644 }
5645
Frans Pop19d5afd2009-10-02 10:04:12 -07005646 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005647
Auke Kok9a799d72007-09-15 14:07:45 -07005648 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07005649 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005650
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005651 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07005652 if (!netdev) {
5653 err = -ENOMEM;
5654 goto err_alloc_etherdev;
5655 }
5656
Auke Kok9a799d72007-09-15 14:07:45 -07005657 SET_NETDEV_DEV(netdev, &pdev->dev);
5658
5659 pci_set_drvdata(pdev, netdev);
5660 adapter = netdev_priv(netdev);
5661
5662 adapter->netdev = netdev;
5663 adapter->pdev = pdev;
5664 hw = &adapter->hw;
5665 hw->back = adapter;
5666 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
5667
Jeff Kirsher05857982008-09-11 19:57:00 -07005668 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
5669 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07005670 if (!hw->hw_addr) {
5671 err = -EIO;
5672 goto err_ioremap;
5673 }
5674
5675 for (i = 1; i <= 5; i++) {
5676 if (pci_resource_len(pdev, i) == 0)
5677 continue;
5678 }
5679
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005680 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07005681 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005682 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07005683 strcpy(netdev->name, pci_name(pdev));
5684
Auke Kok9a799d72007-09-15 14:07:45 -07005685 adapter->bd_number = cards_found;
5686
Auke Kok9a799d72007-09-15 14:07:45 -07005687 /* Setup hw api */
5688 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005689 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07005690
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005691 /* EEPROM */
5692 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
5693 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
5694 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
5695 if (!(eec & (1 << 8)))
5696 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
5697
5698 /* PHY */
5699 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08005700 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00005701 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
5702 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
5703 hw->phy.mdio.mmds = 0;
5704 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
5705 hw->phy.mdio.dev = netdev;
5706 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
5707 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08005708
5709 /* set up this timer and work struct before calling get_invariants
5710 * which might start the timer
5711 */
5712 init_timer(&adapter->sfp_timer);
5713 adapter->sfp_timer.function = &ixgbe_sfp_timer;
5714 adapter->sfp_timer.data = (unsigned long) adapter;
5715
5716 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005717
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005718 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
5719 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
5720
5721 /* a new SFP+ module arrival, called from GPI SDP2 context */
5722 INIT_WORK(&adapter->sfp_config_module_task,
5723 ixgbe_sfp_config_module_task);
5724
Don Skidmore8ca783a2009-05-26 20:40:47 -07005725 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005726
5727 /* setup the private structure */
5728 err = ixgbe_sw_init(adapter);
5729 if (err)
5730 goto err_sw_init;
5731
Don Skidmorebf069c92009-05-07 10:39:54 +00005732 /*
5733 * If there is a fan on this device and it has failed log the
5734 * failure.
5735 */
5736 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5737 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5738 if (esdp & IXGBE_ESDP_SDP1)
5739 DPRINTK(PROBE, CRIT,
5740 "Fan has stopped, replace the adapter\n");
5741 }
5742
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005743 /* reset_hw fills in the perm_addr as well */
5744 err = hw->mac.ops.reset_hw(hw);
Don Skidmore8ca783a2009-05-26 20:40:47 -07005745 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
5746 hw->mac.type == ixgbe_mac_82598EB) {
5747 /*
5748 * Start a kernel thread to watch for a module to arrive.
5749 * Only do this for 82598, since 82599 will generate
5750 * interrupts on module arrival.
5751 */
5752 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5753 mod_timer(&adapter->sfp_timer,
5754 round_jiffies(jiffies + (2 * HZ)));
5755 err = 0;
5756 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00005757 dev_err(&adapter->pdev->dev, "failed to initialize because "
5758 "an unsupported SFP+ module type was detected.\n"
5759 "Reload the driver after installing a supported "
5760 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005761 goto err_sw_init;
5762 } else if (err) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005763 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
5764 goto err_sw_init;
5765 }
5766
Auke Kok9a799d72007-09-15 14:07:45 -07005767 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005768 NETIF_F_IP_CSUM |
5769 NETIF_F_HW_VLAN_TX |
5770 NETIF_F_HW_VLAN_RX |
5771 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07005772
Jesse Brandeburge9990a92008-08-26 04:27:24 -07005773 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005774 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07005775 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08005776 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005777
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00005778 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
5779 netdev->features |= NETIF_F_SCTP_CSUM;
5780
Jeff Kirsherad31c402008-06-05 04:05:30 -07005781 netdev->vlan_features |= NETIF_F_TSO;
5782 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07005783 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00005784 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005785 netdev->vlan_features |= NETIF_F_SG;
5786
Alexander Duyck2f90b862008-11-20 20:52:10 -08005787 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5788 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
5789
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005790#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005791 netdev->dcbnl_ops = &dcbnl_ops;
5792#endif
5793
Yi Zoueacd73f2009-05-13 13:11:06 +00005794#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005795 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00005796 if (hw->mac.ops.get_device_caps) {
5797 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00005798 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
5799 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00005800 }
5801 }
5802#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005803 if (pci_using_dac)
5804 netdev->features |= NETIF_F_HIGHDMA;
5805
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005806 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00005807 netdev->features |= NETIF_F_LRO;
5808
Auke Kok9a799d72007-09-15 14:07:45 -07005809 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005810 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07005811 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
5812 err = -EIO;
5813 goto err_eeprom;
5814 }
5815
5816 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
5817 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
5818
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005819 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
5820 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005821 err = -EIO;
5822 goto err_eeprom;
5823 }
5824
5825 init_timer(&adapter->watchdog_timer);
5826 adapter->watchdog_timer.function = &ixgbe_watchdog;
5827 adapter->watchdog_timer.data = (unsigned long)adapter;
5828
5829 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005830 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005831
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005832 err = ixgbe_init_interrupt_scheme(adapter);
5833 if (err)
5834 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07005835
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005836 switch (pdev->device) {
5837 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005838 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
5839 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
Peter P Waskiewicz Jrbdf0a552009-06-04 11:09:58 +00005840 /* Enable ACPI wakeup in GRC */
5841 IXGBE_WRITE_REG(hw, IXGBE_GRC,
5842 (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005843 break;
5844 default:
5845 adapter->wol = 0;
5846 break;
5847 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005848 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
5849
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005850 /* pick up the PCI bus settings for reporting later */
5851 hw->mac.ops.get_bus_info(hw);
5852
Auke Kok9a799d72007-09-15 14:07:45 -07005853 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07005854 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005855 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
5856 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
5857 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
5858 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
5859 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005860 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07005861 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005862 ixgbe_read_pba_num_generic(hw, &part_num);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005863 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
5864 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
5865 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
5866 (part_num >> 8), (part_num & 0xff));
5867 else
5868 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
5869 hw->mac.type, hw->phy.type,
5870 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07005871
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005872 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Auke Kok0c254d82008-02-11 09:25:56 -08005873 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005874 "this card is not sufficient for optimal "
5875 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005876 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005877 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005878 }
5879
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08005880 /* save off EEPROM version number */
5881 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
5882
Auke Kok9a799d72007-09-15 14:07:45 -07005883 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005884 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005885
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005886 if (err == IXGBE_ERR_EEPROM_VERSION) {
5887 /* We are running on a pre-production device, log a warning */
5888 dev_warn(&pdev->dev, "This device is a pre-production "
5889 "adapter/LOM. Please be aware there may be issues "
5890 "associated with your hardware. If you are "
5891 "experiencing problems please contact your Intel or "
5892 "hardware representative who provided you with this "
5893 "hardware.\n");
5894 }
Auke Kok9a799d72007-09-15 14:07:45 -07005895 strcpy(netdev->name, "eth%d");
5896 err = register_netdev(netdev);
5897 if (err)
5898 goto err_register;
5899
Jesse Brandeburg54386462009-04-17 20:44:27 +00005900 /* carrier off reporting is important to ethtool even BEFORE open */
5901 netif_carrier_off(netdev);
5902
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005903 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5904 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5905 INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
5906
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005907#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03005908 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005909 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005910 ixgbe_setup_dca(adapter);
5911 }
5912#endif
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005913 /* add san mac addr to netdev */
5914 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005915
5916 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
5917 cards_found++;
5918 return 0;
5919
5920err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005921 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005922 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005923err_sw_init:
5924err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08005925 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5926 del_timer_sync(&adapter->sfp_timer);
5927 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005928 cancel_work_sync(&adapter->multispeed_fiber_task);
5929 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005930 iounmap(hw->hw_addr);
5931err_ioremap:
5932 free_netdev(netdev);
5933err_alloc_etherdev:
gouji-new9ce77662009-05-06 10:44:45 +00005934 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5935 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005936err_pci_reg:
5937err_dma:
5938 pci_disable_device(pdev);
5939 return err;
5940}
5941
5942/**
5943 * ixgbe_remove - Device Removal Routine
5944 * @pdev: PCI device information struct
5945 *
5946 * ixgbe_remove is called by the PCI subsystem to alert the driver
5947 * that it should release a PCI device. The could be caused by a
5948 * Hot-Plug event, or because the driver is going to be removed from
5949 * memory.
5950 **/
5951static void __devexit ixgbe_remove(struct pci_dev *pdev)
5952{
5953 struct net_device *netdev = pci_get_drvdata(pdev);
5954 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5955
5956 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08005957 /* clear the module not found bit to make sure the worker won't
5958 * reschedule
5959 */
5960 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07005961 del_timer_sync(&adapter->watchdog_timer);
5962
Donald Skidmorec4900be2008-11-20 21:11:42 -08005963 del_timer_sync(&adapter->sfp_timer);
5964 cancel_work_sync(&adapter->watchdog_task);
5965 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005966 cancel_work_sync(&adapter->multispeed_fiber_task);
5967 cancel_work_sync(&adapter->sfp_config_module_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005968 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5969 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5970 cancel_work_sync(&adapter->fdir_reinit_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005971 flush_scheduled_work();
5972
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005973#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005974 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
5975 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
5976 dca_remove_requester(&pdev->dev);
5977 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
5978 }
5979
5980#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005981#ifdef IXGBE_FCOE
5982 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
5983 ixgbe_cleanup_fcoe(adapter);
5984
5985#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005986
5987 /* remove the added san mac */
5988 ixgbe_del_sanmac_netdev(netdev);
5989
Donald Skidmorec4900be2008-11-20 21:11:42 -08005990 if (netdev->reg_state == NETREG_REGISTERED)
5991 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005992
Alexander Duyck7a921c92009-05-06 10:43:28 +00005993 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005994
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005995 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005996
5997 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00005998 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5999 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07006000
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006001 DPRINTK(PROBE, INFO, "complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006002
Auke Kok9a799d72007-09-15 14:07:45 -07006003 free_netdev(netdev);
6004
Frans Pop19d5afd2009-10-02 10:04:12 -07006005 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006006
Auke Kok9a799d72007-09-15 14:07:45 -07006007 pci_disable_device(pdev);
6008}
6009
6010/**
6011 * ixgbe_io_error_detected - called when PCI error is detected
6012 * @pdev: Pointer to PCI device
6013 * @state: The current pci connection state
6014 *
6015 * This function is called after a PCI bus error affecting
6016 * this device has been detected.
6017 */
6018static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006019 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07006020{
6021 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08006022 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006023
6024 netif_device_detach(netdev);
6025
Breno Leitao3044b8d2009-05-06 10:44:26 +00006026 if (state == pci_channel_io_perm_failure)
6027 return PCI_ERS_RESULT_DISCONNECT;
6028
Auke Kok9a799d72007-09-15 14:07:45 -07006029 if (netif_running(netdev))
6030 ixgbe_down(adapter);
6031 pci_disable_device(pdev);
6032
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006033 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07006034 return PCI_ERS_RESULT_NEED_RESET;
6035}
6036
6037/**
6038 * ixgbe_io_slot_reset - called after the pci bus has been reset.
6039 * @pdev: Pointer to PCI device
6040 *
6041 * Restart the card from scratch, as if from a cold-boot.
6042 */
6043static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
6044{
6045 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08006046 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006047 pci_ers_result_t result;
6048 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07006049
gouji-new9ce77662009-05-06 10:44:45 +00006050 if (pci_enable_device_mem(pdev)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006051 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006052 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006053 result = PCI_ERS_RESULT_DISCONNECT;
6054 } else {
6055 pci_set_master(pdev);
6056 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00006057 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006058
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006059 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006060
6061 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00006062 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006063 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07006064 }
Auke Kok9a799d72007-09-15 14:07:45 -07006065
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006066 err = pci_cleanup_aer_uncorrect_error_status(pdev);
6067 if (err) {
6068 dev_err(&pdev->dev,
6069 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
6070 /* non-fatal, continue */
6071 }
Auke Kok9a799d72007-09-15 14:07:45 -07006072
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006073 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07006074}
6075
6076/**
6077 * ixgbe_io_resume - called when traffic can start flowing again.
6078 * @pdev: Pointer to PCI device
6079 *
6080 * This callback is called when the error recovery driver tells us that
6081 * its OK to resume normal operation.
6082 */
6083static void ixgbe_io_resume(struct pci_dev *pdev)
6084{
6085 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08006086 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006087
6088 if (netif_running(netdev)) {
6089 if (ixgbe_up(adapter)) {
6090 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
6091 return;
6092 }
6093 }
6094
6095 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006096}
6097
6098static struct pci_error_handlers ixgbe_err_handler = {
6099 .error_detected = ixgbe_io_error_detected,
6100 .slot_reset = ixgbe_io_slot_reset,
6101 .resume = ixgbe_io_resume,
6102};
6103
6104static struct pci_driver ixgbe_driver = {
6105 .name = ixgbe_driver_name,
6106 .id_table = ixgbe_pci_tbl,
6107 .probe = ixgbe_probe,
6108 .remove = __devexit_p(ixgbe_remove),
6109#ifdef CONFIG_PM
6110 .suspend = ixgbe_suspend,
6111 .resume = ixgbe_resume,
6112#endif
6113 .shutdown = ixgbe_shutdown,
6114 .err_handler = &ixgbe_err_handler
6115};
6116
6117/**
6118 * ixgbe_init_module - Driver Registration Routine
6119 *
6120 * ixgbe_init_module is the first routine called when the driver is
6121 * loaded. All it does is register with the PCI subsystem.
6122 **/
6123static int __init ixgbe_init_module(void)
6124{
6125 int ret;
6126 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
6127 ixgbe_driver_string, ixgbe_driver_version);
6128
6129 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
6130
Jeff Garzik5dd2d332008-10-16 05:09:31 -04006131#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006132 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006133#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04006134
Auke Kok9a799d72007-09-15 14:07:45 -07006135 ret = pci_register_driver(&ixgbe_driver);
6136 return ret;
6137}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006138
Auke Kok9a799d72007-09-15 14:07:45 -07006139module_init(ixgbe_init_module);
6140
6141/**
6142 * ixgbe_exit_module - Driver Exit Cleanup Routine
6143 *
6144 * ixgbe_exit_module is called just before the driver is removed
6145 * from memory.
6146 **/
6147static void __exit ixgbe_exit_module(void)
6148{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04006149#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006150 dca_unregister_notify(&dca_notifier);
6151#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006152 pci_unregister_driver(&ixgbe_driver);
6153}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006154
Jeff Garzik5dd2d332008-10-16 05:09:31 -04006155#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006156static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006157 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006158{
6159 int ret_val;
6160
6161 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006162 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006163
6164 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
6165}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006166
Alexander Duyckb4533682009-03-31 21:32:42 +00006167#endif /* CONFIG_IXGBE_DCA */
6168#ifdef DEBUG
6169/**
6170 * ixgbe_get_hw_dev_name - return device name string
6171 * used by hardware layer to print debugging information
6172 **/
6173char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
6174{
6175 struct ixgbe_adapter *adapter = hw->back;
6176 return adapter->netdev->name;
6177}
6178
6179#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006180module_exit(ixgbe_exit_module);
6181
6182/* ixgbe_main.c */