blob: 9ba506f6ef2975f058919420321e729c76dcaef5 [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 Brandeburge01c31a2008-08-26 04:27:13 -0700416 ++adapter->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 adapter->hw_csum_rx_good++;
628}
629
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000630static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
631 struct ixgbe_ring *rx_ring, u32 val)
632{
633 /*
634 * Force memory writes to complete before letting h/w
635 * know there are new descriptors to fetch. (Only
636 * applicable for weak-ordered memory model archs,
637 * such as IA-64).
638 */
639 wmb();
640 IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
641}
642
Auke Kok9a799d72007-09-15 14:07:45 -0700643/**
644 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
645 * @adapter: address of board private structure
646 **/
647static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700648 struct ixgbe_ring *rx_ring,
649 int cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -0700650{
Auke Kok9a799d72007-09-15 14:07:45 -0700651 struct pci_dev *pdev = adapter->pdev;
652 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700653 struct ixgbe_rx_buffer *bi;
Auke Kok9a799d72007-09-15 14:07:45 -0700654 unsigned int i;
Auke Kok9a799d72007-09-15 14:07:45 -0700655
656 i = rx_ring->next_to_use;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700657 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700658
659 while (cleaned_count--) {
660 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
661
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700662 if (!bi->page_dma &&
Yi Zou6e455b892009-08-06 13:05:44 +0000663 (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700664 if (!bi->page) {
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700665 bi->page = alloc_page(GFP_ATOMIC);
666 if (!bi->page) {
667 adapter->alloc_rx_page_failed++;
668 goto no_buffers;
669 }
670 bi->page_offset = 0;
671 } else {
672 /* use a half page if we're re-using */
673 bi->page_offset ^= (PAGE_SIZE / 2);
Auke Kok9a799d72007-09-15 14:07:45 -0700674 }
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700675
676 bi->page_dma = pci_map_page(pdev, bi->page,
677 bi->page_offset,
678 (PAGE_SIZE / 2),
679 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700680 }
681
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700682 if (!bi->skb) {
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800683 struct sk_buff *skb;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000684 skb = netdev_alloc_skb_ip_align(adapter->netdev,
685 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -0700686
687 if (!skb) {
688 adapter->alloc_rx_buff_failed++;
689 goto no_buffers;
690 }
691
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700692 bi->skb = skb;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000693 bi->dma = pci_map_single(pdev, skb->data,
694 rx_ring->rx_buf_len,
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700695 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700696 }
697 /* Refresh the desc even if buffer_addrs didn't change because
698 * each write-back erases this info. */
Yi Zou6e455b892009-08-06 13:05:44 +0000699 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700700 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
701 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700702 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700703 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -0700704 }
705
706 i++;
707 if (i == rx_ring->count)
708 i = 0;
Jesse Brandeburg3a581072008-08-26 04:27:08 -0700709 bi = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700710 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700711
Auke Kok9a799d72007-09-15 14:07:45 -0700712no_buffers:
713 if (rx_ring->next_to_use != i) {
714 rx_ring->next_to_use = i;
715 if (i-- == 0)
716 i = (rx_ring->count - 1);
717
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000718 ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700719 }
720}
721
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700722static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
723{
724 return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
725}
726
727static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
728{
729 return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
730}
731
Alexander Duyckf8212f92009-04-27 22:42:37 +0000732static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
733{
734 return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
735 IXGBE_RXDADV_RSCCNT_MASK) >>
736 IXGBE_RXDADV_RSCCNT_SHIFT;
737}
738
739/**
740 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
741 * @skb: pointer to the last skb in the rsc queue
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +0000742 * @count: pointer to number of packets coalesced in this context
Alexander Duyckf8212f92009-04-27 22:42:37 +0000743 *
744 * This function changes a queue full of hw rsc buffers into a completed
745 * packet. It uses the ->prev pointers to find the first packet and then
746 * turns it into the frag list owner.
747 **/
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +0000748static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb,
749 u64 *count)
Alexander Duyckf8212f92009-04-27 22:42:37 +0000750{
751 unsigned int frag_list_size = 0;
752
753 while (skb->prev) {
754 struct sk_buff *prev = skb->prev;
755 frag_list_size += skb->len;
756 skb->prev = NULL;
757 skb = prev;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +0000758 *count += 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000759 }
760
761 skb_shinfo(skb)->frag_list = skb->next;
762 skb->next = NULL;
763 skb->len += frag_list_size;
764 skb->data_len += frag_list_size;
765 skb->truesize += frag_list_size;
766 return skb;
767}
768
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800769static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700770 struct ixgbe_ring *rx_ring,
771 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -0700772{
Herbert Xu78b6f4c2009-01-18 21:49:45 -0800773 struct ixgbe_adapter *adapter = q_vector->adapter;
Ajit Khaparde2d86f132009-10-07 02:43:49 +0000774 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -0700775 struct pci_dev *pdev = adapter->pdev;
776 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
777 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
778 struct sk_buff *skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000779 unsigned int i, rsc_count = 0;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700780 u32 len, staterr;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700781 u16 hdr_info;
782 bool cleaned = false;
Auke Kok9a799d72007-09-15 14:07:45 -0700783 int cleaned_count = 0;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800784 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +0000785#ifdef IXGBE_FCOE
786 int ddp_bytes = 0;
787#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -0700788
789 i = rx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700790 rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i);
791 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
792 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700793
794 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700795 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700796 if (*work_done >= work_to_do)
797 break;
798 (*work_done)++;
799
Yi Zou6e455b892009-08-06 13:05:44 +0000800 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700801 hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
802 len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700803 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -0700804 if (hdr_info & IXGBE_RXDADV_SPH)
805 adapter->rx_hdr_split++;
806 if (len > IXGBE_RX_HDR_SIZE)
807 len = IXGBE_RX_HDR_SIZE;
808 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700809 } else {
Auke Kok9a799d72007-09-15 14:07:45 -0700810 len = le16_to_cpu(rx_desc->wb.upper.length);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -0700811 }
Auke Kok9a799d72007-09-15 14:07:45 -0700812
813 cleaned = true;
814 skb = rx_buffer_info->skb;
815 prefetch(skb->data - NET_IP_ALIGN);
816 rx_buffer_info->skb = NULL;
817
Alexander Duyck21fa4e62009-06-04 15:59:49 +0000818 if (rx_buffer_info->dma) {
Auke Kok9a799d72007-09-15 14:07:45 -0700819 pci_unmap_single(pdev, rx_buffer_info->dma,
Jesse Brandeburg5ecc3612008-12-15 01:00:57 -0800820 rx_ring->rx_buf_len,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700821 PCI_DMA_FROMDEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +0000822 rx_buffer_info->dma = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700823 skb_put(skb, len);
824 }
825
826 if (upper_len) {
827 pci_unmap_page(pdev, rx_buffer_info->page_dma,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700828 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -0700829 rx_buffer_info->page_dma = 0;
830 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Jesse Brandeburg762f4c52008-09-11 19:58:43 -0700831 rx_buffer_info->page,
832 rx_buffer_info->page_offset,
833 upper_len);
834
835 if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
836 (page_count(rx_buffer_info->page) != 1))
837 rx_buffer_info->page = NULL;
838 else
839 get_page(rx_buffer_info->page);
Auke Kok9a799d72007-09-15 14:07:45 -0700840
841 skb->len += upper_len;
842 skb->data_len += upper_len;
843 skb->truesize += upper_len;
844 }
845
846 i++;
847 if (i == rx_ring->count)
848 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700849
850 next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i);
851 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -0700852 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000853
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +0000854 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
Alexander Duyckf8212f92009-04-27 22:42:37 +0000855 rsc_count = ixgbe_get_rsc_count(rx_desc);
856
857 if (rsc_count) {
858 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
859 IXGBE_RXDADV_NEXTP_SHIFT;
860 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +0000861 } else {
862 next_buffer = &rx_ring->rx_buffer_info[i];
863 }
864
Auke Kok9a799d72007-09-15 14:07:45 -0700865 if (staterr & IXGBE_RXD_STAT_EOP) {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000866 if (skb->prev)
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +0000867 skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count));
868 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
869 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)
870 rx_ring->rsc_count += skb_shinfo(skb)->nr_frags;
871 else
872 rx_ring->rsc_count++;
873 rx_ring->rsc_flush++;
874 }
Auke Kok9a799d72007-09-15 14:07:45 -0700875 rx_ring->stats.packets++;
876 rx_ring->stats.bytes += skb->len;
877 } else {
Yi Zou6e455b892009-08-06 13:05:44 +0000878 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +0000879 rx_buffer_info->skb = next_buffer->skb;
880 rx_buffer_info->dma = next_buffer->dma;
881 next_buffer->skb = skb;
882 next_buffer->dma = 0;
883 } else {
884 skb->next = next_buffer->skb;
885 skb->next->prev = skb;
886 }
Auke Kok9a799d72007-09-15 14:07:45 -0700887 adapter->non_eop_descs++;
888 goto next_desc;
889 }
890
891 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
892 dev_kfree_skb_irq(skb);
893 goto next_desc;
894 }
895
Don Skidmore8bae1b22009-07-23 18:00:39 +0000896 ixgbe_rx_checksum(adapter, rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -0800897
898 /* probably a little skewed due to removing CRC */
899 total_rx_bytes += skb->len;
900 total_rx_packets++;
901
Jesse Brandeburg74ce8dd2008-09-11 20:03:23 -0700902 skb->protocol = eth_type_trans(skb, adapter->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +0000903#ifdef IXGBE_FCOE
904 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +0000905 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
906 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
907 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +0000908 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +0000909 }
Yi Zou332d4a72009-05-13 13:11:53 +0000910#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +0000911 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -0700912
913next_desc:
914 rx_desc->wb.upper.status_error = 0;
915
916 /* return some buffers to hardware, one at a time is too slow */
917 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
918 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
919 cleaned_count = 0;
920 }
921
922 /* use prefetched values */
923 rx_desc = next_rxd;
Alexander Duyckf8212f92009-04-27 22:42:37 +0000924 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700925
926 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -0700927 }
928
Auke Kok9a799d72007-09-15 14:07:45 -0700929 rx_ring->next_to_clean = i;
930 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
931
932 if (cleaned_count)
933 ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
934
Yi Zou3d8fd382009-06-08 14:38:44 +0000935#ifdef IXGBE_FCOE
936 /* include DDPed FCoE data */
937 if (ddp_bytes > 0) {
938 unsigned int mss;
939
940 mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) -
941 sizeof(struct fc_frame_header) -
942 sizeof(struct fcoe_crc_eof);
943 if (mss > 512)
944 mss &= ~511;
945 total_rx_bytes += ddp_bytes;
946 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
947 }
948#endif /* IXGBE_FCOE */
949
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800950 rx_ring->total_packets += total_rx_packets;
951 rx_ring->total_bytes += total_rx_bytes;
Ajit Khaparde2d86f132009-10-07 02:43:49 +0000952 netdev->stats.rx_bytes += total_rx_bytes;
953 netdev->stats.rx_packets += total_rx_packets;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -0800954
Auke Kok9a799d72007-09-15 14:07:45 -0700955 return cleaned;
956}
957
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800958static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -0700959/**
960 * ixgbe_configure_msix - Configure MSI-X hardware
961 * @adapter: board private structure
962 *
963 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
964 * interrupts.
965 **/
966static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
967{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800968 struct ixgbe_q_vector *q_vector;
969 int i, j, q_vectors, v_idx, r_idx;
970 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -0700971
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800972 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
973
Jesse Brandeburg4df10462009-03-13 22:15:31 +0000974 /*
975 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800976 * corresponding register.
977 */
978 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +0000979 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800980 /* XXX for_each_bit(...) */
981 r_idx = find_first_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700982 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800983
984 for (i = 0; i < q_vector->rxr_count; i++) {
985 j = adapter->rx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000986 ixgbe_set_ivar(adapter, 0, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800987 r_idx = find_next_bit(q_vector->rxr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700988 adapter->num_rx_queues,
989 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800990 }
991 r_idx = find_first_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700992 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800993
994 for (i = 0; i < q_vector->txr_count; i++) {
995 j = adapter->tx_ring[r_idx].reg_idx;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000996 ixgbe_set_ivar(adapter, 1, j, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -0800997 r_idx = find_next_bit(q_vector->txr_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700998 adapter->num_tx_queues,
999 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001000 }
1001
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001002 if (q_vector->txr_count && !q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001003 /* tx only */
1004 q_vector->eitr = adapter->tx_eitr_param;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001005 else if (q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001006 /* rx or mixed */
1007 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001008
Alexander Duyckfe49f042009-06-04 16:00:09 +00001009 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001010 }
1011
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001012 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
1013 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
1014 v_idx);
1015 else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
1016 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001017 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001018
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001019 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001020 mask = IXGBE_EIMS_ENABLE_MASK;
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001021 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001022 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001023}
1024
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001025enum latency_range {
1026 lowest_latency = 0,
1027 low_latency = 1,
1028 bulk_latency = 2,
1029 latency_invalid = 255
1030};
1031
1032/**
1033 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1034 * @adapter: pointer to adapter
1035 * @eitr: eitr setting (ints per sec) to give last timeslice
1036 * @itr_setting: current throttle rate in ints/second
1037 * @packets: the number of packets during this measurement interval
1038 * @bytes: the number of bytes during this measurement interval
1039 *
1040 * Stores a new ITR value based on packets and byte
1041 * counts during the last interrupt. The advantage of per interrupt
1042 * computation is faster updates and more accurate ITR for the current
1043 * traffic pattern. Constants in this function were computed
1044 * based on theoretical maximum wire speed and thresholds were set based
1045 * on testing data as well as attempting to minimize response time
1046 * while increasing bulk throughput.
1047 * this functionality is controlled by the InterruptThrottleRate module
1048 * parameter (see ixgbe_param.c)
1049 **/
1050static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001051 u32 eitr, u8 itr_setting,
1052 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001053{
1054 unsigned int retval = itr_setting;
1055 u32 timepassed_us;
1056 u64 bytes_perint;
1057
1058 if (packets == 0)
1059 goto update_itr_done;
1060
1061
1062 /* simple throttlerate management
1063 * 0-20MB/s lowest (100000 ints/s)
1064 * 20-100MB/s low (20000 ints/s)
1065 * 100-1249MB/s bulk (8000 ints/s)
1066 */
1067 /* what was last interrupt timeslice? */
1068 timepassed_us = 1000000/eitr;
1069 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1070
1071 switch (itr_setting) {
1072 case lowest_latency:
1073 if (bytes_perint > adapter->eitr_low)
1074 retval = low_latency;
1075 break;
1076 case low_latency:
1077 if (bytes_perint > adapter->eitr_high)
1078 retval = bulk_latency;
1079 else if (bytes_perint <= adapter->eitr_low)
1080 retval = lowest_latency;
1081 break;
1082 case bulk_latency:
1083 if (bytes_perint <= adapter->eitr_high)
1084 retval = low_latency;
1085 break;
1086 }
1087
1088update_itr_done:
1089 return retval;
1090}
1091
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001092/**
1093 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001094 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001095 *
1096 * This function is made to be called by ethtool and by the driver
1097 * when it needs to update EITR registers at runtime. Hardware
1098 * specific quirks/differences are taken care of here.
1099 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001100void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001101{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001102 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001103 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001104 int v_idx = q_vector->v_idx;
1105 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1106
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001107 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1108 /* must write high and low 16 bits to reset counter */
1109 itr_reg |= (itr_reg << 16);
1110 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
1111 /*
1112 * set the WDIS bit to not clear the timer bits and cause an
1113 * immediate assertion of the interrupt
1114 */
1115 itr_reg |= IXGBE_EITR_CNT_WDIS;
1116 }
1117 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1118}
1119
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001120static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1121{
1122 struct ixgbe_adapter *adapter = q_vector->adapter;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001123 u32 new_itr;
1124 u8 current_itr, ret_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001125 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001126 struct ixgbe_ring *rx_ring, *tx_ring;
1127
1128 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1129 for (i = 0; i < q_vector->txr_count; i++) {
1130 tx_ring = &(adapter->tx_ring[r_idx]);
1131 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001132 q_vector->tx_itr,
1133 tx_ring->total_packets,
1134 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001135 /* if the result for this queue would decrease interrupt
1136 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001137 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001138 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001139 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001140 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001141 }
1142
1143 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1144 for (i = 0; i < q_vector->rxr_count; i++) {
1145 rx_ring = &(adapter->rx_ring[r_idx]);
1146 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001147 q_vector->rx_itr,
1148 rx_ring->total_packets,
1149 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001150 /* if the result for this queue would decrease interrupt
1151 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001152 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001153 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001154 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001155 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001156 }
1157
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001158 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001159
1160 switch (current_itr) {
1161 /* counts and packets in update_itr are dependent on these numbers */
1162 case lowest_latency:
1163 new_itr = 100000;
1164 break;
1165 case low_latency:
1166 new_itr = 20000; /* aka hwitr = ~200 */
1167 break;
1168 case bulk_latency:
1169 default:
1170 new_itr = 8000;
1171 break;
1172 }
1173
1174 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001175 /* do an exponential smoothing */
1176 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001177
1178 /* save the algorithm value here, not the smoothed one */
1179 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001180
1181 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001182 }
1183
1184 return;
1185}
1186
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001187static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1188{
1189 struct ixgbe_hw *hw = &adapter->hw;
1190
1191 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1192 (eicr & IXGBE_EICR_GPI_SDP1)) {
1193 DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n");
1194 /* write to clear the interrupt */
1195 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1196 }
1197}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001198
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001199static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1200{
1201 struct ixgbe_hw *hw = &adapter->hw;
1202
1203 if (eicr & IXGBE_EICR_GPI_SDP1) {
1204 /* Clear the interrupt */
1205 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1206 schedule_work(&adapter->multispeed_fiber_task);
1207 } else if (eicr & IXGBE_EICR_GPI_SDP2) {
1208 /* Clear the interrupt */
1209 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1210 schedule_work(&adapter->sfp_config_module_task);
1211 } else {
1212 /* Interrupt isn't for us... */
1213 return;
1214 }
1215}
1216
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001217static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1218{
1219 struct ixgbe_hw *hw = &adapter->hw;
1220
1221 adapter->lsc_int++;
1222 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1223 adapter->link_check_timeout = jiffies;
1224 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1225 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001226 IXGBE_WRITE_FLUSH(hw);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001227 schedule_work(&adapter->watchdog_task);
1228 }
1229}
1230
Auke Kok9a799d72007-09-15 14:07:45 -07001231static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1232{
1233 struct net_device *netdev = data;
1234 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1235 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001236 u32 eicr;
1237
1238 /*
1239 * Workaround for Silicon errata. Use clear-by-write instead
1240 * of clear-by-read. Reading with EICS will return the
1241 * interrupt causes without clearing, which later be done
1242 * with the write to EICR.
1243 */
1244 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1245 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001246
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001247 if (eicr & IXGBE_EICR_LSC)
1248 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001249
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001250 if (hw->mac.type == ixgbe_mac_82598EB)
1251 ixgbe_check_fan_failure(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001252
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001253 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001254 ixgbe_check_sfp_event(adapter, eicr);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001255
1256 /* Handle Flow Director Full threshold interrupt */
1257 if (eicr & IXGBE_EICR_FLOW_DIR) {
1258 int i;
1259 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
1260 /* Disable transmits before FDIR Re-initialization */
1261 netif_tx_stop_all_queues(netdev);
1262 for (i = 0; i < adapter->num_tx_queues; i++) {
1263 struct ixgbe_ring *tx_ring =
1264 &adapter->tx_ring[i];
1265 if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE,
1266 &tx_ring->reinit_state))
1267 schedule_work(&adapter->fdir_reinit_task);
1268 }
1269 }
1270 }
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001271 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1272 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -07001273
1274 return IRQ_HANDLED;
1275}
1276
Alexander Duyckfe49f042009-06-04 16:00:09 +00001277static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1278 u64 qmask)
1279{
1280 u32 mask;
1281
1282 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1283 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1284 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
1285 } else {
1286 mask = (qmask & 0xFFFFFFFF);
1287 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
1288 mask = (qmask >> 32);
1289 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
1290 }
1291 /* skip the flush */
1292}
1293
1294static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
1295 u64 qmask)
1296{
1297 u32 mask;
1298
1299 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1300 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
1301 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
1302 } else {
1303 mask = (qmask & 0xFFFFFFFF);
1304 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
1305 mask = (qmask >> 32);
1306 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
1307 }
1308 /* skip the flush */
1309}
1310
Auke Kok9a799d72007-09-15 14:07:45 -07001311static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1312{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001313 struct ixgbe_q_vector *q_vector = data;
1314 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001315 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001316 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001317
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001318 if (!q_vector->txr_count)
1319 return IRQ_HANDLED;
1320
1321 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1322 for (i = 0; i < q_vector->txr_count; i++) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001323 tx_ring = &(adapter->tx_ring[r_idx]);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001324 tx_ring->total_bytes = 0;
1325 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001326 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001327 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001328 }
1329
Alexander Duyck91281fd2009-06-04 16:00:27 +00001330 /* disable interrupts on this vector only */
1331 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1332 napi_schedule(&q_vector->napi);
1333
Auke Kok9a799d72007-09-15 14:07:45 -07001334 return IRQ_HANDLED;
1335}
1336
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001337/**
1338 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
1339 * @irq: unused
1340 * @data: pointer to our q_vector struct for this interrupt vector
1341 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001342static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
1343{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001344 struct ixgbe_q_vector *q_vector = data;
1345 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001346 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001347 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001348 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07001349
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001350 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001351 for (i = 0; i < q_vector->rxr_count; i++) {
1352 rx_ring = &(adapter->rx_ring[r_idx]);
1353 rx_ring->total_bytes = 0;
1354 rx_ring->total_packets = 0;
1355 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1356 r_idx + 1);
1357 }
1358
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001359 if (!q_vector->rxr_count)
1360 return IRQ_HANDLED;
1361
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001362 /* disable interrupts on this vector only */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001363 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
Ben Hutchings288379f2009-01-19 16:43:59 -08001364 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001365
Auke Kok9a799d72007-09-15 14:07:45 -07001366 return IRQ_HANDLED;
1367}
1368
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001369static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
1370{
Alexander Duyck91281fd2009-06-04 16:00:27 +00001371 struct ixgbe_q_vector *q_vector = data;
1372 struct ixgbe_adapter *adapter = q_vector->adapter;
1373 struct ixgbe_ring *ring;
1374 int r_idx;
1375 int i;
1376
1377 if (!q_vector->txr_count && !q_vector->rxr_count)
1378 return IRQ_HANDLED;
1379
1380 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1381 for (i = 0; i < q_vector->txr_count; i++) {
1382 ring = &(adapter->tx_ring[r_idx]);
1383 ring->total_bytes = 0;
1384 ring->total_packets = 0;
1385 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1386 r_idx + 1);
1387 }
1388
1389 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1390 for (i = 0; i < q_vector->rxr_count; i++) {
1391 ring = &(adapter->rx_ring[r_idx]);
1392 ring->total_bytes = 0;
1393 ring->total_packets = 0;
1394 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1395 r_idx + 1);
1396 }
1397
1398 /* disable interrupts on this vector only */
1399 ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx));
1400 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001401
1402 return IRQ_HANDLED;
1403}
1404
1405/**
1406 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
1407 * @napi: napi struct with our devices info in it
1408 * @budget: amount of work driver is allowed to do this pass, in packets
1409 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001410 * This function is optimized for cleaning one queue only on a single
1411 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001412 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001413static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1414{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001415 struct ixgbe_q_vector *q_vector =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001416 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001417 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001418 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001419 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001420 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001421
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001422 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001423 rx_ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001424#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001425 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001426 ixgbe_update_rx_dca(adapter, rx_ring);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001427#endif
Auke Kok9a799d72007-09-15 14:07:45 -07001428
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001429 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001430
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001431 /* If all Rx work done, exit the polling mode */
1432 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001433 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001434 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001435 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001436 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001437 ixgbe_irq_enable_queues(adapter,
1438 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07001439 }
1440
1441 return work_done;
1442}
1443
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001444/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00001445 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001446 * @napi: napi struct with our devices info in it
1447 * @budget: amount of work driver is allowed to do this pass, in packets
1448 *
1449 * This function will clean more than one rx queue associated with a
1450 * q_vector.
1451 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00001452static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001453{
1454 struct ixgbe_q_vector *q_vector =
1455 container_of(napi, struct ixgbe_q_vector, napi);
1456 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001457 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001458 int work_done = 0, i;
1459 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00001460 bool tx_clean_complete = true;
1461
1462 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1463 for (i = 0; i < q_vector->txr_count; i++) {
1464 ring = &(adapter->tx_ring[r_idx]);
1465#ifdef CONFIG_IXGBE_DCA
1466 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1467 ixgbe_update_tx_dca(adapter, ring);
1468#endif
1469 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
1470 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1471 r_idx + 1);
1472 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001473
1474 /* attempt to distribute budget to each queue fairly, but don't allow
1475 * the budget to go below 1 because we'll exit polling */
1476 budget /= (q_vector->rxr_count ?: 1);
1477 budget = max(budget, 1);
1478 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1479 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck91281fd2009-06-04 16:00:27 +00001480 ring = &(adapter->rx_ring[r_idx]);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001481#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001482 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck91281fd2009-06-04 16:00:27 +00001483 ixgbe_update_rx_dca(adapter, ring);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001484#endif
Alexander Duyck91281fd2009-06-04 16:00:27 +00001485 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001486 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1487 r_idx + 1);
1488 }
1489
1490 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck91281fd2009-06-04 16:00:27 +00001491 ring = &(adapter->rx_ring[r_idx]);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001492 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07001493 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08001494 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001495 if (adapter->rx_itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001496 ixgbe_set_itr_msix(q_vector);
1497 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00001498 ixgbe_irq_enable_queues(adapter,
1499 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07001500 return 0;
1501 }
1502
1503 return work_done;
1504}
Alexander Duyck91281fd2009-06-04 16:00:27 +00001505
1506/**
1507 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
1508 * @napi: napi struct with our devices info in it
1509 * @budget: amount of work driver is allowed to do this pass, in packets
1510 *
1511 * This function is optimized for cleaning one queue only on a single
1512 * q_vector!!!
1513 **/
1514static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
1515{
1516 struct ixgbe_q_vector *q_vector =
1517 container_of(napi, struct ixgbe_q_vector, napi);
1518 struct ixgbe_adapter *adapter = q_vector->adapter;
1519 struct ixgbe_ring *tx_ring = NULL;
1520 int work_done = 0;
1521 long r_idx;
1522
1523 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1524 tx_ring = &(adapter->tx_ring[r_idx]);
1525#ifdef CONFIG_IXGBE_DCA
1526 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1527 ixgbe_update_tx_dca(adapter, tx_ring);
1528#endif
1529
1530 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
1531 work_done = budget;
1532
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001533 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00001534 if (work_done < budget) {
1535 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001536 if (adapter->tx_itr_setting & 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00001537 ixgbe_set_itr_msix(q_vector);
1538 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1539 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
1540 }
1541
1542 return work_done;
1543}
1544
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001545static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001546 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07001547{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001548 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1549
1550 set_bit(r_idx, q_vector->rxr_idx);
1551 q_vector->rxr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001552}
Auke Kok9a799d72007-09-15 14:07:45 -07001553
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001554static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001555 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001556{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001557 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
1558
1559 set_bit(t_idx, q_vector->txr_idx);
1560 q_vector->txr_count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001561}
Auke Kok9a799d72007-09-15 14:07:45 -07001562
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001563/**
1564 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
1565 * @adapter: board private structure to initialize
1566 * @vectors: allotted vector count for descriptor rings
1567 *
1568 * This function maps descriptor rings to the queue-specific vectors
1569 * we were allotted through the MSI-X enabling code. Ideally, we'd have
1570 * one vector per ring/queue, but on a constrained vector budget, we
1571 * group the rings as "efficiently" as possible. You would add new
1572 * mapping configurations in here.
1573 **/
1574static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001575 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001576{
1577 int v_start = 0;
1578 int rxr_idx = 0, txr_idx = 0;
1579 int rxr_remaining = adapter->num_rx_queues;
1580 int txr_remaining = adapter->num_tx_queues;
1581 int i, j;
1582 int rqpv, tqpv;
1583 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001584
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001585 /* No mapping required if MSI-X is disabled. */
1586 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001587 goto out;
1588
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001589 /*
1590 * The ideal configuration...
1591 * We have enough vectors to map one per queue.
1592 */
1593 if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
1594 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
1595 map_vector_to_rxq(adapter, v_start, rxr_idx);
1596
1597 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
1598 map_vector_to_txq(adapter, v_start, txr_idx);
1599
1600 goto out;
1601 }
1602
1603 /*
1604 * If we don't have enough vectors for a 1-to-1
1605 * mapping, we'll have to group them so there are
1606 * multiple queues per vector.
1607 */
1608 /* Re-adjusting *qpv takes care of the remainder. */
1609 for (i = v_start; i < vectors; i++) {
1610 rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
1611 for (j = 0; j < rqpv; j++) {
1612 map_vector_to_rxq(adapter, i, rxr_idx);
1613 rxr_idx++;
1614 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001615 }
Auke Kok9a799d72007-09-15 14:07:45 -07001616 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001617 for (i = v_start; i < vectors; i++) {
1618 tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
1619 for (j = 0; j < tqpv; j++) {
1620 map_vector_to_txq(adapter, i, txr_idx);
1621 txr_idx++;
1622 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07001623 }
Auke Kok9a799d72007-09-15 14:07:45 -07001624 }
1625
Auke Kok9a799d72007-09-15 14:07:45 -07001626out:
Auke Kok9a799d72007-09-15 14:07:45 -07001627 return err;
1628}
1629
1630/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001631 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
1632 * @adapter: board private structure
1633 *
1634 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
1635 * interrupts from the kernel.
1636 **/
1637static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
1638{
1639 struct net_device *netdev = adapter->netdev;
1640 irqreturn_t (*handler)(int, void *);
1641 int i, vector, q_vectors, err;
Robert Olssoncb13fc22008-11-25 16:43:52 -08001642 int ri=0, ti=0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001643
1644 /* Decrement for Other and TCP Timer vectors */
1645 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1646
1647 /* Map the Tx/Rx rings to the vectors we were allotted. */
1648 err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
1649 if (err)
1650 goto out;
1651
1652#define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001653 (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
1654 &ixgbe_msix_clean_many)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001655 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001656 handler = SET_HANDLER(adapter->q_vector[vector]);
Robert Olssoncb13fc22008-11-25 16:43:52 -08001657
1658 if(handler == &ixgbe_msix_clean_rx) {
1659 sprintf(adapter->name[vector], "%s-%s-%d",
1660 netdev->name, "rx", ri++);
1661 }
1662 else if(handler == &ixgbe_msix_clean_tx) {
1663 sprintf(adapter->name[vector], "%s-%s-%d",
1664 netdev->name, "tx", ti++);
1665 }
1666 else
1667 sprintf(adapter->name[vector], "%s-%s-%d",
1668 netdev->name, "TxRx", vector);
1669
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001670 err = request_irq(adapter->msix_entries[vector].vector,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001671 handler, 0, adapter->name[vector],
Alexander Duyck7a921c92009-05-06 10:43:28 +00001672 adapter->q_vector[vector]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001673 if (err) {
1674 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001675 "request_irq failed for MSIX interrupt "
1676 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001677 goto free_queue_irqs;
1678 }
1679 }
1680
1681 sprintf(adapter->name[vector], "%s:lsc", netdev->name);
1682 err = request_irq(adapter->msix_entries[vector].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08001683 ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001684 if (err) {
1685 DPRINTK(PROBE, ERR,
1686 "request_irq for msix_lsc failed: %d\n", err);
1687 goto free_queue_irqs;
1688 }
1689
1690 return 0;
1691
1692free_queue_irqs:
1693 for (i = vector - 1; i >= 0; i--)
1694 free_irq(adapter->msix_entries[--vector].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001695 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001696 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1697 pci_disable_msix(adapter->pdev);
1698 kfree(adapter->msix_entries);
1699 adapter->msix_entries = NULL;
1700out:
1701 return err;
1702}
1703
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001704static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
1705{
Alexander Duyck7a921c92009-05-06 10:43:28 +00001706 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001707 u8 current_itr;
1708 u32 new_itr = q_vector->eitr;
1709 struct ixgbe_ring *rx_ring = &adapter->rx_ring[0];
1710 struct ixgbe_ring *tx_ring = &adapter->tx_ring[0];
1711
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001712 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001713 q_vector->tx_itr,
1714 tx_ring->total_packets,
1715 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001716 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001717 q_vector->rx_itr,
1718 rx_ring->total_packets,
1719 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001720
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001721 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001722
1723 switch (current_itr) {
1724 /* counts and packets in update_itr are dependent on these numbers */
1725 case lowest_latency:
1726 new_itr = 100000;
1727 break;
1728 case low_latency:
1729 new_itr = 20000; /* aka hwitr = ~200 */
1730 break;
1731 case bulk_latency:
1732 new_itr = 8000;
1733 break;
1734 default:
1735 break;
1736 }
1737
1738 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001739 /* do an exponential smoothing */
1740 new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001741
1742 /* save the algorithm value here, not the smoothed one */
1743 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001744
1745 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001746 }
1747
1748 return;
1749}
1750
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001751/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001752 * ixgbe_irq_enable - Enable default interrupt generation settings
1753 * @adapter: board private structure
1754 **/
1755static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter)
1756{
1757 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00001758
1759 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
David S. Miller6ab33d52008-11-20 16:44:00 -08001760 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
1761 mask |= IXGBE_EIMS_GPI_SDP1;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001762 if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00001763 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001764 mask |= IXGBE_EIMS_GPI_SDP1;
1765 mask |= IXGBE_EIMS_GPI_SDP2;
1766 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001767 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
1768 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
1769 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001770
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001771 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Nelson, Shannon835462f2009-04-27 22:42:54 +00001772 ixgbe_irq_enable_queues(adapter, ~0);
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08001773 IXGBE_WRITE_FLUSH(&adapter->hw);
1774}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001775
1776/**
1777 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07001778 * @irq: interrupt number
1779 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07001780 **/
1781static irqreturn_t ixgbe_intr(int irq, void *data)
1782{
1783 struct net_device *netdev = data;
1784 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1785 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001786 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07001787 u32 eicr;
1788
Don Skidmore54037502009-02-21 15:42:56 -08001789 /*
1790 * Workaround for silicon errata. Mask the interrupts
1791 * before the read of EICR.
1792 */
1793 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1794
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001795 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
1796 * therefore no explict interrupt disable is necessary */
1797 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001798 if (!eicr) {
1799 /* shared interrupt alert!
1800 * make sure interrupts are enabled because the read will
1801 * have disabled interrupts due to EIAM */
1802 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07001803 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07001804 }
Auke Kok9a799d72007-09-15 14:07:45 -07001805
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001806 if (eicr & IXGBE_EICR_LSC)
1807 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001808
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001809 if (hw->mac.type == ixgbe_mac_82599EB)
1810 ixgbe_check_sfp_event(adapter, eicr);
1811
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001812 ixgbe_check_fan_failure(adapter, eicr);
1813
Alexander Duyck7a921c92009-05-06 10:43:28 +00001814 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001815 adapter->tx_ring[0].total_packets = 0;
1816 adapter->tx_ring[0].total_bytes = 0;
1817 adapter->rx_ring[0].total_packets = 0;
1818 adapter->rx_ring[0].total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001819 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00001820 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07001821 }
1822
1823 return IRQ_HANDLED;
1824}
1825
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001826static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
1827{
1828 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1829
1830 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001831 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001832 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
1833 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
1834 q_vector->rxr_count = 0;
1835 q_vector->txr_count = 0;
1836 }
1837}
1838
Auke Kok9a799d72007-09-15 14:07:45 -07001839/**
1840 * ixgbe_request_irq - initialize interrupts
1841 * @adapter: board private structure
1842 *
1843 * Attempts to configure interrupts using the best available
1844 * capabilities of the hardware and kernel.
1845 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001846static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07001847{
1848 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001849 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07001850
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001851 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1852 err = ixgbe_request_msix_irqs(adapter);
1853 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001854 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001855 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001856 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08001857 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07001858 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001859 }
1860
Auke Kok9a799d72007-09-15 14:07:45 -07001861 if (err)
1862 DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err);
1863
Auke Kok9a799d72007-09-15 14:07:45 -07001864 return err;
1865}
1866
1867static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
1868{
1869 struct net_device *netdev = adapter->netdev;
1870
1871 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001872 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07001873
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001874 q_vectors = adapter->num_msix_vectors;
1875
1876 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07001877 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001878
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001879 i--;
1880 for (; i >= 0; i--) {
1881 free_irq(adapter->msix_entries[i].vector,
Alexander Duyck7a921c92009-05-06 10:43:28 +00001882 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001883 }
1884
1885 ixgbe_reset_q_vectors(adapter);
1886 } else {
1887 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07001888 }
1889}
1890
1891/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001892 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
1893 * @adapter: board private structure
1894 **/
1895static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
1896{
Nelson, Shannon835462f2009-04-27 22:42:54 +00001897 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
1898 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
1899 } else {
1900 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
1901 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001902 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001903 }
1904 IXGBE_WRITE_FLUSH(&adapter->hw);
1905 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1906 int i;
1907 for (i = 0; i < adapter->num_msix_vectors; i++)
1908 synchronize_irq(adapter->msix_entries[i].vector);
1909 } else {
1910 synchronize_irq(adapter->pdev->irq);
1911 }
1912}
1913
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00001914/**
Auke Kok9a799d72007-09-15 14:07:45 -07001915 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
1916 *
1917 **/
1918static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
1919{
Auke Kok9a799d72007-09-15 14:07:45 -07001920 struct ixgbe_hw *hw = &adapter->hw;
1921
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001922 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001923 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07001924
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001925 ixgbe_set_ivar(adapter, 0, 0, 0);
1926 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001927
1928 map_vector_to_rxq(adapter, 0, 0);
1929 map_vector_to_txq(adapter, 0, 0);
1930
1931 DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07001932}
1933
1934/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001935 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07001936 * @adapter: board private structure
1937 *
1938 * Configure the Tx unit of the MAC after a reset.
1939 **/
1940static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
1941{
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001942 u64 tdba;
Auke Kok9a799d72007-09-15 14:07:45 -07001943 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001944 u32 i, j, tdlen, txctrl;
Auke Kok9a799d72007-09-15 14:07:45 -07001945
1946 /* Setup the HW Tx Head and Tail descriptor pointers */
1947 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001948 struct ixgbe_ring *ring = &adapter->tx_ring[i];
1949 j = ring->reg_idx;
1950 tdba = ring->dma;
1951 tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001952 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j),
Yang Hongyang284901a2009-04-06 19:01:15 -07001953 (tdba & DMA_BIT_MASK(32)));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001954 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32));
1955 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen);
1956 IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0);
1957 IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0);
1958 adapter->tx_ring[i].head = IXGBE_TDH(j);
1959 adapter->tx_ring[i].tail = IXGBE_TDT(j);
Peter P Waskiewicz Jr84f62d42009-09-30 12:07:16 +00001960 /*
1961 * Disable Tx Head Writeback RO bit, since this hoses
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001962 * bookkeeping if things aren't delivered in order.
1963 */
Peter P Waskiewicz Jr84f62d42009-09-30 12:07:16 +00001964 switch (hw->mac.type) {
1965 case ixgbe_mac_82598EB:
1966 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j));
1967 break;
1968 case ixgbe_mac_82599EB:
1969 default:
1970 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j));
1971 break;
1972 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001973 txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
Peter P Waskiewicz Jr84f62d42009-09-30 12:07:16 +00001974 switch (hw->mac.type) {
1975 case ixgbe_mac_82598EB:
1976 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl);
1977 break;
1978 case ixgbe_mac_82599EB:
1979 default:
1980 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl);
1981 break;
1982 }
Auke Kok9a799d72007-09-15 14:07:45 -07001983 }
Don Skidmoreee5f7842009-11-06 12:56:20 +00001984
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001985 if (hw->mac.type == ixgbe_mac_82599EB) {
Don Skidmoreee5f7842009-11-06 12:56:20 +00001986 u32 rttdcs;
1987
1988 /* disable the arbiter while setting MTQC */
1989 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
1990 rttdcs |= IXGBE_RTTDCS_ARBDIS;
1991 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
1992
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001993 /* We enable 8 traffic classes, DCB only */
1994 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
1995 IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA |
1996 IXGBE_MTQC_8TC_8TQ));
Don Skidmoreee5f7842009-11-06 12:56:20 +00001997 else
1998 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
1999
2000 /* re-eable the arbiter */
2001 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2002 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002003 }
Auke Kok9a799d72007-09-15 14:07:45 -07002004}
2005
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002006#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002007
Yi Zoua6616b42009-08-06 13:05:23 +00002008static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
2009 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002010{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002011 u32 srrctl;
Yi Zoua6616b42009-08-06 13:05:23 +00002012 int index;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002013 struct ixgbe_ring_feature *feature = adapter->ring_feature;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002014
Yi Zoua6616b42009-08-06 13:05:23 +00002015 index = rx_ring->reg_idx;
2016 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
2017 unsigned long mask;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002018 mask = (unsigned long) feature[RING_F_RSS].mask;
Alexander Duyck3be1adf2008-08-30 00:29:10 -07002019 index = index & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002020 }
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002021 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
2022
2023 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2024 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
2025
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002026 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2027 IXGBE_SRRCTL_BSIZEHDR_MASK;
2028
Yi Zou6e455b892009-08-06 13:05:44 +00002029 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002030#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2031 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2032#else
2033 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2034#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002035 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002036 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002037 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2038 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002039 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002040 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002041
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002042 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
2043}
2044
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002045static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
2046{
2047 u32 mrqc = 0;
2048 int mask;
2049
2050 if (!(adapter->hw.mac.type == ixgbe_mac_82599EB))
2051 return mrqc;
2052
2053 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2054#ifdef CONFIG_IXGBE_DCB
2055 | IXGBE_FLAG_DCB_ENABLED
2056#endif
2057 );
2058
2059 switch (mask) {
2060 case (IXGBE_FLAG_RSS_ENABLED):
2061 mrqc = IXGBE_MRQC_RSSEN;
2062 break;
2063#ifdef CONFIG_IXGBE_DCB
2064 case (IXGBE_FLAG_DCB_ENABLED):
2065 mrqc = IXGBE_MRQC_RT8TCEN;
2066 break;
2067#endif /* CONFIG_IXGBE_DCB */
2068 default:
2069 break;
2070 }
2071
2072 return mrqc;
2073}
2074
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002075/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002076 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2077 * @adapter: address of board private structure
2078 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002079 **/
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002080static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002081{
2082 struct ixgbe_ring *rx_ring;
2083 struct ixgbe_hw *hw = &adapter->hw;
2084 int j;
2085 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002086 int rx_buf_len;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002087
2088 rx_ring = &adapter->rx_ring[index];
2089 j = rx_ring->reg_idx;
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002090 rx_buf_len = rx_ring->rx_buf_len;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002091 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j));
2092 rscctrl |= IXGBE_RSCCTL_RSCEN;
2093 /*
2094 * we must limit the number of descriptors so that the
2095 * total size of max desc * buf_len is not greater
2096 * than 65535
2097 */
2098 if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
2099#if (MAX_SKB_FRAGS > 16)
2100 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2101#elif (MAX_SKB_FRAGS > 8)
2102 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2103#elif (MAX_SKB_FRAGS > 4)
2104 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2105#else
2106 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2107#endif
2108 } else {
2109 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2110 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2111 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2112 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2113 else
2114 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2115 }
2116 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl);
2117}
2118
2119/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002120 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002121 * @adapter: board private structure
2122 *
2123 * Configure the Rx unit of the MAC after a reset.
2124 **/
2125static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
2126{
2127 u64 rdba;
2128 struct ixgbe_hw *hw = &adapter->hw;
Yi Zoua6616b42009-08-06 13:05:23 +00002129 struct ixgbe_ring *rx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07002130 struct net_device *netdev = adapter->netdev;
2131 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002132 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07002133 u32 rdlen, rxctrl, rxcsum;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002134 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
2135 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2136 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Auke Kok9a799d72007-09-15 14:07:45 -07002137 u32 fctrl, hlreg0;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002138 u32 reta = 0, mrqc = 0;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002139 u32 rdrxctl;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002140 int rx_buf_len;
Auke Kok9a799d72007-09-15 14:07:45 -07002141
2142 /* Decide whether to use packet split mode or not */
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002143 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07002144
2145 /* Set the RX buffer length according to the mode */
2146 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002147 rx_buf_len = IXGBE_RX_HDR_SIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002148 if (hw->mac.type == ixgbe_mac_82599EB) {
2149 /* PSRTYPE must be initialized in 82599 */
2150 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
2151 IXGBE_PSRTYPE_UDPHDR |
2152 IXGBE_PSRTYPE_IPV4HDR |
Yi Zoudfa12f02009-05-07 10:39:35 +00002153 IXGBE_PSRTYPE_IPV6HDR |
2154 IXGBE_PSRTYPE_L2HDR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002155 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype);
2156 }
Auke Kok9a799d72007-09-15 14:07:45 -07002157 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00002158 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00002159 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002160 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07002161 else
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002162 rx_buf_len = ALIGN(max_frame, 1024);
Auke Kok9a799d72007-09-15 14:07:45 -07002163 }
2164
2165 fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL);
2166 fctrl |= IXGBE_FCTRL_BAM;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002167 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002168 fctrl |= IXGBE_FCTRL_PMCF;
Auke Kok9a799d72007-09-15 14:07:45 -07002169 IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl);
2170
2171 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2172 if (adapter->netdev->mtu <= ETH_DATA_LEN)
2173 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
2174 else
2175 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Yi Zou63f39bd2009-05-17 12:34:35 +00002176#ifdef IXGBE_FCOE
Yi Zouf34c5c82009-08-14 12:42:17 +00002177 if (netdev->features & NETIF_F_FCOE_MTU)
Yi Zou63f39bd2009-05-17 12:34:35 +00002178 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
2179#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002180 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2181
Auke Kok9a799d72007-09-15 14:07:45 -07002182 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
2183 /* disable receives while setting up the descriptors */
2184 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2185 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
2186
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002187 /*
2188 * Setup the HW Rx Head and Tail Descriptor Pointers and
2189 * the Base and Length of the Rx Descriptor Ring
2190 */
Auke Kok9a799d72007-09-15 14:07:45 -07002191 for (i = 0; i < adapter->num_rx_queues; i++) {
Yi Zoua6616b42009-08-06 13:05:23 +00002192 rx_ring = &adapter->rx_ring[i];
2193 rdba = rx_ring->dma;
2194 j = rx_ring->reg_idx;
Yang Hongyang284901a2009-04-06 19:01:15 -07002195 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32)));
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002196 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32));
2197 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen);
2198 IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
2199 IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
Yi Zoua6616b42009-08-06 13:05:23 +00002200 rx_ring->head = IXGBE_RDH(j);
2201 rx_ring->tail = IXGBE_RDT(j);
2202 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002203
Yi Zou6e455b892009-08-06 13:05:44 +00002204 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
2205 rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED;
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00002206 else
2207 rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002208
Yi Zou63f39bd2009-05-17 12:34:35 +00002209#ifdef IXGBE_FCOE
Yi Zouf34c5c82009-08-14 12:42:17 +00002210 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00002211 struct ixgbe_ring_feature *f;
2212 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00002213 if ((i >= f->mask) && (i < f->mask + f->indices)) {
2214 rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
2215 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
2216 rx_ring->rx_buf_len =
2217 IXGBE_FCOE_JUMBO_FRAME_SIZE;
2218 }
Yi Zou63f39bd2009-05-17 12:34:35 +00002219 }
2220
2221#endif /* IXGBE_FCOE */
Yi Zoua6616b42009-08-06 13:05:23 +00002222 ixgbe_configure_srrctl(adapter, rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07002223 }
2224
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002225 if (hw->mac.type == ixgbe_mac_82598EB) {
2226 /*
2227 * For VMDq support of different descriptor types or
2228 * buffer sizes through the use of multiple SRRCTL
2229 * registers, RDRXCTL.MVMEN must be set to 1
2230 *
2231 * also, the manual doesn't mention it clearly but DCA hints
2232 * will only use queue 0's tags unless this bit is set. Side
2233 * effects of setting this bit are only that SRRCTL must be
2234 * fully programmed [0..15]
2235 */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002236 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2237 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
2238 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
Alexander Duyck2f90b862008-11-20 20:52:10 -08002239 }
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002240
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002241 /* Program MRQC for the distribution of queues */
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002242 mrqc = ixgbe_setup_mrqc(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002243
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002244 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Auke Kok9a799d72007-09-15 14:07:45 -07002245 /* Fill out redirection table */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002246 for (i = 0, j = 0; i < 128; i++, j++) {
2247 if (j == adapter->ring_feature[RING_F_RSS].indices)
2248 j = 0;
2249 /* reta = 4-byte sliding window of
2250 * 0x00..(indices-1)(indices-1)00..etc. */
2251 reta = (reta << 8) | (j * 0x11);
2252 if ((i & 3) == 3)
2253 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
Auke Kok9a799d72007-09-15 14:07:45 -07002254 }
2255
2256 /* Fill out hash function seeds */
2257 for (i = 0; i < 10; i++)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002258 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002259
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002260 if (hw->mac.type == ixgbe_mac_82598EB)
2261 mrqc |= IXGBE_MRQC_RSSEN;
Auke Kok9a799d72007-09-15 14:07:45 -07002262 /* Perform hash on these packet types */
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002263 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2264 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2265 | IXGBE_MRQC_RSS_FIELD_IPV4_UDP
2266 | IXGBE_MRQC_RSS_FIELD_IPV6
2267 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP
2268 | IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Auke Kok9a799d72007-09-15 14:07:45 -07002269 }
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002270 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002271
2272 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2273
2274 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED ||
2275 adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) {
2276 /* Disable indicating checksum in descriptor, enables
2277 * RSS hash */
2278 rxcsum |= IXGBE_RXCSUM_PCSD;
2279 }
2280 if (!(rxcsum & IXGBE_RXCSUM_PCSD)) {
2281 /* Enable IPv4 payload checksum for UDP fragments
2282 * if PCSD is not set */
2283 rxcsum |= IXGBE_RXCSUM_IPPCSE;
2284 }
2285
2286 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002287
2288 if (hw->mac.type == ixgbe_mac_82599EB) {
2289 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
2290 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002291 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002292 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
2293 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00002294
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00002295 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002296 /* Enable 82599 HW-RSC */
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002297 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002298 ixgbe_configure_rscctl(adapter, i);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002299
Alexander Duyckf8212f92009-04-27 22:42:37 +00002300 /* Disable RSC for ACK packets */
2301 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
2302 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
2303 }
Auke Kok9a799d72007-09-15 14:07:45 -07002304}
2305
Auke Kok9a799d72007-09-15 14:07:45 -07002306static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
2307{
2308 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002309 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002310
2311 /* add VID to filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002312 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002313}
2314
2315static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
2316{
2317 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002318 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002319
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002320 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2321 ixgbe_irq_disable(adapter);
2322
Auke Kok9a799d72007-09-15 14:07:45 -07002323 vlan_group_set_device(adapter->vlgrp, vid, NULL);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002324
2325 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2326 ixgbe_irq_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002327
2328 /* remove VID from filter table */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002329 hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false);
Auke Kok9a799d72007-09-15 14:07:45 -07002330}
2331
Don Skidmore068c89b2009-01-19 16:54:36 -08002332static void ixgbe_vlan_rx_register(struct net_device *netdev,
2333 struct vlan_group *grp)
2334{
2335 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2336 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002337 int i, j;
Don Skidmore068c89b2009-01-19 16:54:36 -08002338
2339 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2340 ixgbe_irq_disable(adapter);
2341 adapter->vlgrp = grp;
2342
2343 /*
2344 * For a DCB driver, always enable VLAN tag stripping so we can
2345 * still receive traffic from a DCB-enabled host even if we're
2346 * not in DCB mode.
2347 */
2348 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL);
Alexander Duyckdc63d372009-11-23 06:32:57 +00002349
2350 /* Disable CFI check */
2351 ctrl &= ~IXGBE_VLNCTRL_CFIEN;
2352
2353 /* enable VLAN tag stripping */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002354 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckdc63d372009-11-23 06:32:57 +00002355 ctrl |= IXGBE_VLNCTRL_VME;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002356 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002357 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckdc63d372009-11-23 06:32:57 +00002358 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002359 j = adapter->rx_ring[i].reg_idx;
2360 ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j));
2361 ctrl |= IXGBE_RXDCTL_VME;
2362 IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl);
2363 }
Don Skidmore068c89b2009-01-19 16:54:36 -08002364 }
Alexander Duyckdc63d372009-11-23 06:32:57 +00002365
2366 IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl);
2367
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002368 ixgbe_vlan_rx_add_vid(netdev, 0);
Don Skidmore068c89b2009-01-19 16:54:36 -08002369
2370 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2371 ixgbe_irq_enable(adapter);
2372}
2373
Auke Kok9a799d72007-09-15 14:07:45 -07002374static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
2375{
2376 ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp);
2377
2378 if (adapter->vlgrp) {
2379 u16 vid;
2380 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
2381 if (!vlan_group_get_device(adapter->vlgrp, vid))
2382 continue;
2383 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
2384 }
2385 }
2386}
2387
Christopher Leech2c5645c2008-08-26 04:27:02 -07002388static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq)
2389{
2390 struct dev_mc_list *mc_ptr;
2391 u8 *addr = *mc_addr_ptr;
2392 *vmdq = 0;
2393
2394 mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]);
2395 if (mc_ptr->next)
2396 *mc_addr_ptr = mc_ptr->next->dmi_addr;
2397 else
2398 *mc_addr_ptr = NULL;
2399
2400 return addr;
2401}
2402
Auke Kok9a799d72007-09-15 14:07:45 -07002403/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07002404 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07002405 * @netdev: network interface device structure
2406 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07002407 * The set_rx_method entry point is called whenever the unicast/multicast
2408 * address list or the network interface flags are updated. This routine is
2409 * responsible for configuring the hardware for proper unicast, multicast and
2410 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07002411 **/
Christopher Leech2c5645c2008-08-26 04:27:02 -07002412static void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07002413{
2414 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2415 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck3d016252008-08-26 18:30:04 -07002416 u32 fctrl, vlnctrl;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002417 u8 *addr_list = NULL;
2418 int addr_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002419
2420 /* Check for Promiscuous and All Multicast modes */
2421
2422 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
Alexander Duyck3d016252008-08-26 18:30:04 -07002423 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
Auke Kok9a799d72007-09-15 14:07:45 -07002424
2425 if (netdev->flags & IFF_PROMISC) {
Christopher Leech2c5645c2008-08-26 04:27:02 -07002426 hw->addr_ctrl.user_set_promisc = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002427 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck3d016252008-08-26 18:30:04 -07002428 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Auke Kok9a799d72007-09-15 14:07:45 -07002429 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07002430 if (netdev->flags & IFF_ALLMULTI) {
2431 fctrl |= IXGBE_FCTRL_MPE;
2432 fctrl &= ~IXGBE_FCTRL_UPE;
2433 } else {
2434 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
2435 }
Alexander Duyck3d016252008-08-26 18:30:04 -07002436 vlnctrl |= IXGBE_VLNCTRL_VFE;
Christopher Leech2c5645c2008-08-26 04:27:02 -07002437 hw->addr_ctrl.user_set_promisc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002438 }
2439
2440 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Alexander Duyck3d016252008-08-26 18:30:04 -07002441 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07002442
Christopher Leech2c5645c2008-08-26 04:27:02 -07002443 /* reprogram secondary unicast list */
Jiri Pirko31278e72009-06-17 01:12:19 +00002444 hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list);
Auke Kok9a799d72007-09-15 14:07:45 -07002445
Christopher Leech2c5645c2008-08-26 04:27:02 -07002446 /* reprogram multicast list */
2447 addr_count = netdev->mc_count;
2448 if (addr_count)
2449 addr_list = netdev->mc_list->dmi_addr;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002450 hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count,
2451 ixgbe_addr_list_itr);
Auke Kok9a799d72007-09-15 14:07:45 -07002452}
2453
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002454static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
2455{
2456 int q_idx;
2457 struct ixgbe_q_vector *q_vector;
2458 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2459
2460 /* legacy and MSI only use one vector */
2461 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2462 q_vectors = 1;
2463
2464 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002465 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002466 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002467 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002468 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2469 if (!q_vector->rxr_count || !q_vector->txr_count) {
2470 if (q_vector->txr_count == 1)
2471 napi->poll = &ixgbe_clean_txonly;
2472 else if (q_vector->rxr_count == 1)
2473 napi->poll = &ixgbe_clean_rxonly;
2474 }
2475 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002476
2477 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002478 }
2479}
2480
2481static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
2482{
2483 int q_idx;
2484 struct ixgbe_q_vector *q_vector;
2485 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2486
2487 /* legacy and MSI only use one vector */
2488 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2489 q_vectors = 1;
2490
2491 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002492 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002493 napi_disable(&q_vector->napi);
2494 }
2495}
2496
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002497#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002498/*
2499 * ixgbe_configure_dcb - Configure DCB hardware
2500 * @adapter: ixgbe adapter struct
2501 *
2502 * This is called by the driver on open to configure the DCB hardware.
2503 * This is also called by the gennetlink interface when reconfiguring
2504 * the DCB state.
2505 */
2506static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
2507{
2508 struct ixgbe_hw *hw = &adapter->hw;
2509 u32 txdctl, vlnctrl;
2510 int i, j;
2511
2512 ixgbe_dcb_check_config(&adapter->dcb_cfg);
2513 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG);
2514 ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG);
2515
2516 /* reconfigure the hardware */
2517 ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
2518
2519 for (i = 0; i < adapter->num_tx_queues; i++) {
2520 j = adapter->tx_ring[i].reg_idx;
2521 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
2522 /* PThresh workaround for Tx hang with DFP enabled. */
2523 txdctl |= 32;
2524 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2525 }
2526 /* Enable VLAN tag insert/strip */
2527 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002528 if (hw->mac.type == ixgbe_mac_82598EB) {
2529 vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE;
2530 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2531 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2532 } else if (hw->mac.type == ixgbe_mac_82599EB) {
2533 vlnctrl |= IXGBE_VLNCTRL_VFE;
2534 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
2535 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
2536 for (i = 0; i < adapter->num_rx_queues; i++) {
2537 j = adapter->rx_ring[i].reg_idx;
2538 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2539 vlnctrl |= IXGBE_RXDCTL_VME;
2540 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
2541 }
2542 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08002543 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
2544}
2545
2546#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002547static void ixgbe_configure(struct ixgbe_adapter *adapter)
2548{
2549 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002550 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07002551 int i;
2552
Christopher Leech2c5645c2008-08-26 04:27:02 -07002553 ixgbe_set_rx_mode(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002554
2555 ixgbe_restore_vlan(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08002556#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08002557 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Yi Zoub352e402009-11-06 12:55:38 +00002558 if (hw->mac.type == ixgbe_mac_82598EB)
2559 netif_set_gso_max_size(netdev, 32768);
2560 else
2561 netif_set_gso_max_size(netdev, 65536);
Alexander Duyck2f90b862008-11-20 20:52:10 -08002562 ixgbe_configure_dcb(adapter);
2563 } else {
2564 netif_set_gso_max_size(netdev, 65536);
2565 }
2566#else
2567 netif_set_gso_max_size(netdev, 65536);
2568#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002569
Yi Zoueacd73f2009-05-13 13:11:06 +00002570#ifdef IXGBE_FCOE
2571 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
2572 ixgbe_configure_fcoe(adapter);
2573
2574#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002575 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2576 for (i = 0; i < adapter->num_tx_queues; i++)
2577 adapter->tx_ring[i].atr_sample_rate =
2578 adapter->atr_sample_rate;
2579 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
2580 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
2581 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
2582 }
2583
Auke Kok9a799d72007-09-15 14:07:45 -07002584 ixgbe_configure_tx(adapter);
2585 ixgbe_configure_rx(adapter);
2586 for (i = 0; i < adapter->num_rx_queues; i++)
2587 ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i],
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002588 (adapter->rx_ring[i].count - 1));
Auke Kok9a799d72007-09-15 14:07:45 -07002589}
2590
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002591static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2592{
2593 switch (hw->phy.type) {
2594 case ixgbe_phy_sfp_avago:
2595 case ixgbe_phy_sfp_ftl:
2596 case ixgbe_phy_sfp_intel:
2597 case ixgbe_phy_sfp_unknown:
2598 case ixgbe_phy_tw_tyco:
2599 case ixgbe_phy_tw_unknown:
2600 return true;
2601 default:
2602 return false;
2603 }
2604}
2605
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002606/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002607 * ixgbe_sfp_link_config - set up SFP+ link
2608 * @adapter: pointer to private adapter struct
2609 **/
2610static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
2611{
2612 struct ixgbe_hw *hw = &adapter->hw;
2613
2614 if (hw->phy.multispeed_fiber) {
2615 /*
2616 * In multispeed fiber setups, the device may not have
2617 * had a physical connection when the driver loaded.
2618 * If that's the case, the initial link configuration
2619 * couldn't get the MAC into 10G or 1G mode, so we'll
2620 * never have a link status change interrupt fire.
2621 * We need to try and force an autonegotiation
2622 * session, then bring up link.
2623 */
2624 hw->mac.ops.setup_sfp(hw);
2625 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
2626 schedule_work(&adapter->multispeed_fiber_task);
2627 } else {
2628 /*
2629 * Direct Attach Cu and non-multispeed fiber modules
2630 * still need to be configured properly prior to
2631 * attempting link.
2632 */
2633 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
2634 schedule_work(&adapter->sfp_config_module_task);
2635 }
2636}
2637
2638/**
2639 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002640 * @hw: pointer to private hardware struct
2641 *
2642 * Returns 0 on success, negative on failure
2643 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002644static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002645{
2646 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00002647 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002648 u32 ret = IXGBE_ERR_LINK_SETUP;
2649
2650 if (hw->mac.ops.check_link)
2651 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2652
2653 if (ret)
2654 goto link_cfg_out;
2655
2656 if (hw->mac.ops.get_link_capabilities)
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00002657 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002658 if (ret)
2659 goto link_cfg_out;
2660
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00002661 if (hw->mac.ops.setup_link)
2662 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002663link_cfg_out:
2664 return ret;
2665}
2666
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002667#define IXGBE_MAX_RX_DESC_POLL 10
2668static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2669 int rxr)
2670{
2671 int j = adapter->rx_ring[rxr].reg_idx;
2672 int k;
2673
2674 for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) {
2675 if (IXGBE_READ_REG(&adapter->hw,
2676 IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE)
2677 break;
2678 else
2679 msleep(1);
2680 }
2681 if (k >= IXGBE_MAX_RX_DESC_POLL) {
2682 DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d "
2683 "not set within the polling period\n", rxr);
2684 }
2685 ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr],
2686 (adapter->rx_ring[rxr].count - 1));
2687}
2688
Auke Kok9a799d72007-09-15 14:07:45 -07002689static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
2690{
2691 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07002692 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002693 int i, j = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002694 int num_rx_rings = adapter->num_rx_queues;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002695 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002696 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002697 u32 txdctl, rxdctl, mhadd;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002698 u32 dmatxctl;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002699 u32 gpie;
Auke Kok9a799d72007-09-15 14:07:45 -07002700
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08002701 ixgbe_get_hw_control(adapter);
2702
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002703 if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) ||
2704 (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) {
Auke Kok9a799d72007-09-15 14:07:45 -07002705 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2706 gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002707 IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD);
Auke Kok9a799d72007-09-15 14:07:45 -07002708 } else {
2709 /* MSI only */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002710 gpie = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002711 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002712 /* XXX: to interrupt immediately for EICS writes, enable this */
2713 /* gpie |= IXGBE_GPIE_EIMEN; */
2714 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2715 }
2716
2717 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
2718 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
2719 * specifically only auto mask tx and rx interrupts */
2720 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07002721 }
2722
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002723 /* Enable fan failure interrupt if media type is copper */
2724 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2725 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2726 gpie |= IXGBE_SDP1_GPIEN;
2727 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2728 }
2729
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002730 if (hw->mac.type == ixgbe_mac_82599EB) {
2731 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
2732 gpie |= IXGBE_SDP1_GPIEN;
2733 gpie |= IXGBE_SDP2_GPIEN;
2734 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
2735 }
2736
Yi Zou63f39bd2009-05-17 12:34:35 +00002737#ifdef IXGBE_FCOE
2738 /* adjust max frame to be able to do baby jumbo for FCoE */
Yi Zouf34c5c82009-08-14 12:42:17 +00002739 if ((netdev->features & NETIF_F_FCOE_MTU) &&
Yi Zou63f39bd2009-05-17 12:34:35 +00002740 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
2741 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
2742
2743#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07002744 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
Auke Kok9a799d72007-09-15 14:07:45 -07002745 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
2746 mhadd &= ~IXGBE_MHADD_MFS_MASK;
2747 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
2748
2749 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
2750 }
2751
2752 for (i = 0; i < adapter->num_tx_queues; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002753 j = adapter->tx_ring[i].reg_idx;
2754 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07002755 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2756 txdctl |= (8 << 16);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002757 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
2758 }
2759
2760 if (hw->mac.type == ixgbe_mac_82599EB) {
2761 /* DMATXCTL.EN must be set after all Tx queue config is done */
2762 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2763 dmatxctl |= IXGBE_DMATXCTL_TE;
2764 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2765 }
2766 for (i = 0; i < adapter->num_tx_queues; i++) {
2767 j = adapter->tx_ring[i].reg_idx;
2768 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
Auke Kok9a799d72007-09-15 14:07:45 -07002769 txdctl |= IXGBE_TXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002770 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002771 }
2772
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002773 for (i = 0; i < num_rx_rings; i++) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002774 j = adapter->rx_ring[i].reg_idx;
2775 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
2776 /* enable PTHRESH=32 descriptors (half the internal cache)
2777 * and HTHRESH=0 descriptors (to minimize latency on fetch),
2778 * this also removes a pesky rx_no_buffer_count increment */
2779 rxdctl |= 0x0020;
Auke Kok9a799d72007-09-15 14:07:45 -07002780 rxdctl |= IXGBE_RXDCTL_ENABLE;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002781 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002782 if (hw->mac.type == ixgbe_mac_82599EB)
2783 ixgbe_rx_desc_queue_enable(adapter, i);
Auke Kok9a799d72007-09-15 14:07:45 -07002784 }
2785 /* enable all receives */
2786 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002787 if (hw->mac.type == ixgbe_mac_82598EB)
2788 rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN);
2789 else
2790 rxdctl |= IXGBE_RXCTRL_RXEN;
2791 hw->mac.ops.enable_rx_dma(hw, rxdctl);
Auke Kok9a799d72007-09-15 14:07:45 -07002792
2793 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
2794 ixgbe_configure_msix(adapter);
2795 else
2796 ixgbe_configure_msi_and_legacy(adapter);
2797
2798 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002799 ixgbe_napi_enable_all(adapter);
2800
2801 /* clear any pending interrupts, may auto mask */
2802 IXGBE_READ_REG(hw, IXGBE_EICR);
2803
Auke Kok9a799d72007-09-15 14:07:45 -07002804 ixgbe_irq_enable(adapter);
2805
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002806 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00002807 * If this adapter has a fan, check to see if we had a failure
2808 * before we enabled the interrupt.
2809 */
2810 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
2811 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2812 if (esdp & IXGBE_ESDP_SDP1)
2813 DPRINTK(DRV, CRIT,
2814 "Fan has stopped, replace the adapter\n");
2815 }
2816
2817 /*
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002818 * For hot-pluggable SFP+ devices, a new SFP+ module may have
Don Skidmore19343de2009-07-02 12:50:31 +00002819 * arrived before interrupts were enabled but after probe. Such
2820 * devices wouldn't have their type identified yet. We need to
2821 * kick off the SFP+ module setup first, then try to bring up link.
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002822 * If we're not hot-pluggable SFP+, we just need to configure link
2823 * and bring it up.
2824 */
Don Skidmore19343de2009-07-02 12:50:31 +00002825 if (hw->phy.type == ixgbe_phy_unknown) {
2826 err = hw->phy.ops.identify(hw);
2827 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore5da43c12009-07-02 12:50:52 +00002828 /*
2829 * Take the device down and schedule the sfp tasklet
2830 * which will unregister_netdev and log it.
2831 */
Don Skidmore19343de2009-07-02 12:50:31 +00002832 ixgbe_down(adapter);
Don Skidmore5da43c12009-07-02 12:50:52 +00002833 schedule_work(&adapter->sfp_config_module_task);
Don Skidmore19343de2009-07-02 12:50:31 +00002834 return err;
2835 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002836 }
2837
2838 if (ixgbe_is_sfp(hw)) {
2839 ixgbe_sfp_link_config(adapter);
2840 } else {
2841 err = ixgbe_non_sfp_link_config(hw);
2842 if (err)
2843 DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err);
2844 }
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08002845
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002846 for (i = 0; i < adapter->num_tx_queues; i++)
2847 set_bit(__IXGBE_FDIR_INIT_DONE,
2848 &(adapter->tx_ring[i].reinit_state));
2849
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08002850 /* enable transmits */
2851 netif_tx_start_all_queues(netdev);
2852
Auke Kok9a799d72007-09-15 14:07:45 -07002853 /* bring the link up in the watchdog, this could race with our first
2854 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002855 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2856 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07002857 mod_timer(&adapter->watchdog_timer, jiffies);
2858 return 0;
2859}
2860
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08002861void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
2862{
2863 WARN_ON(in_interrupt());
2864 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
2865 msleep(1);
2866 ixgbe_down(adapter);
2867 ixgbe_up(adapter);
2868 clear_bit(__IXGBE_RESETTING, &adapter->state);
2869}
2870
Auke Kok9a799d72007-09-15 14:07:45 -07002871int ixgbe_up(struct ixgbe_adapter *adapter)
2872{
2873 /* hardware has been reset, we need to reload some things */
2874 ixgbe_configure(adapter);
2875
2876 return ixgbe_up_complete(adapter);
2877}
2878
2879void ixgbe_reset(struct ixgbe_adapter *adapter)
2880{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002881 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07002882 int err;
2883
2884 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002885 switch (err) {
2886 case 0:
2887 case IXGBE_ERR_SFP_NOT_PRESENT:
2888 break;
2889 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
2890 dev_err(&adapter->pdev->dev, "master disable timed out\n");
2891 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00002892 case IXGBE_ERR_EEPROM_VERSION:
2893 /* We are running on a pre-production device, log a warning */
2894 dev_warn(&adapter->pdev->dev, "This device is a pre-production "
2895 "adapter/LOM. Please be aware there may be issues "
2896 "associated with your hardware. If you are "
2897 "experiencing problems please contact your Intel or "
2898 "hardware representative who provided you with this "
2899 "hardware.\n");
2900 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00002901 default:
2902 dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err);
2903 }
Auke Kok9a799d72007-09-15 14:07:45 -07002904
2905 /* reprogram the RAR[0] in case user changed it. */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07002906 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07002907}
2908
Auke Kok9a799d72007-09-15 14:07:45 -07002909/**
2910 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
2911 * @adapter: board private structure
2912 * @rx_ring: ring to free buffers from
2913 **/
2914static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002915 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002916{
2917 struct pci_dev *pdev = adapter->pdev;
2918 unsigned long size;
2919 unsigned int i;
2920
2921 /* Free all the Rx ring sk_buffs */
2922
2923 for (i = 0; i < rx_ring->count; i++) {
2924 struct ixgbe_rx_buffer *rx_buffer_info;
2925
2926 rx_buffer_info = &rx_ring->rx_buffer_info[i];
2927 if (rx_buffer_info->dma) {
2928 pci_unmap_single(pdev, rx_buffer_info->dma,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002929 rx_ring->rx_buf_len,
2930 PCI_DMA_FROMDEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07002931 rx_buffer_info->dma = 0;
2932 }
2933 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00002934 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07002935 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002936 do {
2937 struct sk_buff *this = skb;
2938 skb = skb->prev;
2939 dev_kfree_skb(this);
2940 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002941 }
2942 if (!rx_buffer_info->page)
2943 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00002944 if (rx_buffer_info->page_dma) {
2945 pci_unmap_page(pdev, rx_buffer_info->page_dma,
2946 PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
2947 rx_buffer_info->page_dma = 0;
2948 }
Auke Kok9a799d72007-09-15 14:07:45 -07002949 put_page(rx_buffer_info->page);
2950 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07002951 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002952 }
2953
2954 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
2955 memset(rx_ring->rx_buffer_info, 0, size);
2956
2957 /* Zero out the descriptor ring */
2958 memset(rx_ring->desc, 0, rx_ring->size);
2959
2960 rx_ring->next_to_clean = 0;
2961 rx_ring->next_to_use = 0;
2962
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002963 if (rx_ring->head)
2964 writel(0, adapter->hw.hw_addr + rx_ring->head);
2965 if (rx_ring->tail)
2966 writel(0, adapter->hw.hw_addr + rx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07002967}
2968
2969/**
2970 * ixgbe_clean_tx_ring - Free Tx Buffers
2971 * @adapter: board private structure
2972 * @tx_ring: ring to be cleaned
2973 **/
2974static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07002975 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07002976{
2977 struct ixgbe_tx_buffer *tx_buffer_info;
2978 unsigned long size;
2979 unsigned int i;
2980
2981 /* Free all the Tx ring sk_buffs */
2982
2983 for (i = 0; i < tx_ring->count; i++) {
2984 tx_buffer_info = &tx_ring->tx_buffer_info[i];
2985 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
2986 }
2987
2988 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
2989 memset(tx_ring->tx_buffer_info, 0, size);
2990
2991 /* Zero out the descriptor ring */
2992 memset(tx_ring->desc, 0, tx_ring->size);
2993
2994 tx_ring->next_to_use = 0;
2995 tx_ring->next_to_clean = 0;
2996
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00002997 if (tx_ring->head)
2998 writel(0, adapter->hw.hw_addr + tx_ring->head);
2999 if (tx_ring->tail)
3000 writel(0, adapter->hw.hw_addr + tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07003001}
3002
3003/**
Auke Kok9a799d72007-09-15 14:07:45 -07003004 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
3005 * @adapter: board private structure
3006 **/
3007static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
3008{
3009 int i;
3010
3011 for (i = 0; i < adapter->num_rx_queues; i++)
3012 ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]);
3013}
3014
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003015/**
3016 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
3017 * @adapter: board private structure
3018 **/
3019static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
3020{
3021 int i;
3022
3023 for (i = 0; i < adapter->num_tx_queues; i++)
3024 ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]);
3025}
3026
Auke Kok9a799d72007-09-15 14:07:45 -07003027void ixgbe_down(struct ixgbe_adapter *adapter)
3028{
3029 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003030 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003031 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003032 u32 txdctl;
3033 int i, j;
Auke Kok9a799d72007-09-15 14:07:45 -07003034
3035 /* signal that we are down to the interrupt handler */
3036 set_bit(__IXGBE_DOWN, &adapter->state);
3037
3038 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003039 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3040 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07003041
3042 netif_tx_disable(netdev);
3043
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003044 IXGBE_WRITE_FLUSH(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07003045 msleep(10);
3046
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003047 netif_tx_stop_all_queues(netdev);
3048
Auke Kok9a799d72007-09-15 14:07:45 -07003049 ixgbe_irq_disable(adapter);
3050
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003051 ixgbe_napi_disable_all(adapter);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003052
Don Skidmore0a1f87c2009-09-18 09:45:43 +00003053 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3054 del_timer_sync(&adapter->sfp_timer);
Auke Kok9a799d72007-09-15 14:07:45 -07003055 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003056 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07003057
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003058 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3059 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3060 cancel_work_sync(&adapter->fdir_reinit_task);
3061
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003062 /* disable transmits in the hardware now that interrupts are off */
3063 for (i = 0; i < adapter->num_tx_queues; i++) {
3064 j = adapter->tx_ring[i].reg_idx;
3065 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
3066 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
3067 (txdctl & ~IXGBE_TXDCTL_ENABLE));
3068 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00003069 /* Disable the Tx DMA engine on 82599 */
3070 if (hw->mac.type == ixgbe_mac_82599EB)
3071 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
3072 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
3073 ~IXGBE_DMATXCTL_TE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07003074
Auke Kok9a799d72007-09-15 14:07:45 -07003075 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07003076
Paul Larson6f4a0e42008-06-24 17:00:56 -07003077 if (!pci_channel_offline(adapter->pdev))
3078 ixgbe_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003079 ixgbe_clean_all_tx_rings(adapter);
3080 ixgbe_clean_all_rx_rings(adapter);
3081
Jeff Garzik5dd2d332008-10-16 05:09:31 -04003082#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07003083 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00003084 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07003085#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003086}
3087
Auke Kok9a799d72007-09-15 14:07:45 -07003088/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003089 * ixgbe_poll - NAPI Rx polling callback
3090 * @napi: structure for representing this polling device
3091 * @budget: how many packets driver is allowed to clean
3092 *
3093 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07003094 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003095static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07003096{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00003097 struct ixgbe_q_vector *q_vector =
3098 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003099 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00003100 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003101
Jeff Garzik5dd2d332008-10-16 05:09:31 -04003102#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08003103 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
3104 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
3105 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
3106 }
3107#endif
3108
Alexander Duyckfe49f042009-06-04 16:00:09 +00003109 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring);
Herbert Xu78b6f4c2009-01-18 21:49:45 -08003110 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07003111
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00003112 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08003113 work_done = budget;
3114
David S. Miller53e52c72008-01-07 21:06:12 -08003115 /* If budget not fully consumed, exit the polling mode */
3116 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08003117 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00003118 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08003119 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003120 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00003121 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003122 }
Auke Kok9a799d72007-09-15 14:07:45 -07003123 return work_done;
3124}
3125
3126/**
3127 * ixgbe_tx_timeout - Respond to a Tx Hang
3128 * @netdev: network interface device structure
3129 **/
3130static void ixgbe_tx_timeout(struct net_device *netdev)
3131{
3132 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3133
3134 /* Do the reset outside of interrupt context */
3135 schedule_work(&adapter->reset_task);
3136}
3137
3138static void ixgbe_reset_task(struct work_struct *work)
3139{
3140 struct ixgbe_adapter *adapter;
3141 adapter = container_of(work, struct ixgbe_adapter, reset_task);
3142
Alexander Duyck2f90b862008-11-20 20:52:10 -08003143 /* If we're already down or resetting, just bail */
3144 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
3145 test_bit(__IXGBE_RESETTING, &adapter->state))
3146 return;
3147
Auke Kok9a799d72007-09-15 14:07:45 -07003148 adapter->tx_timeout_count++;
3149
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003150 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003151}
3152
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003153#ifdef CONFIG_IXGBE_DCB
3154static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003155{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003156 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003157 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003158
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003159 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
3160 return ret;
3161
3162 f->mask = 0x7 << 3;
3163 adapter->num_rx_queues = f->indices;
3164 adapter->num_tx_queues = f->indices;
3165 ret = true;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003166
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003167 return ret;
3168}
3169#endif
3170
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003171/**
3172 * ixgbe_set_rss_queues: Allocate queues for RSS
3173 * @adapter: board private structure to initialize
3174 *
3175 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
3176 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
3177 *
3178 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003179static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
3180{
3181 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003182 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003183
3184 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003185 f->mask = 0xF;
3186 adapter->num_rx_queues = f->indices;
3187 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003188 ret = true;
3189 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003190 ret = false;
3191 }
3192
3193 return ret;
3194}
3195
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003196/**
3197 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
3198 * @adapter: board private structure to initialize
3199 *
3200 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
3201 * to the original CPU that initiated the Tx session. This runs in addition
3202 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
3203 * Rx load across CPUs using RSS.
3204 *
3205 **/
3206static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
3207{
3208 bool ret = false;
3209 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
3210
3211 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
3212 f_fdir->mask = 0;
3213
3214 /* Flow Director must have RSS enabled */
3215 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3216 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3217 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
3218 adapter->num_tx_queues = f_fdir->indices;
3219 adapter->num_rx_queues = f_fdir->indices;
3220 ret = true;
3221 } else {
3222 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3223 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3224 }
3225 return ret;
3226}
3227
Yi Zou0331a832009-05-17 12:33:52 +00003228#ifdef IXGBE_FCOE
3229/**
3230 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
3231 * @adapter: board private structure to initialize
3232 *
3233 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
3234 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
3235 * rx queues out of the max number of rx queues, instead, it is used as the
3236 * index of the first rx queue used by FCoE.
3237 *
3238 **/
3239static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
3240{
3241 bool ret = false;
3242 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3243
3244 f->indices = min((int)num_online_cpus(), f->indices);
3245 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003246 adapter->num_rx_queues = 1;
3247 adapter->num_tx_queues = 1;
Yi Zou0331a832009-05-17 12:33:52 +00003248#ifdef CONFIG_IXGBE_DCB
3249 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003250 DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n");
Yi Zou0331a832009-05-17 12:33:52 +00003251 ixgbe_set_dcb_queues(adapter);
3252 }
3253#endif
3254 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003255 DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n");
Yi Zou8faa2a72009-07-09 02:29:50 +00003256 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3257 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
3258 ixgbe_set_fdir_queues(adapter);
3259 else
3260 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00003261 }
3262 /* adding FCoE rx rings to the end */
3263 f->mask = adapter->num_rx_queues;
3264 adapter->num_rx_queues += f->indices;
Yi Zou8de8b2e2009-09-03 14:55:50 +00003265 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00003266
3267 ret = true;
3268 }
3269
3270 return ret;
3271}
3272
3273#endif /* IXGBE_FCOE */
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003274/*
3275 * ixgbe_set_num_queues: Allocate queues for device, feature dependant
3276 * @adapter: board private structure to initialize
3277 *
3278 * This is the top level queue allocation routine. The order here is very
3279 * important, starting with the "most" number of features turned on at once,
3280 * and ending with the smallest set of features. This way large combinations
3281 * can be allocated if they're turned on, and smaller combinations are the
3282 * fallthrough conditions.
3283 *
3284 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003285static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
3286{
Yi Zou0331a832009-05-17 12:33:52 +00003287#ifdef IXGBE_FCOE
3288 if (ixgbe_set_fcoe_queues(adapter))
3289 goto done;
3290
3291#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003292#ifdef CONFIG_IXGBE_DCB
3293 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003294 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003295
3296#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003297 if (ixgbe_set_fdir_queues(adapter))
3298 goto done;
3299
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003300 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07003301 goto done;
3302
3303 /* fallback to base case */
3304 adapter->num_rx_queues = 1;
3305 adapter->num_tx_queues = 1;
3306
3307done:
3308 /* Notify the stack of the (possibly) reduced Tx Queue count. */
3309 adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003310}
3311
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003312static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003313 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003314{
3315 int err, vector_threshold;
3316
3317 /* We'll want at least 3 (vector_threshold):
3318 * 1) TxQ[0] Cleanup
3319 * 2) RxQ[0] Cleanup
3320 * 3) Other (Link Status Change, etc.)
3321 * 4) TCP Timer (optional)
3322 */
3323 vector_threshold = MIN_MSIX_COUNT;
3324
3325 /* The more we get, the more we will assign to Tx/Rx Cleanup
3326 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
3327 * Right now, we simply care about how many we'll get; we'll
3328 * set them up later while requesting irq's.
3329 */
3330 while (vectors >= vector_threshold) {
3331 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003332 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003333 if (!err) /* Success in acquiring all requested vectors. */
3334 break;
3335 else if (err < 0)
3336 vectors = 0; /* Nasty failure, quit now */
3337 else /* err == number of vectors we should try again with */
3338 vectors = err;
3339 }
3340
3341 if (vectors < vector_threshold) {
3342 /* Can't allocate enough MSI-X interrupts? Oh well.
3343 * This just means we'll go with either a single MSI
3344 * vector or fall back to legacy interrupts.
3345 */
3346 DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n");
3347 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3348 kfree(adapter->msix_entries);
3349 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003350 } else {
3351 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08003352 /*
3353 * Adjust for only the vectors we'll use, which is minimum
3354 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
3355 * vectors we were allocated.
3356 */
3357 adapter->num_msix_vectors = min(vectors,
3358 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003359 }
3360}
3361
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003362/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003363 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003364 * @adapter: board private structure to initialize
3365 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003366 * Cache the descriptor ring offsets for RSS to the assigned rings.
3367 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003368 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003369static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003370{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003371 int i;
3372 bool ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003373
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003374 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
3375 for (i = 0; i < adapter->num_rx_queues; i++)
3376 adapter->rx_ring[i].reg_idx = i;
3377 for (i = 0; i < adapter->num_tx_queues; i++)
3378 adapter->tx_ring[i].reg_idx = i;
3379 ret = true;
3380 } else {
3381 ret = false;
3382 }
3383
3384 return ret;
3385}
3386
3387#ifdef CONFIG_IXGBE_DCB
3388/**
3389 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
3390 * @adapter: board private structure to initialize
3391 *
3392 * Cache the descriptor ring offsets for DCB to the assigned rings.
3393 *
3394 **/
3395static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
3396{
3397 int i;
3398 bool ret = false;
3399 int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
3400
3401 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
3402 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyck2f90b862008-11-20 20:52:10 -08003403 /* the number of queues is assumed to be symmetric */
3404 for (i = 0; i < dcb_i; i++) {
3405 adapter->rx_ring[i].reg_idx = i << 3;
3406 adapter->tx_ring[i].reg_idx = i << 2;
3407 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003408 ret = true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003409 } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
PJ Waskiewiczf92ef202009-04-16 15:00:20 +00003410 if (dcb_i == 8) {
3411 /*
3412 * Tx TC0 starts at: descriptor queue 0
3413 * Tx TC1 starts at: descriptor queue 32
3414 * Tx TC2 starts at: descriptor queue 64
3415 * Tx TC3 starts at: descriptor queue 80
3416 * Tx TC4 starts at: descriptor queue 96
3417 * Tx TC5 starts at: descriptor queue 104
3418 * Tx TC6 starts at: descriptor queue 112
3419 * Tx TC7 starts at: descriptor queue 120
3420 *
3421 * Rx TC0-TC7 are offset by 16 queues each
3422 */
3423 for (i = 0; i < 3; i++) {
3424 adapter->tx_ring[i].reg_idx = i << 5;
3425 adapter->rx_ring[i].reg_idx = i << 4;
3426 }
3427 for ( ; i < 5; i++) {
3428 adapter->tx_ring[i].reg_idx =
3429 ((i + 2) << 4);
3430 adapter->rx_ring[i].reg_idx = i << 4;
3431 }
3432 for ( ; i < dcb_i; i++) {
3433 adapter->tx_ring[i].reg_idx =
3434 ((i + 8) << 3);
3435 adapter->rx_ring[i].reg_idx = i << 4;
3436 }
3437
3438 ret = true;
3439 } else if (dcb_i == 4) {
3440 /*
3441 * Tx TC0 starts at: descriptor queue 0
3442 * Tx TC1 starts at: descriptor queue 64
3443 * Tx TC2 starts at: descriptor queue 96
3444 * Tx TC3 starts at: descriptor queue 112
3445 *
3446 * Rx TC0-TC3 are offset by 32 queues each
3447 */
3448 adapter->tx_ring[0].reg_idx = 0;
3449 adapter->tx_ring[1].reg_idx = 64;
3450 adapter->tx_ring[2].reg_idx = 96;
3451 adapter->tx_ring[3].reg_idx = 112;
3452 for (i = 0 ; i < dcb_i; i++)
3453 adapter->rx_ring[i].reg_idx = i << 5;
3454
3455 ret = true;
3456 } else {
3457 ret = false;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003458 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003459 } else {
3460 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003461 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003462 } else {
3463 ret = false;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003464 }
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003465
3466 return ret;
3467}
3468#endif
3469
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003470/**
3471 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
3472 * @adapter: board private structure to initialize
3473 *
3474 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
3475 *
3476 **/
3477static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
3478{
3479 int i;
3480 bool ret = false;
3481
3482 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
3483 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3484 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
3485 for (i = 0; i < adapter->num_rx_queues; i++)
3486 adapter->rx_ring[i].reg_idx = i;
3487 for (i = 0; i < adapter->num_tx_queues; i++)
3488 adapter->tx_ring[i].reg_idx = i;
3489 ret = true;
3490 }
3491
3492 return ret;
3493}
3494
Yi Zou0331a832009-05-17 12:33:52 +00003495#ifdef IXGBE_FCOE
3496/**
3497 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
3498 * @adapter: board private structure to initialize
3499 *
3500 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
3501 *
3502 */
3503static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
3504{
Yi Zou8de8b2e2009-09-03 14:55:50 +00003505 int i, fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00003506 bool ret = false;
3507 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
3508
3509 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
3510#ifdef CONFIG_IXGBE_DCB
3511 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Yi Zou8de8b2e2009-09-03 14:55:50 +00003512 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
3513
Yi Zou0331a832009-05-17 12:33:52 +00003514 ixgbe_cache_ring_dcb(adapter);
Yi Zou8de8b2e2009-09-03 14:55:50 +00003515 /* find out queues in TC for FCoE */
3516 fcoe_rx_i = adapter->rx_ring[fcoe->tc].reg_idx + 1;
3517 fcoe_tx_i = adapter->tx_ring[fcoe->tc].reg_idx + 1;
3518 /*
3519 * In 82599, the number of Tx queues for each traffic
3520 * class for both 8-TC and 4-TC modes are:
3521 * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7
3522 * 8 TCs: 32 32 16 16 8 8 8 8
3523 * 4 TCs: 64 64 32 32
3524 * We have max 8 queues for FCoE, where 8 the is
3525 * FCoE redirection table size. If TC for FCoE is
3526 * less than or equal to TC3, we have enough queues
3527 * to add max of 8 queues for FCoE, so we start FCoE
3528 * tx descriptor from the next one, i.e., reg_idx + 1.
3529 * If TC for FCoE is above TC3, implying 8 TC mode,
3530 * and we need 8 for FCoE, we have to take all queues
3531 * in that traffic class for FCoE.
3532 */
3533 if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3))
3534 fcoe_tx_i--;
Yi Zou0331a832009-05-17 12:33:52 +00003535 }
3536#endif /* CONFIG_IXGBE_DCB */
3537 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Yi Zou8faa2a72009-07-09 02:29:50 +00003538 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
3539 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
3540 ixgbe_cache_ring_fdir(adapter);
3541 else
3542 ixgbe_cache_ring_rss(adapter);
3543
Yi Zou8de8b2e2009-09-03 14:55:50 +00003544 fcoe_rx_i = f->mask;
3545 fcoe_tx_i = f->mask;
Yi Zou0331a832009-05-17 12:33:52 +00003546 }
Yi Zou8de8b2e2009-09-03 14:55:50 +00003547 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
3548 adapter->rx_ring[f->mask + i].reg_idx = fcoe_rx_i;
3549 adapter->tx_ring[f->mask + i].reg_idx = fcoe_tx_i;
3550 }
Yi Zou0331a832009-05-17 12:33:52 +00003551 ret = true;
3552 }
3553 return ret;
3554}
3555
3556#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003557/**
3558 * ixgbe_cache_ring_register - Descriptor ring to register mapping
3559 * @adapter: board private structure to initialize
3560 *
3561 * Once we know the feature-set enabled for the device, we'll cache
3562 * the register offset the descriptor ring is assigned to.
3563 *
3564 * Note, the order the various feature calls is important. It must start with
3565 * the "most" features enabled at the same time, then trickle down to the
3566 * least amount of features turned on at once.
3567 **/
3568static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
3569{
3570 /* start with default case */
3571 adapter->rx_ring[0].reg_idx = 0;
3572 adapter->tx_ring[0].reg_idx = 0;
3573
Yi Zou0331a832009-05-17 12:33:52 +00003574#ifdef IXGBE_FCOE
3575 if (ixgbe_cache_ring_fcoe(adapter))
3576 return;
3577
3578#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003579#ifdef CONFIG_IXGBE_DCB
3580 if (ixgbe_cache_ring_dcb(adapter))
3581 return;
3582
3583#endif
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003584 if (ixgbe_cache_ring_fdir(adapter))
3585 return;
3586
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08003587 if (ixgbe_cache_ring_rss(adapter))
3588 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003589}
3590
Auke Kok9a799d72007-09-15 14:07:45 -07003591/**
3592 * ixgbe_alloc_queues - Allocate memory for all rings
3593 * @adapter: board private structure to initialize
3594 *
3595 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003596 * number of queues at compile-time. The polling_netdev array is
3597 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07003598 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003599static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003600{
3601 int i;
3602
3603 adapter->tx_ring = kcalloc(adapter->num_tx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003604 sizeof(struct ixgbe_ring), GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07003605 if (!adapter->tx_ring)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003606 goto err_tx_ring_allocation;
Auke Kok9a799d72007-09-15 14:07:45 -07003607
3608 adapter->rx_ring = kcalloc(adapter->num_rx_queues,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003609 sizeof(struct ixgbe_ring), GFP_KERNEL);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003610 if (!adapter->rx_ring)
3611 goto err_rx_ring_allocation;
3612
3613 for (i = 0; i < adapter->num_tx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003614 adapter->tx_ring[i].count = adapter->tx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003615 adapter->tx_ring[i].queue_index = i;
3616 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003617
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003618 for (i = 0; i < adapter->num_rx_queues; i++) {
Jesse Brandeburgb9804972008-09-11 20:00:29 -07003619 adapter->rx_ring[i].count = adapter->rx_ring_count;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003620 adapter->rx_ring[i].queue_index = i;
Auke Kok9a799d72007-09-15 14:07:45 -07003621 }
3622
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003623 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003624
3625 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003626
3627err_rx_ring_allocation:
3628 kfree(adapter->tx_ring);
3629err_tx_ring_allocation:
3630 return -ENOMEM;
3631}
3632
3633/**
3634 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
3635 * @adapter: board private structure to initialize
3636 *
3637 * Attempt to configure the interrupts using the best available
3638 * capabilities of the hardware and the kernel.
3639 **/
Al Virofeea6a52008-11-27 15:34:07 -08003640static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003641{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003642 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003643 int err = 0;
3644 int vector, v_budget;
3645
3646 /*
3647 * It's easy to be greedy for MSI-X vectors, but it really
3648 * doesn't do us much good if we have a lot more vectors
3649 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00003650 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003651 */
3652 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
PJ Waskiewicz342bde12009-11-12 23:50:43 +00003653 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003654
3655 /*
3656 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003657 * hw.mac->max_msix_vectors vectors. With features
3658 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
3659 * descriptor queues supported by our device. Thus, we cap it off in
3660 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003661 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00003662 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003663
3664 /* A failure in MSI-X entry allocation isn't fatal, but it does
3665 * mean we disable MSI-X capabilities of the adapter. */
3666 adapter->msix_entries = kcalloc(v_budget,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003667 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003668 if (adapter->msix_entries) {
3669 for (vector = 0; vector < v_budget; vector++)
3670 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003671
Alexander Duyck7a921c92009-05-06 10:43:28 +00003672 ixgbe_acquire_msix_vectors(adapter, v_budget);
3673
3674 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3675 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003676 }
3677
Alexander Duyck7a921c92009-05-06 10:43:28 +00003678 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
3679 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003680 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
3681 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
3682 adapter->atr_sample_rate = 0;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003683 ixgbe_set_num_queues(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003684
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003685 err = pci_enable_msi(adapter->pdev);
3686 if (!err) {
3687 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
3688 } else {
3689 DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003690 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003691 /* reset err */
3692 err = 0;
3693 }
3694
3695out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003696 return err;
3697}
3698
Alexander Duyck7a921c92009-05-06 10:43:28 +00003699/**
3700 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
3701 * @adapter: board private structure to initialize
3702 *
3703 * We allocate one q_vector per queue interrupt. If allocation fails we
3704 * return -ENOMEM.
3705 **/
3706static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
3707{
3708 int q_idx, num_q_vectors;
3709 struct ixgbe_q_vector *q_vector;
3710 int napi_vectors;
3711 int (*poll)(struct napi_struct *, int);
3712
3713 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3714 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3715 napi_vectors = adapter->num_rx_queues;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003716 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003717 } else {
3718 num_q_vectors = 1;
3719 napi_vectors = 1;
3720 poll = &ixgbe_poll;
3721 }
3722
3723 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3724 q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL);
3725 if (!q_vector)
3726 goto err_out;
3727 q_vector->adapter = adapter;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00003728 if (q_vector->txr_count && !q_vector->rxr_count)
3729 q_vector->eitr = adapter->tx_eitr_param;
3730 else
3731 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00003732 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003733 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003734 adapter->q_vector[q_idx] = q_vector;
3735 }
3736
3737 return 0;
3738
3739err_out:
3740 while (q_idx) {
3741 q_idx--;
3742 q_vector = adapter->q_vector[q_idx];
3743 netif_napi_del(&q_vector->napi);
3744 kfree(q_vector);
3745 adapter->q_vector[q_idx] = NULL;
3746 }
3747 return -ENOMEM;
3748}
3749
3750/**
3751 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
3752 * @adapter: board private structure to initialize
3753 *
3754 * This function frees the memory allocated to the q_vectors. In addition if
3755 * NAPI is enabled it will delete any references to the NAPI struct prior
3756 * to freeing the q_vector.
3757 **/
3758static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
3759{
3760 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003761
Alexander Duyck91281fd2009-06-04 16:00:27 +00003762 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00003763 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003764 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00003765 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003766
3767 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
3768 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00003769 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003770 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003771 kfree(q_vector);
3772 }
3773}
3774
Don Skidmore7b25cdb2009-08-25 04:47:32 +00003775static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003776{
3777 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3778 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3779 pci_disable_msix(adapter->pdev);
3780 kfree(adapter->msix_entries);
3781 adapter->msix_entries = NULL;
3782 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
3783 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
3784 pci_disable_msi(adapter->pdev);
3785 }
3786 return;
3787}
3788
3789/**
3790 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
3791 * @adapter: board private structure to initialize
3792 *
3793 * We determine which interrupt scheme to use based on...
3794 * - Kernel support (MSI, MSI-X)
3795 * - which can be user-defined (via MODULE_PARAM)
3796 * - Hardware queue count (num_*_queues)
3797 * - defined by miscellaneous hardware support/features (RSS, etc.)
3798 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08003799int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003800{
3801 int err;
3802
3803 /* Number of supported queues */
3804 ixgbe_set_num_queues(adapter);
3805
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003806 err = ixgbe_set_interrupt_capability(adapter);
3807 if (err) {
3808 DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n");
3809 goto err_set_interrupt;
3810 }
3811
Alexander Duyck7a921c92009-05-06 10:43:28 +00003812 err = ixgbe_alloc_q_vectors(adapter);
3813 if (err) {
3814 DPRINTK(PROBE, ERR, "Unable to allocate memory for queue "
3815 "vectors\n");
3816 goto err_alloc_q_vectors;
3817 }
3818
3819 err = ixgbe_alloc_queues(adapter);
3820 if (err) {
3821 DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
3822 goto err_alloc_queues;
3823 }
3824
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003825 DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07003826 "Tx Queue count = %u\n",
3827 (adapter->num_rx_queues > 1) ? "Enabled" :
3828 "Disabled", adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003829
3830 set_bit(__IXGBE_DOWN, &adapter->state);
3831
3832 return 0;
3833
Alexander Duyck7a921c92009-05-06 10:43:28 +00003834err_alloc_queues:
3835 ixgbe_free_q_vectors(adapter);
3836err_alloc_q_vectors:
3837 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003838err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00003839 return err;
3840}
3841
3842/**
3843 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
3844 * @adapter: board private structure to clear interrupt scheme on
3845 *
3846 * We go through and clear interrupt specific resources and reset the structure
3847 * to pre-load conditions
3848 **/
3849void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
3850{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003851 kfree(adapter->tx_ring);
3852 kfree(adapter->rx_ring);
Alexander Duyck7a921c92009-05-06 10:43:28 +00003853 adapter->tx_ring = NULL;
3854 adapter->rx_ring = NULL;
3855
3856 ixgbe_free_q_vectors(adapter);
3857 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003858}
3859
3860/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08003861 * ixgbe_sfp_timer - worker thread to find a missing module
3862 * @data: pointer to our adapter struct
3863 **/
3864static void ixgbe_sfp_timer(unsigned long data)
3865{
3866 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
3867
Jesse Brandeburg4df10462009-03-13 22:15:31 +00003868 /*
3869 * Do the sfp_timer outside of interrupt context due to the
Donald Skidmorec4900be2008-11-20 21:11:42 -08003870 * delays that sfp+ detection requires
3871 */
3872 schedule_work(&adapter->sfp_task);
3873}
3874
3875/**
3876 * ixgbe_sfp_task - worker thread to find a missing module
3877 * @work: pointer to work_struct containing our data
3878 **/
3879static void ixgbe_sfp_task(struct work_struct *work)
3880{
3881 struct ixgbe_adapter *adapter = container_of(work,
3882 struct ixgbe_adapter,
3883 sfp_task);
3884 struct ixgbe_hw *hw = &adapter->hw;
3885
3886 if ((hw->phy.type == ixgbe_phy_nl) &&
3887 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
3888 s32 ret = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00003889 if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
Donald Skidmorec4900be2008-11-20 21:11:42 -08003890 goto reschedule;
3891 ret = hw->phy.ops.reset(hw);
3892 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00003893 dev_err(&adapter->pdev->dev, "failed to initialize "
3894 "because an unsupported SFP+ module type "
3895 "was detected.\n"
3896 "Reload the driver after installing a "
3897 "supported module.\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08003898 unregister_netdev(adapter->netdev);
3899 } else {
3900 DPRINTK(PROBE, INFO, "detected SFP+: %d\n",
3901 hw->phy.sfp_type);
3902 }
3903 /* don't need this routine any more */
3904 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
3905 }
3906 return;
3907reschedule:
3908 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
3909 mod_timer(&adapter->sfp_timer,
3910 round_jiffies(jiffies + (2 * HZ)));
3911}
3912
3913/**
Auke Kok9a799d72007-09-15 14:07:45 -07003914 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
3915 * @adapter: board private structure to initialize
3916 *
3917 * ixgbe_sw_init initializes the Adapter private data structure.
3918 * Fields are initialized based on PCI device information and
3919 * OS network device settings (MTU size).
3920 **/
3921static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
3922{
3923 struct ixgbe_hw *hw = &adapter->hw;
3924 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003925 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003926#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003927 int j;
3928 struct tc_configuration *tc;
3929#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003930
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003931 /* PCI config space info */
3932
3933 hw->vendor_id = pdev->vendor;
3934 hw->device_id = pdev->device;
3935 hw->revision_id = pdev->revision;
3936 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3937 hw->subsystem_device_id = pdev->subsystem_device;
3938
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003939 /* Set capability flags */
3940 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
3941 adapter->ring_feature[RING_F_RSS].indices = rss;
3942 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003943 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Don Skidmorebf069c92009-05-07 10:39:54 +00003944 if (hw->mac.type == ixgbe_mac_82598EB) {
3945 if (hw->device_id == IXGBE_DEV_ID_82598AT)
3946 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003947 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Don Skidmorebf069c92009-05-07 10:39:54 +00003948 } else if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003949 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003950 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
3951 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003952 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
3953 adapter->ring_feature[RING_F_FDIR].indices =
3954 IXGBE_MAX_FDIR_INDICES;
3955 adapter->atr_sample_rate = 20;
3956 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00003957#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00003958 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
3959 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
3960 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou6ee16522009-08-31 12:34:28 +00003961 /* Default traffic class to use for FCoE */
3962 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
Yi Zoueacd73f2009-05-13 13:11:06 +00003963#endif /* IXGBE_FCOE */
Alexander Duyckf8212f92009-04-27 22:42:37 +00003964 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003965
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003966#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003967 /* Configure DCB traffic classes */
3968 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
3969 tc = &adapter->dcb_cfg.tc_config[j];
3970 tc->path[DCB_TX_CONFIG].bwg_id = 0;
3971 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
3972 tc->path[DCB_RX_CONFIG].bwg_id = 0;
3973 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
3974 tc->dcb_pfc = pfc_disabled;
3975 }
3976 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
3977 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
3978 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003979 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003980 adapter->dcb_cfg.round_robin_enable = false;
3981 adapter->dcb_set_bitmap = 0x00;
3982 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
3983 adapter->ring_feature[RING_F_DCB].indices);
3984
3985#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003986
3987 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00003988 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00003989 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00003990#ifdef CONFIG_DCB
3991 adapter->last_lfc_mode = hw->fc.current_mode;
3992#endif
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07003993 hw->fc.high_water = IXGBE_DEFAULT_FCRTH;
3994 hw->fc.low_water = IXGBE_DEFAULT_FCRTL;
3995 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
3996 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00003997 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07003998
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07003999 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004000 adapter->rx_itr_setting = 1;
4001 adapter->rx_eitr_param = 20000;
4002 adapter->tx_itr_setting = 1;
4003 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004004
4005 /* set defaults for eitr in MegaBytes */
4006 adapter->eitr_low = 10;
4007 adapter->eitr_high = 20;
4008
4009 /* set default ring sizes */
4010 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4011 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4012
Auke Kok9a799d72007-09-15 14:07:45 -07004013 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004014 if (ixgbe_init_eeprom_params_generic(hw)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004015 dev_err(&pdev->dev, "EEPROM initialization failed\n");
4016 return -EIO;
4017 }
4018
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004019 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07004020 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
4021
Auke Kok9a799d72007-09-15 14:07:45 -07004022 set_bit(__IXGBE_DOWN, &adapter->state);
4023
4024 return 0;
4025}
4026
4027/**
4028 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
4029 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004030 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004031 *
4032 * Return 0 on success, negative on failure
4033 **/
4034int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004035 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004036{
4037 struct pci_dev *pdev = adapter->pdev;
4038 int size;
4039
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004040 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4041 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004042 if (!tx_ring->tx_buffer_info)
4043 goto err;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004044 memset(tx_ring->tx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07004045
4046 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004047 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004048 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004049
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004050 tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
4051 &tx_ring->dma);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004052 if (!tx_ring->desc)
4053 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004054
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004055 tx_ring->next_to_use = 0;
4056 tx_ring->next_to_clean = 0;
4057 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07004058 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004059
4060err:
4061 vfree(tx_ring->tx_buffer_info);
4062 tx_ring->tx_buffer_info = NULL;
4063 DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit "
4064 "descriptor ring\n");
4065 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004066}
4067
4068/**
Alexander Duyck69888672008-09-11 20:05:39 -07004069 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4070 * @adapter: board private structure
4071 *
4072 * If this function returns with an error, then it's possible one or
4073 * more of the rings is populated (while the rest are not). It is the
4074 * callers duty to clean those orphaned rings.
4075 *
4076 * Return 0 on success, negative on failure
4077 **/
4078static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4079{
4080 int i, err = 0;
4081
4082 for (i = 0; i < adapter->num_tx_queues; i++) {
4083 err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]);
4084 if (!err)
4085 continue;
4086 DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i);
4087 break;
4088 }
4089
4090 return err;
4091}
4092
4093/**
Auke Kok9a799d72007-09-15 14:07:45 -07004094 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
4095 * @adapter: board private structure
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004096 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004097 *
4098 * Returns 0 on success, negative on failure
4099 **/
4100int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004101 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004102{
4103 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004104 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004105
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004106 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4107 rx_ring->rx_buffer_info = vmalloc(size);
4108 if (!rx_ring->rx_buffer_info) {
Auke Kok9a799d72007-09-15 14:07:45 -07004109 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004110 "vmalloc allocation failed for the rx desc ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004111 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07004112 }
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004113 memset(rx_ring->rx_buffer_info, 0, size);
Auke Kok9a799d72007-09-15 14:07:45 -07004114
Auke Kok9a799d72007-09-15 14:07:45 -07004115 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004116 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4117 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004118
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004119 rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004120
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004121 if (!rx_ring->desc) {
Auke Kok9a799d72007-09-15 14:07:45 -07004122 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004123 "Memory allocation failed for the rx desc ring\n");
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004124 vfree(rx_ring->rx_buffer_info);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004125 goto alloc_failed;
Auke Kok9a799d72007-09-15 14:07:45 -07004126 }
4127
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004128 rx_ring->next_to_clean = 0;
4129 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004130
4131 return 0;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004132
4133alloc_failed:
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004134 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004135}
4136
4137/**
Alexander Duyck69888672008-09-11 20:05:39 -07004138 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4139 * @adapter: board private structure
4140 *
4141 * If this function returns with an error, then it's possible one or
4142 * more of the rings is populated (while the rest are not). It is the
4143 * callers duty to clean those orphaned rings.
4144 *
4145 * Return 0 on success, negative on failure
4146 **/
4147
4148static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4149{
4150 int i, err = 0;
4151
4152 for (i = 0; i < adapter->num_rx_queues; i++) {
4153 err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]);
4154 if (!err)
4155 continue;
4156 DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i);
4157 break;
4158 }
4159
4160 return err;
4161}
4162
4163/**
Auke Kok9a799d72007-09-15 14:07:45 -07004164 * ixgbe_free_tx_resources - Free Tx Resources per Queue
4165 * @adapter: board private structure
4166 * @tx_ring: Tx descriptor ring for a specific queue
4167 *
4168 * Free all transmit software resources
4169 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07004170void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
4171 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004172{
4173 struct pci_dev *pdev = adapter->pdev;
4174
4175 ixgbe_clean_tx_ring(adapter, tx_ring);
4176
4177 vfree(tx_ring->tx_buffer_info);
4178 tx_ring->tx_buffer_info = NULL;
4179
4180 pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
4181
4182 tx_ring->desc = NULL;
4183}
4184
4185/**
4186 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4187 * @adapter: board private structure
4188 *
4189 * Free all transmit software resources
4190 **/
4191static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4192{
4193 int i;
4194
4195 for (i = 0; i < adapter->num_tx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004196 if (adapter->tx_ring[i].desc)
4197 ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004198}
4199
4200/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004201 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004202 * @adapter: board private structure
4203 * @rx_ring: ring to clean the resources from
4204 *
4205 * Free all receive software resources
4206 **/
Jesse Brandeburgc431f972008-09-11 19:59:16 -07004207void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
4208 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004209{
4210 struct pci_dev *pdev = adapter->pdev;
4211
4212 ixgbe_clean_rx_ring(adapter, rx_ring);
4213
4214 vfree(rx_ring->rx_buffer_info);
4215 rx_ring->rx_buffer_info = NULL;
4216
4217 pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
4218
4219 rx_ring->desc = NULL;
4220}
4221
4222/**
4223 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4224 * @adapter: board private structure
4225 *
4226 * Free all receive software resources
4227 **/
4228static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4229{
4230 int i;
4231
4232 for (i = 0; i < adapter->num_rx_queues; i++)
Jesse Brandeburg9891ca72009-03-13 22:14:50 +00004233 if (adapter->rx_ring[i].desc)
4234 ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004235}
4236
4237/**
Auke Kok9a799d72007-09-15 14:07:45 -07004238 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4239 * @netdev: network interface device structure
4240 * @new_mtu: new value for maximum frame size
4241 *
4242 * Returns 0 on success, negative on failure
4243 **/
4244static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4245{
4246 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4247 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4248
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004249 /* MTU < 68 is an error and causes problems on some kernels */
4250 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
Auke Kok9a799d72007-09-15 14:07:45 -07004251 return -EINVAL;
4252
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004253 DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n",
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004254 netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004255 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004256 netdev->mtu = new_mtu;
4257
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004258 if (netif_running(netdev))
4259 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004260
4261 return 0;
4262}
4263
4264/**
4265 * ixgbe_open - Called when a network interface is made active
4266 * @netdev: network interface device structure
4267 *
4268 * Returns 0 on success, negative value on failure
4269 *
4270 * The open entry point is called when a network interface is made
4271 * active by the system (IFF_UP). At this point all resources needed
4272 * for transmit and receive operations are allocated, the interrupt
4273 * handler is registered with the OS, the watchdog timer is started,
4274 * and the stack is notified that the interface is ready.
4275 **/
4276static int ixgbe_open(struct net_device *netdev)
4277{
4278 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4279 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004280
Auke Kok4bebfaa2008-02-11 09:26:01 -08004281 /* disallow open during test */
4282 if (test_bit(__IXGBE_TESTING, &adapter->state))
4283 return -EBUSY;
4284
Jesse Brandeburg54386462009-04-17 20:44:27 +00004285 netif_carrier_off(netdev);
4286
Auke Kok9a799d72007-09-15 14:07:45 -07004287 /* allocate transmit descriptors */
4288 err = ixgbe_setup_all_tx_resources(adapter);
4289 if (err)
4290 goto err_setup_tx;
4291
Auke Kok9a799d72007-09-15 14:07:45 -07004292 /* allocate receive descriptors */
4293 err = ixgbe_setup_all_rx_resources(adapter);
4294 if (err)
4295 goto err_setup_rx;
4296
4297 ixgbe_configure(adapter);
4298
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004299 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004300 if (err)
4301 goto err_req_irq;
4302
Auke Kok9a799d72007-09-15 14:07:45 -07004303 err = ixgbe_up_complete(adapter);
4304 if (err)
4305 goto err_up;
4306
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07004307 netif_tx_start_all_queues(netdev);
4308
Auke Kok9a799d72007-09-15 14:07:45 -07004309 return 0;
4310
4311err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004312 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004313 ixgbe_free_irq(adapter);
4314err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07004315err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004316 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004317err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004318 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004319 ixgbe_reset(adapter);
4320
4321 return err;
4322}
4323
4324/**
4325 * ixgbe_close - Disables a network interface
4326 * @netdev: network interface device structure
4327 *
4328 * Returns 0, this is not allowed to fail
4329 *
4330 * The close entry point is called when an interface is de-activated
4331 * by the OS. The hardware is still under the drivers control, but
4332 * needs to be disabled. A global MAC reset is issued to stop the
4333 * hardware, and all transmit and receive resources are freed.
4334 **/
4335static int ixgbe_close(struct net_device *netdev)
4336{
4337 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004338
4339 ixgbe_down(adapter);
4340 ixgbe_free_irq(adapter);
4341
4342 ixgbe_free_all_tx_resources(adapter);
4343 ixgbe_free_all_rx_resources(adapter);
4344
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004345 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004346
4347 return 0;
4348}
4349
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004350#ifdef CONFIG_PM
4351static int ixgbe_resume(struct pci_dev *pdev)
4352{
4353 struct net_device *netdev = pci_get_drvdata(pdev);
4354 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4355 u32 err;
4356
4357 pci_set_power_state(pdev, PCI_D0);
4358 pci_restore_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004359
4360 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004361 if (err) {
Alexander Duyck69888672008-09-11 20:05:39 -07004362 printk(KERN_ERR "ixgbe: Cannot enable PCI device from "
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004363 "suspend\n");
4364 return err;
4365 }
4366 pci_set_master(pdev);
4367
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004368 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004369
4370 err = ixgbe_init_interrupt_scheme(adapter);
4371 if (err) {
4372 printk(KERN_ERR "ixgbe: Cannot initialize interrupts for "
4373 "device\n");
4374 return err;
4375 }
4376
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004377 ixgbe_reset(adapter);
4378
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00004379 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
4380
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004381 if (netif_running(netdev)) {
4382 err = ixgbe_open(adapter->netdev);
4383 if (err)
4384 return err;
4385 }
4386
4387 netif_device_attach(netdev);
4388
4389 return 0;
4390}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004391#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004392
4393static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004394{
4395 struct net_device *netdev = pci_get_drvdata(pdev);
4396 struct ixgbe_adapter *adapter = netdev_priv(netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004397 struct ixgbe_hw *hw = &adapter->hw;
4398 u32 ctrl, fctrl;
4399 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004400#ifdef CONFIG_PM
4401 int retval = 0;
4402#endif
4403
4404 netif_device_detach(netdev);
4405
4406 if (netif_running(netdev)) {
4407 ixgbe_down(adapter);
4408 ixgbe_free_irq(adapter);
4409 ixgbe_free_all_tx_resources(adapter);
4410 ixgbe_free_all_rx_resources(adapter);
4411 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00004412 ixgbe_clear_interrupt_scheme(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004413
4414#ifdef CONFIG_PM
4415 retval = pci_save_state(pdev);
4416 if (retval)
4417 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004418
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004419#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004420 if (wufc) {
4421 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004422
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004423 /* turn on all-multi mode if wake on multicast is enabled */
4424 if (wufc & IXGBE_WUFC_MC) {
4425 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4426 fctrl |= IXGBE_FCTRL_MPE;
4427 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
4428 }
4429
4430 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
4431 ctrl |= IXGBE_CTRL_GIO_DIS;
4432 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
4433
4434 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
4435 } else {
4436 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
4437 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
4438 }
4439
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07004440 if (wufc && hw->mac.type == ixgbe_mac_82599EB)
4441 pci_wake_from_d3(pdev, true);
4442 else
4443 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004444
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004445 *enable_wake = !!wufc;
4446
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004447 ixgbe_release_hw_control(adapter);
4448
4449 pci_disable_device(pdev);
4450
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004451 return 0;
4452}
4453
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004454#ifdef CONFIG_PM
4455static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
4456{
4457 int retval;
4458 bool wake;
4459
4460 retval = __ixgbe_shutdown(pdev, &wake);
4461 if (retval)
4462 return retval;
4463
4464 if (wake) {
4465 pci_prepare_to_sleep(pdev);
4466 } else {
4467 pci_wake_from_d3(pdev, false);
4468 pci_set_power_state(pdev, PCI_D3hot);
4469 }
4470
4471 return 0;
4472}
4473#endif /* CONFIG_PM */
4474
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004475static void ixgbe_shutdown(struct pci_dev *pdev)
4476{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00004477 bool wake;
4478
4479 __ixgbe_shutdown(pdev, &wake);
4480
4481 if (system_state == SYSTEM_POWER_OFF) {
4482 pci_wake_from_d3(pdev, wake);
4483 pci_set_power_state(pdev, PCI_D3hot);
4484 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004485}
4486
4487/**
Auke Kok9a799d72007-09-15 14:07:45 -07004488 * ixgbe_update_stats - Update the board statistics counters.
4489 * @adapter: board private structure
4490 **/
4491void ixgbe_update_stats(struct ixgbe_adapter *adapter)
4492{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004493 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07004494 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004495 u64 total_mpc = 0;
4496 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004497
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004498 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004499 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004500 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004501 for (i = 0; i < 16; i++)
4502 adapter->hw_rx_no_dma_resources +=
4503 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004504 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004505 rsc_count += adapter->rx_ring[i].rsc_count;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00004506 rsc_flush += adapter->rx_ring[i].rsc_flush;
4507 }
4508 adapter->rsc_total_count = rsc_count;
4509 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00004510 }
4511
Auke Kok9a799d72007-09-15 14:07:45 -07004512 adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004513 for (i = 0; i < 8; i++) {
4514 /* for packet buffers not used, the register should read 0 */
4515 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
4516 missed_rx += mpc;
4517 adapter->stats.mpc[i] += mpc;
4518 total_mpc += adapter->stats.mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004519 if (hw->mac.type == ixgbe_mac_82598EB)
4520 adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004521 adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
4522 adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
4523 adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
4524 adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004525 if (hw->mac.type == ixgbe_mac_82599EB) {
4526 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4527 IXGBE_PXONRXCNT(i));
4528 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4529 IXGBE_PXOFFRXCNT(i));
4530 adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004531 } else {
4532 adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw,
4533 IXGBE_PXONRXC(i));
4534 adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw,
4535 IXGBE_PXOFFRXC(i));
4536 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004537 adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw,
4538 IXGBE_PXONTXC(i));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004539 adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw,
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004540 IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004541 }
4542 adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
4543 /* work around hardware counting issue */
4544 adapter->stats.gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07004545
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004546 /* 82598 hardware only has a 32 bit counter in the high register */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004547 if (hw->mac.type == ixgbe_mac_82599EB) {
Ben Greearaad71912009-09-30 12:08:16 +00004548 u64 tmp;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004549 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Ben Greearaad71912009-09-30 12:08:16 +00004550 tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */
4551 adapter->stats.gorc += (tmp << 32);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004552 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Ben Greearaad71912009-09-30 12:08:16 +00004553 tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */
4554 adapter->stats.gotc += (tmp << 32);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004555 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL);
4556 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
4557 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
4558 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004559 adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
4560 adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00004561#ifdef IXGBE_FCOE
4562 adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
4563 adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
4564 adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
4565 adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
4566 adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
4567 adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
4568#endif /* IXGBE_FCOE */
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004569 } else {
4570 adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
4571 adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
4572 adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
4573 adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
4574 adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH);
4575 }
Auke Kok9a799d72007-09-15 14:07:45 -07004576 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
4577 adapter->stats.bprc += bprc;
4578 adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004579 if (hw->mac.type == ixgbe_mac_82598EB)
4580 adapter->stats.mprc -= bprc;
Auke Kok9a799d72007-09-15 14:07:45 -07004581 adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC);
4582 adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
4583 adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
4584 adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
4585 adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
4586 adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
4587 adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004588 adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004589 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
4590 adapter->stats.lxontxc += lxon;
4591 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
4592 adapter->stats.lxofftxc += lxoff;
Auke Kok9a799d72007-09-15 14:07:45 -07004593 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4594 adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004595 adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
4596 /*
4597 * 82598 errata - tx of flow control packets is included in tx counters
4598 */
4599 xon_off_tot = lxon + lxoff;
4600 adapter->stats.gptc -= xon_off_tot;
4601 adapter->stats.mptc -= xon_off_tot;
4602 adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
Auke Kok9a799d72007-09-15 14:07:45 -07004603 adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
4604 adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
4605 adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
Auke Kok9a799d72007-09-15 14:07:45 -07004606 adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
4607 adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08004608 adapter->stats.ptc64 -= xon_off_tot;
Auke Kok9a799d72007-09-15 14:07:45 -07004609 adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
4610 adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
4611 adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
4612 adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
4613 adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
Auke Kok9a799d72007-09-15 14:07:45 -07004614 adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
4615
4616 /* Fill out the OS statistics structure */
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004617 netdev->stats.multicast = adapter->stats.mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07004618
4619 /* Rx Errors */
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004620 netdev->stats.rx_errors = adapter->stats.crcerrs +
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004621 adapter->stats.rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00004622 netdev->stats.rx_dropped = 0;
4623 netdev->stats.rx_length_errors = adapter->stats.rlec;
4624 netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
4625 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07004626}
4627
4628/**
4629 * ixgbe_watchdog - Timer Call-back
4630 * @data: pointer to adapter cast into an unsigned long
4631 **/
4632static void ixgbe_watchdog(unsigned long data)
4633{
4634 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004635 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004636 u64 eics = 0;
4637 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004638
Alexander Duyckfe49f042009-06-04 16:00:09 +00004639 /*
4640 * Do the watchdog outside of interrupt context due to the lovely
4641 * delays that some of the newer hardware requires
4642 */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004643
Alexander Duyckfe49f042009-06-04 16:00:09 +00004644 if (test_bit(__IXGBE_DOWN, &adapter->state))
4645 goto watchdog_short_circuit;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00004646
Alexander Duyckfe49f042009-06-04 16:00:09 +00004647 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
4648 /*
4649 * for legacy and MSI interrupts don't set any bits
4650 * that are enabled for EIAM, because this operation
4651 * would set *both* EIMS and EICS for any bit in EIAM
4652 */
4653 IXGBE_WRITE_REG(hw, IXGBE_EICS,
4654 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
4655 goto watchdog_reschedule;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004656 }
4657
Alexander Duyckfe49f042009-06-04 16:00:09 +00004658 /* get one bit for every active tx/rx interrupt vector */
4659 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
4660 struct ixgbe_q_vector *qv = adapter->q_vector[i];
4661 if (qv->rxr_count || qv->txr_count)
4662 eics |= ((u64)1 << i);
4663 }
4664
4665 /* Cause software interrupt to ensure rx rings are cleaned */
4666 ixgbe_irq_rearm_queues(adapter, eics);
4667
4668watchdog_reschedule:
4669 /* Reset the timer */
4670 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
4671
4672watchdog_short_circuit:
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004673 schedule_work(&adapter->watchdog_task);
4674}
4675
4676/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004677 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
4678 * @work: pointer to work_struct containing our data
4679 **/
4680static void ixgbe_multispeed_fiber_task(struct work_struct *work)
4681{
4682 struct ixgbe_adapter *adapter = container_of(work,
4683 struct ixgbe_adapter,
4684 multispeed_fiber_task);
4685 struct ixgbe_hw *hw = &adapter->hw;
4686 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004687 bool negotiation;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004688
4689 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
Mallikarjuna R Chilakalaa1f25322009-06-30 11:44:36 +00004690 autoneg = hw->phy.autoneg_advertised;
4691 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004692 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
4693 if (hw->mac.ops.setup_link)
4694 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004695 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4696 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
4697}
4698
4699/**
4700 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
4701 * @work: pointer to work_struct containing our data
4702 **/
4703static void ixgbe_sfp_config_module_task(struct work_struct *work)
4704{
4705 struct ixgbe_adapter *adapter = container_of(work,
4706 struct ixgbe_adapter,
4707 sfp_config_module_task);
4708 struct ixgbe_hw *hw = &adapter->hw;
4709 u32 err;
4710
4711 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004712
4713 /* Time for electrical oscillations to settle down */
4714 msleep(100);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004715 err = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004716
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004717 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00004718 dev_err(&adapter->pdev->dev, "failed to initialize because "
4719 "an unsupported SFP+ module type was detected.\n"
4720 "Reload the driver after installing a supported "
4721 "module.\n");
Don Skidmore63d6e1d2009-07-02 12:50:12 +00004722 unregister_netdev(adapter->netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004723 return;
4724 }
4725 hw->mac.ops.setup_sfp(hw);
4726
Tony Breeds8d1c3c02009-04-09 22:29:10 +00004727 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004728 /* This will also work for DA Twinax connections */
4729 schedule_work(&adapter->multispeed_fiber_task);
4730 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
4731}
4732
4733/**
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004734 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
4735 * @work: pointer to work_struct containing our data
4736 **/
4737static void ixgbe_fdir_reinit_task(struct work_struct *work)
4738{
4739 struct ixgbe_adapter *adapter = container_of(work,
4740 struct ixgbe_adapter,
4741 fdir_reinit_task);
4742 struct ixgbe_hw *hw = &adapter->hw;
4743 int i;
4744
4745 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
4746 for (i = 0; i < adapter->num_tx_queues; i++)
4747 set_bit(__IXGBE_FDIR_INIT_DONE,
4748 &(adapter->tx_ring[i].reinit_state));
4749 } else {
4750 DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, "
4751 "ignored adding FDIR ATR filters \n");
4752 }
4753 /* Done FDIR Re-initialization, enable transmits */
4754 netif_tx_start_all_queues(adapter->netdev);
4755}
4756
4757/**
Alexander Duyck69888672008-09-11 20:05:39 -07004758 * ixgbe_watchdog_task - worker thread to bring link up
4759 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004760 **/
4761static void ixgbe_watchdog_task(struct work_struct *work)
4762{
4763 struct ixgbe_adapter *adapter = container_of(work,
4764 struct ixgbe_adapter,
4765 watchdog_task);
4766 struct net_device *netdev = adapter->netdev;
4767 struct ixgbe_hw *hw = &adapter->hw;
4768 u32 link_speed = adapter->link_speed;
4769 bool link_up = adapter->link_up;
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004770 int i;
4771 struct ixgbe_ring *tx_ring;
4772 int some_tx_pending = 0;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004773
4774 adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK;
4775
4776 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
4777 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004778 if (link_up) {
4779#ifdef CONFIG_DCB
4780 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4781 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004782 hw->mac.ops.fc_enable(hw, i);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004783 } else {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004784 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004785 }
4786#else
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00004787 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004788#endif
4789 }
4790
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004791 if (link_up ||
4792 time_after(jiffies, (adapter->link_check_timeout +
4793 IXGBE_TRY_LINK_TIMEOUT))) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004794 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004795 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004796 }
4797 adapter->link_up = link_up;
4798 adapter->link_speed = link_speed;
4799 }
Auke Kok9a799d72007-09-15 14:07:45 -07004800
4801 if (link_up) {
4802 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004803 bool flow_rx, flow_tx;
4804
4805 if (hw->mac.type == ixgbe_mac_82599EB) {
4806 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
4807 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
Peter P Waskiewicz Jr078788b2009-07-16 15:50:32 +00004808 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
4809 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004810 } else {
4811 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4812 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
Peter P Waskiewicz Jr078788b2009-07-16 15:50:32 +00004813 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
4814 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004815 }
4816
Jeff Kirshera46e5342008-11-27 00:22:21 -08004817 printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, "
4818 "Flow Control: %s\n",
4819 netdev->name,
4820 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
4821 "10 Gbps" :
4822 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
4823 "1 Gbps" : "unknown speed")),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004824 ((flow_rx && flow_tx) ? "RX/TX" :
4825 (flow_rx ? "RX" :
4826 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07004827
4828 netif_carrier_on(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004829 } else {
4830 /* Force detection of hung controller */
4831 adapter->detect_tx_hung = true;
4832 }
4833 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004834 adapter->link_up = false;
4835 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004836 if (netif_carrier_ok(netdev)) {
Jeff Kirshera46e5342008-11-27 00:22:21 -08004837 printk(KERN_INFO "ixgbe: %s NIC Link is Down\n",
4838 netdev->name);
Auke Kok9a799d72007-09-15 14:07:45 -07004839 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004840 }
4841 }
4842
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00004843 if (!netif_carrier_ok(netdev)) {
4844 for (i = 0; i < adapter->num_tx_queues; i++) {
4845 tx_ring = &adapter->tx_ring[i];
4846 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
4847 some_tx_pending = 1;
4848 break;
4849 }
4850 }
4851
4852 if (some_tx_pending) {
4853 /* We've lost link, so the controller stops DMA,
4854 * but we've got queued Tx work that's never going
4855 * to get done, so reset controller to flush Tx.
4856 * (Do the reset outside of interrupt context).
4857 */
4858 schedule_work(&adapter->reset_task);
4859 }
4860 }
4861
Auke Kok9a799d72007-09-15 14:07:45 -07004862 ixgbe_update_stats(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004863 adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK;
Auke Kok9a799d72007-09-15 14:07:45 -07004864}
4865
Auke Kok9a799d72007-09-15 14:07:45 -07004866static int ixgbe_tso(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004867 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
4868 u32 tx_flags, u8 *hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07004869{
4870 struct ixgbe_adv_tx_context_desc *context_desc;
4871 unsigned int i;
4872 int err;
4873 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004874 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
4875 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07004876
4877 if (skb_is_gso(skb)) {
4878 if (skb_header_cloned(skb)) {
4879 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
4880 if (err)
4881 return err;
4882 }
4883 l4len = tcp_hdrlen(skb);
4884 *hdr_len += l4len;
4885
Al Viro8327d002007-12-10 18:54:12 +00004886 if (skb->protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07004887 struct iphdr *iph = ip_hdr(skb);
4888 iph->tot_len = 0;
4889 iph->check = 0;
4890 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004891 iph->daddr, 0,
4892 IPPROTO_TCP,
4893 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004894 adapter->hw_tso_ctxt++;
4895 } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
4896 ipv6_hdr(skb)->payload_len = 0;
4897 tcp_hdr(skb)->check =
4898 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004899 &ipv6_hdr(skb)->daddr,
4900 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07004901 adapter->hw_tso6_ctxt++;
4902 }
4903
4904 i = tx_ring->next_to_use;
4905
4906 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4907 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4908
4909 /* VLAN MACLEN IPLEN */
4910 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4911 vlan_macip_lens |=
4912 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4913 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004914 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004915 *hdr_len += skb_network_offset(skb);
4916 vlan_macip_lens |=
4917 (skb_transport_header(skb) - skb_network_header(skb));
4918 *hdr_len +=
4919 (skb_transport_header(skb) - skb_network_header(skb));
4920 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4921 context_desc->seqnum_seed = 0;
4922
4923 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004924 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004925 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004926
Al Viro8327d002007-12-10 18:54:12 +00004927 if (skb->protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07004928 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
4929 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
4930 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
4931
4932 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07004933 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07004934 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
4935 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07004936 /* use index 1 for TSO */
4937 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004938 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
4939
4940 tx_buffer_info->time_stamp = jiffies;
4941 tx_buffer_info->next_to_watch = i;
4942
4943 i++;
4944 if (i == tx_ring->count)
4945 i = 0;
4946 tx_ring->next_to_use = i;
4947
4948 return true;
4949 }
4950 return false;
4951}
4952
4953static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004954 struct ixgbe_ring *tx_ring,
4955 struct sk_buff *skb, u32 tx_flags)
Auke Kok9a799d72007-09-15 14:07:45 -07004956{
4957 struct ixgbe_adv_tx_context_desc *context_desc;
4958 unsigned int i;
4959 struct ixgbe_tx_buffer *tx_buffer_info;
4960 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
4961
4962 if (skb->ip_summed == CHECKSUM_PARTIAL ||
4963 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
4964 i = tx_ring->next_to_use;
4965 tx_buffer_info = &tx_ring->tx_buffer_info[i];
4966 context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i);
4967
4968 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
4969 vlan_macip_lens |=
4970 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
4971 vlan_macip_lens |= (skb_network_offset(skb) <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004972 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07004973 if (skb->ip_summed == CHECKSUM_PARTIAL)
4974 vlan_macip_lens |= (skb_transport_header(skb) -
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004975 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07004976
4977 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
4978 context_desc->seqnum_seed = 0;
4979
4980 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004981 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07004982
4983 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Auke Kok41825d72008-02-12 15:20:33 -08004984 switch (skb->protocol) {
Harvey Harrison09640e62009-02-01 00:45:17 -08004985 case cpu_to_be16(ETH_P_IP):
Auke Kok9a799d72007-09-15 14:07:45 -07004986 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
Auke Kok41825d72008-02-12 15:20:33 -08004987 if (ip_hdr(skb)->protocol == IPPROTO_TCP)
4988 type_tucmd_mlhl |=
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004989 IXGBE_ADVTXD_TUCMD_L4T_TCP;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00004990 else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
4991 type_tucmd_mlhl |=
4992 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08004993 break;
Harvey Harrison09640e62009-02-01 00:45:17 -08004994 case cpu_to_be16(ETH_P_IPV6):
Auke Kok41825d72008-02-12 15:20:33 -08004995 /* XXX what about other V6 headers?? */
4996 if (ipv6_hdr(skb)->nexthdr == 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 (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
5000 type_tucmd_mlhl |=
5001 IXGBE_ADVTXD_TUCMD_L4T_SCTP;
Auke Kok41825d72008-02-12 15:20:33 -08005002 break;
Auke Kok41825d72008-02-12 15:20:33 -08005003 default:
5004 if (unlikely(net_ratelimit())) {
5005 DPRINTK(PROBE, WARNING,
5006 "partial checksum but proto=%x!\n",
5007 skb->protocol);
5008 }
5009 break;
5010 }
Auke Kok9a799d72007-09-15 14:07:45 -07005011 }
5012
5013 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07005014 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07005015 context_desc->mss_l4len_idx = 0;
5016
5017 tx_buffer_info->time_stamp = jiffies;
5018 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005019
Auke Kok9a799d72007-09-15 14:07:45 -07005020 adapter->hw_csum_tx_good++;
5021 i++;
5022 if (i == tx_ring->count)
5023 i = 0;
5024 tx_ring->next_to_use = i;
5025
5026 return true;
5027 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005028
Auke Kok9a799d72007-09-15 14:07:45 -07005029 return false;
5030}
5031
5032static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005033 struct ixgbe_ring *tx_ring,
Yi Zoueacd73f2009-05-13 13:11:06 +00005034 struct sk_buff *skb, u32 tx_flags,
5035 unsigned int first)
Auke Kok9a799d72007-09-15 14:07:45 -07005036{
Alexander Duycke5a43542009-12-02 16:46:56 +00005037 struct pci_dev *pdev = adapter->pdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005038 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00005039 unsigned int len;
5040 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07005041 unsigned int offset = 0, size, count = 0, i;
5042 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
5043 unsigned int f;
Auke Kok9a799d72007-09-15 14:07:45 -07005044
5045 i = tx_ring->next_to_use;
5046
Yi Zoueacd73f2009-05-13 13:11:06 +00005047 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
5048 /* excluding fcoe_crc_eof for FCoE */
5049 total -= sizeof(struct fcoe_crc_eof);
5050
5051 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07005052 while (len) {
5053 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5054 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
5055
5056 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00005057 tx_buffer_info->mapped_as_page = false;
5058 tx_buffer_info->dma = pci_map_single(pdev,
5059 skb->data + offset,
5060 size, PCI_DMA_TODEVICE);
5061 if (pci_dma_mapping_error(pdev, tx_buffer_info->dma))
5062 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07005063 tx_buffer_info->time_stamp = jiffies;
5064 tx_buffer_info->next_to_watch = i;
5065
5066 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00005067 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07005068 offset += size;
5069 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00005070
5071 if (len) {
5072 i++;
5073 if (i == tx_ring->count)
5074 i = 0;
5075 }
Auke Kok9a799d72007-09-15 14:07:45 -07005076 }
5077
5078 for (f = 0; f < nr_frags; f++) {
5079 struct skb_frag_struct *frag;
5080
5081 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00005082 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00005083 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07005084
5085 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00005086 i++;
5087 if (i == tx_ring->count)
5088 i = 0;
5089
Auke Kok9a799d72007-09-15 14:07:45 -07005090 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5091 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
5092
5093 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00005094 tx_buffer_info->dma = pci_map_page(adapter->pdev,
5095 frag->page,
5096 offset, size,
5097 PCI_DMA_TODEVICE);
5098 tx_buffer_info->mapped_as_page = true;
5099 if (pci_dma_mapping_error(pdev, tx_buffer_info->dma))
5100 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07005101 tx_buffer_info->time_stamp = jiffies;
5102 tx_buffer_info->next_to_watch = i;
5103
5104 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00005105 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07005106 offset += size;
5107 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07005108 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005109 if (total == 0)
5110 break;
Auke Kok9a799d72007-09-15 14:07:45 -07005111 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00005112
Auke Kok9a799d72007-09-15 14:07:45 -07005113 tx_ring->tx_buffer_info[i].skb = skb;
5114 tx_ring->tx_buffer_info[first].next_to_watch = i;
5115
5116 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00005117
5118dma_error:
5119 dev_err(&pdev->dev, "TX DMA map failed\n");
5120
5121 /* clear timestamp and dma mappings for failed tx_buffer_info map */
5122 tx_buffer_info->dma = 0;
5123 tx_buffer_info->time_stamp = 0;
5124 tx_buffer_info->next_to_watch = 0;
5125 count--;
5126
5127 /* clear timestamp and dma mappings for remaining portion of packet */
5128 while (count >= 0) {
5129 count--;
5130 i--;
5131 if (i < 0)
5132 i += tx_ring->count;
5133 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5134 ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
5135 }
5136
5137 return count;
Auke Kok9a799d72007-09-15 14:07:45 -07005138}
5139
5140static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005141 struct ixgbe_ring *tx_ring,
5142 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07005143{
5144 union ixgbe_adv_tx_desc *tx_desc = NULL;
5145 struct ixgbe_tx_buffer *tx_buffer_info;
5146 u32 olinfo_status = 0, cmd_type_len = 0;
5147 unsigned int i;
5148 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
5149
5150 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
5151
5152 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
5153
5154 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
5155 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
5156
5157 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
5158 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
5159
5160 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005161 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07005162
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07005163 /* use index 1 context for tso */
5164 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07005165 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
5166 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005167 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07005168
5169 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
5170 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005171 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07005172
Yi Zoueacd73f2009-05-13 13:11:06 +00005173 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5174 olinfo_status |= IXGBE_ADVTXD_CC;
5175 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
5176 if (tx_flags & IXGBE_TX_FLAGS_FSO)
5177 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
5178 }
5179
Auke Kok9a799d72007-09-15 14:07:45 -07005180 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
5181
5182 i = tx_ring->next_to_use;
5183 while (count--) {
5184 tx_buffer_info = &tx_ring->tx_buffer_info[i];
5185 tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i);
5186 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
5187 tx_desc->read.cmd_type_len =
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005188 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07005189 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07005190 i++;
5191 if (i == tx_ring->count)
5192 i = 0;
5193 }
5194
5195 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
5196
5197 /*
5198 * Force memory writes to complete before letting h/w
5199 * know there are new descriptors to fetch. (Only
5200 * applicable for weak-ordered memory model archs,
5201 * such as IA-64).
5202 */
5203 wmb();
5204
5205 tx_ring->next_to_use = i;
5206 writel(i, adapter->hw.hw_addr + tx_ring->tail);
5207}
5208
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005209static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
5210 int queue, u32 tx_flags)
5211{
5212 /* Right now, we support IPv4 only */
5213 struct ixgbe_atr_input atr_input;
5214 struct tcphdr *th;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005215 struct iphdr *iph = ip_hdr(skb);
5216 struct ethhdr *eth = (struct ethhdr *)skb->data;
5217 u16 vlan_id, src_port, dst_port, flex_bytes;
5218 u32 src_ipv4_addr, dst_ipv4_addr;
5219 u8 l4type = 0;
5220
5221 /* check if we're UDP or TCP */
5222 if (iph->protocol == IPPROTO_TCP) {
5223 th = tcp_hdr(skb);
5224 src_port = th->source;
5225 dst_port = th->dest;
5226 l4type |= IXGBE_ATR_L4TYPE_TCP;
5227 /* l4type IPv4 type is 0, no need to assign */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005228 } else {
5229 /* Unsupported L4 header, just bail here */
5230 return;
5231 }
5232
5233 memset(&atr_input, 0, sizeof(struct ixgbe_atr_input));
5234
5235 vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >>
5236 IXGBE_TX_FLAGS_VLAN_SHIFT;
5237 src_ipv4_addr = iph->saddr;
5238 dst_ipv4_addr = iph->daddr;
5239 flex_bytes = eth->h_proto;
5240
5241 ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
5242 ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
5243 ixgbe_atr_set_dst_port_82599(&atr_input, src_port);
5244 ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes);
5245 ixgbe_atr_set_l4type_82599(&atr_input, l4type);
5246 /* src and dst are inverted, think how the receiver sees them */
5247 ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr);
5248 ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr);
5249
5250 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
5251 ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue);
5252}
5253
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005254static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005255 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005256{
5257 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5258
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005259 netif_stop_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005260 /* Herbert's original patch had:
5261 * smp_mb__after_netif_stop_queue();
5262 * but since that doesn't exist yet, just open code it. */
5263 smp_mb();
5264
5265 /* We need to check again in a case another CPU has just
5266 * made room available. */
5267 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
5268 return -EBUSY;
5269
5270 /* A reprieve! - use start_queue because it doesn't call schedule */
Jesse Brandeburgaf721662008-09-11 19:54:23 -07005271 netif_start_subqueue(netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005272 ++adapter->restart_queue;
5273 return 0;
5274}
5275
5276static int ixgbe_maybe_stop_tx(struct net_device *netdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005277 struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005278{
5279 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
5280 return 0;
5281 return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
5282}
5283
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005284static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
5285{
5286 struct ixgbe_adapter *adapter = netdev_priv(dev);
5287
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005288 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
5289 return smp_processor_id();
5290
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005291 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
Lucy Liu36e89d72009-08-05 13:06:34 -07005292 return (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) >> 13;
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005293
5294 return skb_tx_hash(dev, skb);
5295}
5296
Stephen Hemminger3b29a562009-08-31 19:50:55 +00005297static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
5298 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07005299{
5300 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5301 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07005302 unsigned int first;
5303 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005304 u8 hdr_len = 0;
5305 int r_idx = 0, tso;
Auke Kok9a799d72007-09-15 14:07:45 -07005306 int count = 0;
5307 unsigned int f;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005308
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005309 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
5310 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005311 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5312 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
5313 tx_flags |= (skb->queue_mapping << 13);
5314 }
5315 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5316 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5317 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
Lucy Liu60127862009-07-22 14:07:33 +00005318 if (skb->priority != TC_PRIO_CONTROL) {
5319 tx_flags |= (skb->queue_mapping << 13);
5320 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
5321 tx_flags |= IXGBE_TX_FLAGS_VLAN;
5322 } else {
5323 skb->queue_mapping =
5324 adapter->ring_feature[RING_F_DCB].indices-1;
5325 }
Auke Kok9a799d72007-09-15 14:07:45 -07005326 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005327
Lucy Liu60127862009-07-22 14:07:33 +00005328 r_idx = skb->queue_mapping;
5329 tx_ring = &adapter->tx_ring[r_idx];
5330
Yi Zoueacd73f2009-05-13 13:11:06 +00005331 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
Yi Zou09ad1cc2009-09-03 14:56:10 +00005332 (skb->protocol == htons(ETH_P_FCOE))) {
Yi Zoueacd73f2009-05-13 13:11:06 +00005333 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Yi Zou09ad1cc2009-09-03 14:56:10 +00005334#ifdef IXGBE_FCOE
5335 r_idx = smp_processor_id();
5336 r_idx &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
5337 r_idx += adapter->ring_feature[RING_F_FCOE].mask;
5338 tx_ring = &adapter->tx_ring[r_idx];
5339#endif
5340 }
Yi Zoueacd73f2009-05-13 13:11:06 +00005341 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005342 if (skb_is_gso(skb) ||
5343 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00005344 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
5345 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07005346 count++;
5347
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005348 count += TXD_USE_COUNT(skb_headlen(skb));
5349 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07005350 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
5351
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08005352 if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
Auke Kok9a799d72007-09-15 14:07:45 -07005353 adapter->tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07005354 return NETDEV_TX_BUSY;
5355 }
Auke Kok9a799d72007-09-15 14:07:45 -07005356
Auke Kok9a799d72007-09-15 14:07:45 -07005357 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00005358 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
5359#ifdef IXGBE_FCOE
5360 /* setup tx offload for FCoE */
5361 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5362 if (tso < 0) {
5363 dev_kfree_skb_any(skb);
5364 return NETDEV_TX_OK;
5365 }
5366 if (tso)
5367 tx_flags |= IXGBE_TX_FLAGS_FSO;
5368#endif /* IXGBE_FCOE */
5369 } else {
5370 if (skb->protocol == htons(ETH_P_IP))
5371 tx_flags |= IXGBE_TX_FLAGS_IPV4;
5372 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len);
5373 if (tso < 0) {
5374 dev_kfree_skb_any(skb);
5375 return NETDEV_TX_OK;
5376 }
5377
5378 if (tso)
5379 tx_flags |= IXGBE_TX_FLAGS_TSO;
5380 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) &&
5381 (skb->ip_summed == CHECKSUM_PARTIAL))
5382 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005383 }
5384
Yi Zoueacd73f2009-05-13 13:11:06 +00005385 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005386 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005387 /* add the ATR filter if ATR is on */
5388 if (tx_ring->atr_sample_rate) {
5389 ++tx_ring->atr_count;
5390 if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) &&
5391 test_bit(__IXGBE_FDIR_INIT_DONE,
5392 &tx_ring->reinit_state)) {
5393 ixgbe_atr(adapter, skb, tx_ring->queue_index,
5394 tx_flags);
5395 tx_ring->atr_count = 0;
5396 }
5397 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00005398 ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
5399 hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00005400 ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07005401
Alexander Duyck44df32c2009-03-31 21:34:23 +00005402 } else {
5403 dev_kfree_skb_any(skb);
5404 tx_ring->tx_buffer_info[first].time_stamp = 0;
5405 tx_ring->next_to_use = first;
5406 }
Auke Kok9a799d72007-09-15 14:07:45 -07005407
5408 return NETDEV_TX_OK;
5409}
5410
5411/**
5412 * ixgbe_get_stats - Get System Network Statistics
5413 * @netdev: network interface device structure
5414 *
5415 * Returns the address of the device statistics structure.
5416 * The statistics are actually updated from the timer callback.
5417 **/
5418static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev)
5419{
Auke Kok9a799d72007-09-15 14:07:45 -07005420 /* only return the current stats */
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005421 return &netdev->stats;
Auke Kok9a799d72007-09-15 14:07:45 -07005422}
5423
5424/**
5425 * ixgbe_set_mac - Change the Ethernet Address of the NIC
5426 * @netdev: network interface device structure
5427 * @p: pointer to an address structure
5428 *
5429 * Returns 0 on success, negative on failure
5430 **/
5431static int ixgbe_set_mac(struct net_device *netdev, void *p)
5432{
5433 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005434 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005435 struct sockaddr *addr = p;
5436
5437 if (!is_valid_ether_addr(addr->sa_data))
5438 return -EADDRNOTAVAIL;
5439
5440 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005441 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07005442
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005443 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07005444
5445 return 0;
5446}
5447
Ben Hutchings6b73e102009-04-29 08:08:58 +00005448static int
5449ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
5450{
5451 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5452 struct ixgbe_hw *hw = &adapter->hw;
5453 u16 value;
5454 int rc;
5455
5456 if (prtad != hw->phy.mdio.prtad)
5457 return -EINVAL;
5458 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
5459 if (!rc)
5460 rc = value;
5461 return rc;
5462}
5463
5464static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
5465 u16 addr, u16 value)
5466{
5467 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5468 struct ixgbe_hw *hw = &adapter->hw;
5469
5470 if (prtad != hw->phy.mdio.prtad)
5471 return -EINVAL;
5472 return hw->phy.ops.write_reg(hw, addr, devad, value);
5473}
5474
5475static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
5476{
5477 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5478
5479 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
5480}
5481
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005482/**
5483 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00005484 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005485 * @netdev: network interface device structure
5486 *
5487 * Returns non-zero on failure
5488 **/
5489static int ixgbe_add_sanmac_netdev(struct net_device *dev)
5490{
5491 int err = 0;
5492 struct ixgbe_adapter *adapter = netdev_priv(dev);
5493 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5494
5495 if (is_valid_ether_addr(mac->san_addr)) {
5496 rtnl_lock();
5497 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5498 rtnl_unlock();
5499 }
5500 return err;
5501}
5502
5503/**
5504 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00005505 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005506 * @netdev: network interface device structure
5507 *
5508 * Returns non-zero on failure
5509 **/
5510static int ixgbe_del_sanmac_netdev(struct net_device *dev)
5511{
5512 int err = 0;
5513 struct ixgbe_adapter *adapter = netdev_priv(dev);
5514 struct ixgbe_mac_info *mac = &adapter->hw.mac;
5515
5516 if (is_valid_ether_addr(mac->san_addr)) {
5517 rtnl_lock();
5518 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
5519 rtnl_unlock();
5520 }
5521 return err;
5522}
5523
Auke Kok9a799d72007-09-15 14:07:45 -07005524#ifdef CONFIG_NET_POLL_CONTROLLER
5525/*
5526 * Polling 'interrupt' - used by things like netconsole to send skbs
5527 * without having to re-enable interrupts. It's not called while
5528 * the interrupt routine is executing.
5529 */
5530static void ixgbe_netpoll(struct net_device *netdev)
5531{
5532 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00005533 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005534
Auke Kok9a799d72007-09-15 14:07:45 -07005535 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00005536 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5537 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
5538 for (i = 0; i < num_q_vectors; i++) {
5539 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
5540 ixgbe_msix_clean_many(0, q_vector);
5541 }
5542 } else {
5543 ixgbe_intr(adapter->pdev->irq, netdev);
5544 }
Auke Kok9a799d72007-09-15 14:07:45 -07005545 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07005546}
5547#endif
5548
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005549static const struct net_device_ops ixgbe_netdev_ops = {
5550 .ndo_open = ixgbe_open,
5551 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08005552 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07005553 .ndo_select_queue = ixgbe_select_queue,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005554 .ndo_get_stats = ixgbe_get_stats,
Chris Leeche90d4002009-03-10 16:00:24 +00005555 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005556 .ndo_set_multicast_list = ixgbe_set_rx_mode,
5557 .ndo_validate_addr = eth_validate_addr,
5558 .ndo_set_mac_address = ixgbe_set_mac,
5559 .ndo_change_mtu = ixgbe_change_mtu,
5560 .ndo_tx_timeout = ixgbe_tx_timeout,
5561 .ndo_vlan_rx_register = ixgbe_vlan_rx_register,
5562 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
5563 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00005564 .ndo_do_ioctl = ixgbe_ioctl,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005565#ifdef CONFIG_NET_POLL_CONTROLLER
5566 .ndo_poll_controller = ixgbe_netpoll,
5567#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005568#ifdef IXGBE_FCOE
5569 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
5570 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00005571 .ndo_fcoe_enable = ixgbe_fcoe_enable,
5572 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00005573 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00005574#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005575};
5576
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005577/**
Auke Kok9a799d72007-09-15 14:07:45 -07005578 * ixgbe_probe - Device Initialization Routine
5579 * @pdev: PCI device information struct
5580 * @ent: entry in ixgbe_pci_tbl
5581 *
5582 * Returns 0 on success, negative on failure
5583 *
5584 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
5585 * The OS initialization, configuring of the adapter private structure,
5586 * and a hardware reset occur.
5587 **/
5588static int __devinit ixgbe_probe(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005589 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07005590{
5591 struct net_device *netdev;
5592 struct ixgbe_adapter *adapter = NULL;
5593 struct ixgbe_hw *hw;
5594 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07005595 static int cards_found;
5596 int i, err, pci_using_dac;
Yi Zoueacd73f2009-05-13 13:11:06 +00005597#ifdef IXGBE_FCOE
5598 u16 device_caps;
5599#endif
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005600 u32 part_num, eec;
Auke Kok9a799d72007-09-15 14:07:45 -07005601
gouji-new9ce77662009-05-06 10:44:45 +00005602 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005603 if (err)
5604 return err;
5605
Yang Hongyang6a355282009-04-06 19:01:13 -07005606 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) &&
5607 !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07005608 pci_using_dac = 1;
5609 } else {
Yang Hongyang284901a2009-04-06 19:01:15 -07005610 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005611 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -07005612 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07005613 if (err) {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005614 dev_err(&pdev->dev, "No usable DMA "
5615 "configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005616 goto err_dma;
5617 }
5618 }
5619 pci_using_dac = 0;
5620 }
5621
gouji-new9ce77662009-05-06 10:44:45 +00005622 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
5623 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07005624 if (err) {
gouji-new9ce77662009-05-06 10:44:45 +00005625 dev_err(&pdev->dev,
5626 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07005627 goto err_pci_reg;
5628 }
5629
Frans Pop19d5afd2009-10-02 10:04:12 -07005630 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005631
Auke Kok9a799d72007-09-15 14:07:45 -07005632 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07005633 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005634
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08005635 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES);
Auke Kok9a799d72007-09-15 14:07:45 -07005636 if (!netdev) {
5637 err = -ENOMEM;
5638 goto err_alloc_etherdev;
5639 }
5640
Auke Kok9a799d72007-09-15 14:07:45 -07005641 SET_NETDEV_DEV(netdev, &pdev->dev);
5642
5643 pci_set_drvdata(pdev, netdev);
5644 adapter = netdev_priv(netdev);
5645
5646 adapter->netdev = netdev;
5647 adapter->pdev = pdev;
5648 hw = &adapter->hw;
5649 hw->back = adapter;
5650 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
5651
Jeff Kirsher05857982008-09-11 19:57:00 -07005652 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
5653 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07005654 if (!hw->hw_addr) {
5655 err = -EIO;
5656 goto err_ioremap;
5657 }
5658
5659 for (i = 1; i <= 5; i++) {
5660 if (pci_resource_len(pdev, i) == 0)
5661 continue;
5662 }
5663
Stephen Hemminger0edc3522008-11-19 22:24:29 -08005664 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07005665 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005666 netdev->watchdog_timeo = 5 * HZ;
Auke Kok9a799d72007-09-15 14:07:45 -07005667 strcpy(netdev->name, pci_name(pdev));
5668
Auke Kok9a799d72007-09-15 14:07:45 -07005669 adapter->bd_number = cards_found;
5670
Auke Kok9a799d72007-09-15 14:07:45 -07005671 /* Setup hw api */
5672 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005673 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07005674
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005675 /* EEPROM */
5676 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
5677 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
5678 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
5679 if (!(eec & (1 << 8)))
5680 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
5681
5682 /* PHY */
5683 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08005684 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00005685 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
5686 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
5687 hw->phy.mdio.mmds = 0;
5688 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
5689 hw->phy.mdio.dev = netdev;
5690 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
5691 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08005692
5693 /* set up this timer and work struct before calling get_invariants
5694 * which might start the timer
5695 */
5696 init_timer(&adapter->sfp_timer);
5697 adapter->sfp_timer.function = &ixgbe_sfp_timer;
5698 adapter->sfp_timer.data = (unsigned long) adapter;
5699
5700 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005701
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005702 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
5703 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
5704
5705 /* a new SFP+ module arrival, called from GPI SDP2 context */
5706 INIT_WORK(&adapter->sfp_config_module_task,
5707 ixgbe_sfp_config_module_task);
5708
Don Skidmore8ca783a2009-05-26 20:40:47 -07005709 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005710
5711 /* setup the private structure */
5712 err = ixgbe_sw_init(adapter);
5713 if (err)
5714 goto err_sw_init;
5715
Don Skidmorebf069c92009-05-07 10:39:54 +00005716 /*
5717 * If there is a fan on this device and it has failed log the
5718 * failure.
5719 */
5720 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5721 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5722 if (esdp & IXGBE_ESDP_SDP1)
5723 DPRINTK(PROBE, CRIT,
5724 "Fan has stopped, replace the adapter\n");
5725 }
5726
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005727 /* reset_hw fills in the perm_addr as well */
5728 err = hw->mac.ops.reset_hw(hw);
Don Skidmore8ca783a2009-05-26 20:40:47 -07005729 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
5730 hw->mac.type == ixgbe_mac_82598EB) {
5731 /*
5732 * Start a kernel thread to watch for a module to arrive.
5733 * Only do this for 82598, since 82599 will generate
5734 * interrupts on module arrival.
5735 */
5736 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5737 mod_timer(&adapter->sfp_timer,
5738 round_jiffies(jiffies + (2 * HZ)));
5739 err = 0;
5740 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore88d2b812009-06-30 11:43:55 +00005741 dev_err(&adapter->pdev->dev, "failed to initialize because "
5742 "an unsupported SFP+ module type was detected.\n"
5743 "Reload the driver after installing a supported "
5744 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005745 goto err_sw_init;
5746 } else if (err) {
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005747 dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err);
5748 goto err_sw_init;
5749 }
5750
Auke Kok9a799d72007-09-15 14:07:45 -07005751 netdev->features = NETIF_F_SG |
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005752 NETIF_F_IP_CSUM |
5753 NETIF_F_HW_VLAN_TX |
5754 NETIF_F_HW_VLAN_RX |
5755 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07005756
Jesse Brandeburge9990a92008-08-26 04:27:24 -07005757 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07005758 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07005759 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08005760 netdev->features |= NETIF_F_GRO;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005761
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00005762 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
5763 netdev->features |= NETIF_F_SCTP_CSUM;
5764
Jeff Kirsherad31c402008-06-05 04:05:30 -07005765 netdev->vlan_features |= NETIF_F_TSO;
5766 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07005767 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00005768 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07005769 netdev->vlan_features |= NETIF_F_SG;
5770
Alexander Duyck2f90b862008-11-20 20:52:10 -08005771 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
5772 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
5773
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005774#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005775 netdev->dcbnl_ops = &dcbnl_ops;
5776#endif
5777
Yi Zoueacd73f2009-05-13 13:11:06 +00005778#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005779 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00005780 if (hw->mac.ops.get_device_caps) {
5781 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00005782 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
5783 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00005784 }
5785 }
5786#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005787 if (pci_using_dac)
5788 netdev->features |= NETIF_F_HIGHDMA;
5789
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005790 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00005791 netdev->features |= NETIF_F_LRO;
5792
Auke Kok9a799d72007-09-15 14:07:45 -07005793 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005794 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Auke Kok9a799d72007-09-15 14:07:45 -07005795 dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n");
5796 err = -EIO;
5797 goto err_eeprom;
5798 }
5799
5800 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
5801 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
5802
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005803 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
5804 dev_err(&pdev->dev, "invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005805 err = -EIO;
5806 goto err_eeprom;
5807 }
5808
5809 init_timer(&adapter->watchdog_timer);
5810 adapter->watchdog_timer.function = &ixgbe_watchdog;
5811 adapter->watchdog_timer.data = (unsigned long)adapter;
5812
5813 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005814 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005815
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005816 err = ixgbe_init_interrupt_scheme(adapter);
5817 if (err)
5818 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07005819
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005820 switch (pdev->device) {
5821 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005822 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
5823 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
Peter P Waskiewicz Jrbdf0a552009-06-04 11:09:58 +00005824 /* Enable ACPI wakeup in GRC */
5825 IXGBE_WRITE_REG(hw, IXGBE_GRC,
5826 (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME));
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005827 break;
5828 default:
5829 adapter->wol = 0;
5830 break;
5831 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005832 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
5833
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00005834 /* pick up the PCI bus settings for reporting later */
5835 hw->mac.ops.get_bus_info(hw);
5836
Auke Kok9a799d72007-09-15 14:07:45 -07005837 /* print bus type/speed/width info */
Johannes Berg7c510e42008-10-27 17:47:26 -07005838 dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n",
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005839 ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s":
5840 (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"),
5841 ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" :
5842 (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" :
5843 (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" :
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005844 "Unknown"),
Johannes Berg7c510e42008-10-27 17:47:26 -07005845 netdev->dev_addr);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005846 ixgbe_read_pba_num_generic(hw, &part_num);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005847 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
5848 dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n",
5849 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
5850 (part_num >> 8), (part_num & 0xff));
5851 else
5852 dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
5853 hw->mac.type, hw->phy.type,
5854 (part_num >> 8), (part_num & 0xff));
Auke Kok9a799d72007-09-15 14:07:45 -07005855
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005856 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Auke Kok0c254d82008-02-11 09:25:56 -08005857 dev_warn(&pdev->dev, "PCI-Express bandwidth available for "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005858 "this card is not sufficient for optimal "
5859 "performance.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005860 dev_warn(&pdev->dev, "For optimal performance a x8 "
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005861 "PCI-Express slot is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08005862 }
5863
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08005864 /* save off EEPROM version number */
5865 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
5866
Auke Kok9a799d72007-09-15 14:07:45 -07005867 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005868 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005869
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005870 if (err == IXGBE_ERR_EEPROM_VERSION) {
5871 /* We are running on a pre-production device, log a warning */
5872 dev_warn(&pdev->dev, "This device is a pre-production "
5873 "adapter/LOM. Please be aware there may be issues "
5874 "associated with your hardware. If you are "
5875 "experiencing problems please contact your Intel or "
5876 "hardware representative who provided you with this "
5877 "hardware.\n");
5878 }
Auke Kok9a799d72007-09-15 14:07:45 -07005879 strcpy(netdev->name, "eth%d");
5880 err = register_netdev(netdev);
5881 if (err)
5882 goto err_register;
5883
Jesse Brandeburg54386462009-04-17 20:44:27 +00005884 /* carrier off reporting is important to ethtool even BEFORE open */
5885 netif_carrier_off(netdev);
5886
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005887 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5888 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5889 INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
5890
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005891#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03005892 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005893 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005894 ixgbe_setup_dca(adapter);
5895 }
5896#endif
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005897 /* add san mac addr to netdev */
5898 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005899
5900 dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n");
5901 cards_found++;
5902 return 0;
5903
5904err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005905 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005906 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005907err_sw_init:
5908err_eeprom:
Donald Skidmorec4900be2008-11-20 21:11:42 -08005909 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5910 del_timer_sync(&adapter->sfp_timer);
5911 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005912 cancel_work_sync(&adapter->multispeed_fiber_task);
5913 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005914 iounmap(hw->hw_addr);
5915err_ioremap:
5916 free_netdev(netdev);
5917err_alloc_etherdev:
gouji-new9ce77662009-05-06 10:44:45 +00005918 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5919 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005920err_pci_reg:
5921err_dma:
5922 pci_disable_device(pdev);
5923 return err;
5924}
5925
5926/**
5927 * ixgbe_remove - Device Removal Routine
5928 * @pdev: PCI device information struct
5929 *
5930 * ixgbe_remove is called by the PCI subsystem to alert the driver
5931 * that it should release a PCI device. The could be caused by a
5932 * Hot-Plug event, or because the driver is going to be removed from
5933 * memory.
5934 **/
5935static void __devexit ixgbe_remove(struct pci_dev *pdev)
5936{
5937 struct net_device *netdev = pci_get_drvdata(pdev);
5938 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5939
5940 set_bit(__IXGBE_DOWN, &adapter->state);
Donald Skidmorec4900be2008-11-20 21:11:42 -08005941 /* clear the module not found bit to make sure the worker won't
5942 * reschedule
5943 */
5944 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07005945 del_timer_sync(&adapter->watchdog_timer);
5946
Donald Skidmorec4900be2008-11-20 21:11:42 -08005947 del_timer_sync(&adapter->sfp_timer);
5948 cancel_work_sync(&adapter->watchdog_task);
5949 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005950 cancel_work_sync(&adapter->multispeed_fiber_task);
5951 cancel_work_sync(&adapter->sfp_config_module_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005952 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5953 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
5954 cancel_work_sync(&adapter->fdir_reinit_task);
Auke Kok9a799d72007-09-15 14:07:45 -07005955 flush_scheduled_work();
5956
Jeff Garzik5dd2d332008-10-16 05:09:31 -04005957#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08005958 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
5959 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
5960 dca_remove_requester(&pdev->dev);
5961 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
5962 }
5963
5964#endif
Yi Zou332d4a72009-05-13 13:11:53 +00005965#ifdef IXGBE_FCOE
5966 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
5967 ixgbe_cleanup_fcoe(adapter);
5968
5969#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00005970
5971 /* remove the added san mac */
5972 ixgbe_del_sanmac_netdev(netdev);
5973
Donald Skidmorec4900be2008-11-20 21:11:42 -08005974 if (netdev->reg_state == NETREG_REGISTERED)
5975 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005976
Alexander Duyck7a921c92009-05-06 10:43:28 +00005977 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005978
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005979 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005980
5981 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00005982 pci_release_selected_regions(pdev, pci_select_bars(pdev,
5983 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07005984
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005985 DPRINTK(PROBE, INFO, "complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005986
Auke Kok9a799d72007-09-15 14:07:45 -07005987 free_netdev(netdev);
5988
Frans Pop19d5afd2009-10-02 10:04:12 -07005989 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08005990
Auke Kok9a799d72007-09-15 14:07:45 -07005991 pci_disable_device(pdev);
5992}
5993
5994/**
5995 * ixgbe_io_error_detected - called when PCI error is detected
5996 * @pdev: Pointer to PCI device
5997 * @state: The current pci connection state
5998 *
5999 * This function is called after a PCI bus error affecting
6000 * this device has been detected.
6001 */
6002static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006003 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07006004{
6005 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08006006 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006007
6008 netif_device_detach(netdev);
6009
Breno Leitao3044b8d2009-05-06 10:44:26 +00006010 if (state == pci_channel_io_perm_failure)
6011 return PCI_ERS_RESULT_DISCONNECT;
6012
Auke Kok9a799d72007-09-15 14:07:45 -07006013 if (netif_running(netdev))
6014 ixgbe_down(adapter);
6015 pci_disable_device(pdev);
6016
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006017 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07006018 return PCI_ERS_RESULT_NEED_RESET;
6019}
6020
6021/**
6022 * ixgbe_io_slot_reset - called after the pci bus has been reset.
6023 * @pdev: Pointer to PCI device
6024 *
6025 * Restart the card from scratch, as if from a cold-boot.
6026 */
6027static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
6028{
6029 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08006030 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006031 pci_ers_result_t result;
6032 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07006033
gouji-new9ce77662009-05-06 10:44:45 +00006034 if (pci_enable_device_mem(pdev)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006035 DPRINTK(PROBE, ERR,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006036 "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006037 result = PCI_ERS_RESULT_DISCONNECT;
6038 } else {
6039 pci_set_master(pdev);
6040 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00006041 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006042
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006043 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006044
6045 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00006046 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006047 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07006048 }
Auke Kok9a799d72007-09-15 14:07:45 -07006049
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006050 err = pci_cleanup_aer_uncorrect_error_status(pdev);
6051 if (err) {
6052 dev_err(&pdev->dev,
6053 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err);
6054 /* non-fatal, continue */
6055 }
Auke Kok9a799d72007-09-15 14:07:45 -07006056
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08006057 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07006058}
6059
6060/**
6061 * ixgbe_io_resume - called when traffic can start flowing again.
6062 * @pdev: Pointer to PCI device
6063 *
6064 * This callback is called when the error recovery driver tells us that
6065 * its OK to resume normal operation.
6066 */
6067static void ixgbe_io_resume(struct pci_dev *pdev)
6068{
6069 struct net_device *netdev = pci_get_drvdata(pdev);
Wang Chen454d7c92008-11-12 23:37:49 -08006070 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006071
6072 if (netif_running(netdev)) {
6073 if (ixgbe_up(adapter)) {
6074 DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n");
6075 return;
6076 }
6077 }
6078
6079 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006080}
6081
6082static struct pci_error_handlers ixgbe_err_handler = {
6083 .error_detected = ixgbe_io_error_detected,
6084 .slot_reset = ixgbe_io_slot_reset,
6085 .resume = ixgbe_io_resume,
6086};
6087
6088static struct pci_driver ixgbe_driver = {
6089 .name = ixgbe_driver_name,
6090 .id_table = ixgbe_pci_tbl,
6091 .probe = ixgbe_probe,
6092 .remove = __devexit_p(ixgbe_remove),
6093#ifdef CONFIG_PM
6094 .suspend = ixgbe_suspend,
6095 .resume = ixgbe_resume,
6096#endif
6097 .shutdown = ixgbe_shutdown,
6098 .err_handler = &ixgbe_err_handler
6099};
6100
6101/**
6102 * ixgbe_init_module - Driver Registration Routine
6103 *
6104 * ixgbe_init_module is the first routine called when the driver is
6105 * loaded. All it does is register with the PCI subsystem.
6106 **/
6107static int __init ixgbe_init_module(void)
6108{
6109 int ret;
6110 printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name,
6111 ixgbe_driver_string, ixgbe_driver_version);
6112
6113 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
6114
Jeff Garzik5dd2d332008-10-16 05:09:31 -04006115#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006116 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006117#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04006118
Auke Kok9a799d72007-09-15 14:07:45 -07006119 ret = pci_register_driver(&ixgbe_driver);
6120 return ret;
6121}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006122
Auke Kok9a799d72007-09-15 14:07:45 -07006123module_init(ixgbe_init_module);
6124
6125/**
6126 * ixgbe_exit_module - Driver Exit Cleanup Routine
6127 *
6128 * ixgbe_exit_module is called just before the driver is removed
6129 * from memory.
6130 **/
6131static void __exit ixgbe_exit_module(void)
6132{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04006133#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006134 dca_unregister_notify(&dca_notifier);
6135#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006136 pci_unregister_driver(&ixgbe_driver);
6137}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006138
Jeff Garzik5dd2d332008-10-16 05:09:31 -04006139#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006140static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006141 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006142{
6143 int ret_val;
6144
6145 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006146 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006147
6148 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
6149}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08006150
Alexander Duyckb4533682009-03-31 21:32:42 +00006151#endif /* CONFIG_IXGBE_DCA */
6152#ifdef DEBUG
6153/**
6154 * ixgbe_get_hw_dev_name - return device name string
6155 * used by hardware layer to print debugging information
6156 **/
6157char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw)
6158{
6159 struct ixgbe_adapter *adapter = hw->back;
6160 return adapter->netdev->name;
6161}
6162
6163#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006164module_exit(ixgbe_exit_module);
6165
6166/* ixgbe_main.c */