blob: f8a22eb89dafdc40681809aa273015aa8a0f774c [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmorea52055e2011-02-23 09:58:39 +00004 Copyright(c) 1999 - 2011 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>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Lucy Liu60127862009-07-22 14:07:33 +000038#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070039#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090040#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070041#include <net/checksum.h>
42#include <net/ip6_checksum.h>
43#include <linux/ethtool.h>
44#include <linux/if_vlan.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040045#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000046#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070047
48#include "ixgbe.h"
49#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000050#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000051#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070052
53char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070054static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000055 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000056#define MAJ 3
Don Skidmorea38a1042011-05-20 03:05:14 +000057#define MIN 4
Don Skidmorec89c7112011-04-14 07:40:11 +000058#define BUILD 8
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000059#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000060 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070061const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000062static const char ixgbe_copyright[] =
63 "Copyright (c) 1999-2011 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070064
65static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070066 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000067 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080068 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070069};
70
71/* ixgbe_pci_tbl - PCI Device ID Table
72 *
73 * Wildcard entries (PCI_ANY_ID) should come last
74 * Last entry must be all 0s
75 *
76 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
77 * Class, Class Mask, private data (not used) }
78 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000079static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Don Skidmore1e336d02009-01-26 20:57:51 -080080 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
81 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070082 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070083 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070084 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070085 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070086 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
87 board_82598 },
Peter P Waskiewicz Jr3845bec2009-07-16 15:50:52 +000088 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
89 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070090 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070091 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070092 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
93 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080094 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
95 board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
97 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070098 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
99 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -0800100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
101 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -0800102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
103 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
105 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +0000106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
107 board_82599 },
Don Skidmore74757d42009-12-08 07:22:23 +0000108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
109 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
111 board_82599 },
Don Skidmore38ad1c82009-10-08 15:35:58 +0000112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
113 board_82599 },
Don Skidmoredbfec662009-10-02 08:58:25 +0000114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
115 board_82599 },
Peter P Waskiewicz Jr8911184f2009-09-14 07:47:49 +0000116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
117 board_82599 },
Don Skidmoredbffcb22010-12-03 03:32:34 +0000118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE),
119 board_82599 },
120 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE),
121 board_82599 },
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700122 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM),
123 board_82599 },
Don Skidmore312eb932009-10-02 08:58:04 +0000124 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
125 board_82599 },
Don Skidmoreb93a2222010-11-16 19:27:17 -0800126 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T),
Don Skidmored9946532010-12-09 06:55:19 +0000127 board_X540 },
Emil Tantilov4c40ef02011-03-24 07:06:02 +0000128 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2),
129 board_82599 },
Don Skidmore4f6290c2011-05-14 06:36:35 +0000130 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS),
131 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700132
133 /* required last entry */
134 {0, }
135};
136MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
137
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400138#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800139static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000140 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800141static struct notifier_block dca_notifier = {
142 .notifier_call = ixgbe_notify_dca,
143 .next = NULL,
144 .priority = 0
145};
146#endif
147
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000148#ifdef CONFIG_PCI_IOV
149static unsigned int max_vfs;
150module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000151MODULE_PARM_DESC(max_vfs,
152 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000153#endif /* CONFIG_PCI_IOV */
154
Auke Kok9a799d72007-09-15 14:07:45 -0700155MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
156MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
157MODULE_LICENSE("GPL");
158MODULE_VERSION(DRV_VERSION);
159
160#define DEFAULT_DEBUG_LEVEL_SHIFT 3
161
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000162static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
163{
164 struct ixgbe_hw *hw = &adapter->hw;
165 u32 gcr;
166 u32 gpie;
167 u32 vmdctl;
168
169#ifdef CONFIG_PCI_IOV
170 /* disable iov and allow time for transactions to clear */
171 pci_disable_sriov(adapter->pdev);
172#endif
173
174 /* turn off device IOV mode */
175 gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
176 gcr &= ~(IXGBE_GCR_EXT_SRIOV);
177 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
178 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
179 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
180 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
181
182 /* set default pool back to 0 */
183 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
184 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
185 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
186
187 /* take a breather then clean up driver data */
188 msleep(100);
Joe Perchese8e9f692010-09-07 21:34:53 +0000189
190 kfree(adapter->vfinfo);
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000191 adapter->vfinfo = NULL;
192
193 adapter->num_vfs = 0;
194 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
195}
196
Alexander Duyck70864002011-04-27 09:13:56 +0000197static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
198{
199 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
200 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
201 schedule_work(&adapter->service_task);
202}
203
204static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
205{
206 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
207
208 /* flush memory to make sure state is correct before next watchog */
209 smp_mb__before_clear_bit();
210 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
211}
212
Taku Izumidcd79ae2010-04-27 14:39:53 +0000213struct ixgbe_reg_info {
214 u32 ofs;
215 char *name;
216};
217
218static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
219
220 /* General Registers */
221 {IXGBE_CTRL, "CTRL"},
222 {IXGBE_STATUS, "STATUS"},
223 {IXGBE_CTRL_EXT, "CTRL_EXT"},
224
225 /* Interrupt Registers */
226 {IXGBE_EICR, "EICR"},
227
228 /* RX Registers */
229 {IXGBE_SRRCTL(0), "SRRCTL"},
230 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
231 {IXGBE_RDLEN(0), "RDLEN"},
232 {IXGBE_RDH(0), "RDH"},
233 {IXGBE_RDT(0), "RDT"},
234 {IXGBE_RXDCTL(0), "RXDCTL"},
235 {IXGBE_RDBAL(0), "RDBAL"},
236 {IXGBE_RDBAH(0), "RDBAH"},
237
238 /* TX Registers */
239 {IXGBE_TDBAL(0), "TDBAL"},
240 {IXGBE_TDBAH(0), "TDBAH"},
241 {IXGBE_TDLEN(0), "TDLEN"},
242 {IXGBE_TDH(0), "TDH"},
243 {IXGBE_TDT(0), "TDT"},
244 {IXGBE_TXDCTL(0), "TXDCTL"},
245
246 /* List Terminator */
247 {}
248};
249
250
251/*
252 * ixgbe_regdump - register printout routine
253 */
254static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
255{
256 int i = 0, j = 0;
257 char rname[16];
258 u32 regs[64];
259
260 switch (reginfo->ofs) {
261 case IXGBE_SRRCTL(0):
262 for (i = 0; i < 64; i++)
263 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
264 break;
265 case IXGBE_DCA_RXCTRL(0):
266 for (i = 0; i < 64; i++)
267 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
268 break;
269 case IXGBE_RDLEN(0):
270 for (i = 0; i < 64; i++)
271 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
272 break;
273 case IXGBE_RDH(0):
274 for (i = 0; i < 64; i++)
275 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
276 break;
277 case IXGBE_RDT(0):
278 for (i = 0; i < 64; i++)
279 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
280 break;
281 case IXGBE_RXDCTL(0):
282 for (i = 0; i < 64; i++)
283 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
284 break;
285 case IXGBE_RDBAL(0):
286 for (i = 0; i < 64; i++)
287 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
288 break;
289 case IXGBE_RDBAH(0):
290 for (i = 0; i < 64; i++)
291 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
292 break;
293 case IXGBE_TDBAL(0):
294 for (i = 0; i < 64; i++)
295 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
296 break;
297 case IXGBE_TDBAH(0):
298 for (i = 0; i < 64; i++)
299 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
300 break;
301 case IXGBE_TDLEN(0):
302 for (i = 0; i < 64; i++)
303 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
304 break;
305 case IXGBE_TDH(0):
306 for (i = 0; i < 64; i++)
307 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
308 break;
309 case IXGBE_TDT(0):
310 for (i = 0; i < 64; i++)
311 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
312 break;
313 case IXGBE_TXDCTL(0):
314 for (i = 0; i < 64; i++)
315 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
316 break;
317 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000318 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000319 IXGBE_READ_REG(hw, reginfo->ofs));
320 return;
321 }
322
323 for (i = 0; i < 8; i++) {
324 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000325 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000326 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000327 pr_cont(" %08x", regs[i*8+j]);
328 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000329 }
330
331}
332
333/*
334 * ixgbe_dump - Print registers, tx-rings and rx-rings
335 */
336static void ixgbe_dump(struct ixgbe_adapter *adapter)
337{
338 struct net_device *netdev = adapter->netdev;
339 struct ixgbe_hw *hw = &adapter->hw;
340 struct ixgbe_reg_info *reginfo;
341 int n = 0;
342 struct ixgbe_ring *tx_ring;
343 struct ixgbe_tx_buffer *tx_buffer_info;
344 union ixgbe_adv_tx_desc *tx_desc;
345 struct my_u0 { u64 a; u64 b; } *u0;
346 struct ixgbe_ring *rx_ring;
347 union ixgbe_adv_rx_desc *rx_desc;
348 struct ixgbe_rx_buffer *rx_buffer_info;
349 u32 staterr;
350 int i = 0;
351
352 if (!netif_msg_hw(adapter))
353 return;
354
355 /* Print netdevice Info */
356 if (netdev) {
357 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000358 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000359 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000360 pr_info("%-15s %016lX %016lX %016lX\n",
361 netdev->name,
362 netdev->state,
363 netdev->trans_start,
364 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000365 }
366
367 /* Print Registers */
368 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000369 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000370 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
371 reginfo->name; reginfo++) {
372 ixgbe_regdump(hw, reginfo);
373 }
374
375 /* Print TX Ring Summary */
376 if (!netdev || !netif_running(netdev))
377 goto exit;
378
379 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000380 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000381 for (n = 0; n < adapter->num_tx_queues; n++) {
382 tx_ring = adapter->tx_ring[n];
383 tx_buffer_info =
384 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Joe Perchesc7689572010-09-07 21:35:17 +0000385 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000386 n, tx_ring->next_to_use, tx_ring->next_to_clean,
387 (u64)tx_buffer_info->dma,
388 tx_buffer_info->length,
389 tx_buffer_info->next_to_watch,
390 (u64)tx_buffer_info->time_stamp);
391 }
392
393 /* Print TX Rings */
394 if (!netif_msg_tx_done(adapter))
395 goto rx_ring_summary;
396
397 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
398
399 /* Transmit Descriptor Formats
400 *
401 * Advanced Transmit Descriptor
402 * +--------------------------------------------------------------+
403 * 0 | Buffer Address [63:0] |
404 * +--------------------------------------------------------------+
405 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
406 * +--------------------------------------------------------------+
407 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
408 */
409
410 for (n = 0; n < adapter->num_tx_queues; n++) {
411 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000412 pr_info("------------------------------------\n");
413 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
414 pr_info("------------------------------------\n");
415 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000416 "[PlPOIdStDDt Ln] [bi->dma ] "
417 "leng ntw timestamp bi->skb\n");
418
419 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000420 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000421 tx_buffer_info = &tx_ring->tx_buffer_info[i];
422 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000423 pr_info("T [0x%03X] %016llX %016llX %016llX"
Taku Izumidcd79ae2010-04-27 14:39:53 +0000424 " %04X %3X %016llX %p", i,
425 le64_to_cpu(u0->a),
426 le64_to_cpu(u0->b),
427 (u64)tx_buffer_info->dma,
428 tx_buffer_info->length,
429 tx_buffer_info->next_to_watch,
430 (u64)tx_buffer_info->time_stamp,
431 tx_buffer_info->skb);
432 if (i == tx_ring->next_to_use &&
433 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000434 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000435 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000436 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000437 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000438 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000439 else
Joe Perchesc7689572010-09-07 21:35:17 +0000440 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000441
442 if (netif_msg_pktdata(adapter) &&
443 tx_buffer_info->dma != 0)
444 print_hex_dump(KERN_INFO, "",
445 DUMP_PREFIX_ADDRESS, 16, 1,
446 phys_to_virt(tx_buffer_info->dma),
447 tx_buffer_info->length, true);
448 }
449 }
450
451 /* Print RX Rings Summary */
452rx_ring_summary:
453 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000454 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000455 for (n = 0; n < adapter->num_rx_queues; n++) {
456 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000457 pr_info("%5d %5X %5X\n",
458 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000459 }
460
461 /* Print RX Rings */
462 if (!netif_msg_rx_status(adapter))
463 goto exit;
464
465 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
466
467 /* Advanced Receive Descriptor (Read) Format
468 * 63 1 0
469 * +-----------------------------------------------------+
470 * 0 | Packet Buffer Address [63:1] |A0/NSE|
471 * +----------------------------------------------+------+
472 * 8 | Header Buffer Address [63:1] | DD |
473 * +-----------------------------------------------------+
474 *
475 *
476 * Advanced Receive Descriptor (Write-Back) Format
477 *
478 * 63 48 47 32 31 30 21 20 16 15 4 3 0
479 * +------------------------------------------------------+
480 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
481 * | Checksum Ident | | | | Type | Type |
482 * +------------------------------------------------------+
483 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
484 * +------------------------------------------------------+
485 * 63 48 47 32 31 20 19 0
486 */
487 for (n = 0; n < adapter->num_rx_queues; n++) {
488 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000489 pr_info("------------------------------------\n");
490 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
491 pr_info("------------------------------------\n");
492 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000493 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
494 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000495 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000496 "[vl er S cks ln] ---------------- [bi->skb] "
497 "<-- Adv Rx Write-Back format\n");
498
499 for (i = 0; i < rx_ring->count; i++) {
500 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +0000501 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000502 u0 = (struct my_u0 *)rx_desc;
503 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
504 if (staterr & IXGBE_RXD_STAT_DD) {
505 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000506 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000507 "%016llX ---------------- %p", i,
508 le64_to_cpu(u0->a),
509 le64_to_cpu(u0->b),
510 rx_buffer_info->skb);
511 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000512 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000513 "%016llX %016llX %p", i,
514 le64_to_cpu(u0->a),
515 le64_to_cpu(u0->b),
516 (u64)rx_buffer_info->dma,
517 rx_buffer_info->skb);
518
519 if (netif_msg_pktdata(adapter)) {
520 print_hex_dump(KERN_INFO, "",
521 DUMP_PREFIX_ADDRESS, 16, 1,
522 phys_to_virt(rx_buffer_info->dma),
523 rx_ring->rx_buf_len, true);
524
525 if (rx_ring->rx_buf_len
526 < IXGBE_RXBUFFER_2048)
527 print_hex_dump(KERN_INFO, "",
528 DUMP_PREFIX_ADDRESS, 16, 1,
529 phys_to_virt(
530 rx_buffer_info->page_dma +
531 rx_buffer_info->page_offset
532 ),
533 PAGE_SIZE/2, true);
534 }
535 }
536
537 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000538 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000539 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000540 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000541 else
Joe Perchesc7689572010-09-07 21:35:17 +0000542 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000543
544 }
545 }
546
547exit:
548 return;
549}
550
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800551static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
552{
553 u32 ctrl_ext;
554
555 /* Let firmware take over control of h/w */
556 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
557 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000558 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800559}
560
561static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
562{
563 u32 ctrl_ext;
564
565 /* Let firmware know the driver has taken over */
566 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
567 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000568 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800569}
Auke Kok9a799d72007-09-15 14:07:45 -0700570
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000571/*
572 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
573 * @adapter: pointer to adapter struct
574 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
575 * @queue: queue to map the corresponding interrupt to
576 * @msix_vector: the vector to map to the corresponding queue
577 *
578 */
579static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000580 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700581{
582 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000583 struct ixgbe_hw *hw = &adapter->hw;
584 switch (hw->mac.type) {
585 case ixgbe_mac_82598EB:
586 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
587 if (direction == -1)
588 direction = 0;
589 index = (((direction * 64) + queue) >> 2) & 0x1F;
590 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
591 ivar &= ~(0xFF << (8 * (queue & 0x3)));
592 ivar |= (msix_vector << (8 * (queue & 0x3)));
593 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
594 break;
595 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800596 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000597 if (direction == -1) {
598 /* other causes */
599 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
600 index = ((queue & 1) * 8);
601 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
602 ivar &= ~(0xFF << index);
603 ivar |= (msix_vector << index);
604 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
605 break;
606 } else {
607 /* tx or rx causes */
608 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
609 index = ((16 * (queue & 1)) + (8 * direction));
610 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
611 ivar &= ~(0xFF << index);
612 ivar |= (msix_vector << index);
613 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
614 break;
615 }
616 default:
617 break;
618 }
Auke Kok9a799d72007-09-15 14:07:45 -0700619}
620
Alexander Duyckfe49f042009-06-04 16:00:09 +0000621static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000622 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000623{
624 u32 mask;
625
Alexander Duyckbd508172010-11-16 19:27:03 -0800626 switch (adapter->hw.mac.type) {
627 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000628 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
629 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800630 break;
631 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800632 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000633 mask = (qmask & 0xFFFFFFFF);
634 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
635 mask = (qmask >> 32);
636 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800637 break;
638 default:
639 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000640 }
641}
642
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800643void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
644 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700645{
Alexander Duycke5a43542009-12-02 16:46:56 +0000646 if (tx_buffer_info->dma) {
647 if (tx_buffer_info->mapped_as_page)
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800648 dma_unmap_page(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000649 tx_buffer_info->dma,
650 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000651 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000652 else
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800653 dma_unmap_single(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000654 tx_buffer_info->dma,
655 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000656 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000657 tx_buffer_info->dma = 0;
658 }
Auke Kok9a799d72007-09-15 14:07:45 -0700659 if (tx_buffer_info->skb) {
660 dev_kfree_skb_any(tx_buffer_info->skb);
661 tx_buffer_info->skb = NULL;
662 }
Alexander Duyck44df32c2009-03-31 21:34:23 +0000663 tx_buffer_info->time_stamp = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700664 /* tx_buffer_info must be completely set up in the transmit path */
665}
666
John Fastabendc84d3242010-11-16 19:27:12 -0800667static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700668{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700669 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800670 struct ixgbe_hw_stats *hwstats = &adapter->stats;
671 u32 data = 0;
672 u32 xoff[8] = {0};
673 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700674
John Fastabendc84d3242010-11-16 19:27:12 -0800675 if ((hw->fc.current_mode == ixgbe_fc_full) ||
676 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
677 switch (hw->mac.type) {
678 case ixgbe_mac_82598EB:
679 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
680 break;
681 default:
682 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
683 }
684 hwstats->lxoffrxc += data;
685
686 /* refill credits (no tx hang) if we received xoff */
687 if (!data)
688 return;
689
690 for (i = 0; i < adapter->num_tx_queues; i++)
691 clear_bit(__IXGBE_HANG_CHECK_ARMED,
692 &adapter->tx_ring[i]->state);
693 return;
694 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
695 return;
696
697 /* update stats for each tc, only valid with PFC enabled */
698 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
699 switch (hw->mac.type) {
700 case ixgbe_mac_82598EB:
701 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
702 break;
703 default:
704 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
705 }
706 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700707 }
708
John Fastabendc84d3242010-11-16 19:27:12 -0800709 /* disarm tx queues that have received xoff frames */
710 for (i = 0; i < adapter->num_tx_queues; i++) {
711 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000712 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800713
714 if (xoff[tc])
715 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
716 }
717}
718
719static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
720{
721 return ring->tx_stats.completed;
722}
723
724static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
725{
726 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
727 struct ixgbe_hw *hw = &adapter->hw;
728
729 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
730 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
731
732 if (head != tail)
733 return (head < tail) ?
734 tail - head : (tail + ring->count - head);
735
736 return 0;
737}
738
739static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
740{
741 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
742 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
743 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
744 bool ret = false;
745
746 clear_check_for_tx_hang(tx_ring);
747
748 /*
749 * Check for a hung queue, but be thorough. This verifies
750 * that a transmit has been completed since the previous
751 * check AND there is at least one packet pending. The
752 * ARMED bit is set to indicate a potential hang. The
753 * bit is cleared if a pause frame is received to remove
754 * false hang detection due to PFC or 802.3x frames. By
755 * requiring this to fail twice we avoid races with
756 * pfc clearing the ARMED bit and conditions where we
757 * run the check_tx_hang logic with a transmit completion
758 * pending but without time to complete it yet.
759 */
760 if ((tx_done_old == tx_done) && tx_pending) {
761 /* make sure it is true for two checks in a row */
762 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
763 &tx_ring->state);
764 } else {
765 /* update completed stats and continue */
766 tx_ring->tx_stats.tx_done_old = tx_done;
767 /* reset the countdown */
768 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
769 }
770
771 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700772}
773
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700774#define IXGBE_MAX_TXD_PWR 14
775#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800776
777/* Tx Descriptors needed, worst case */
778#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
779 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
780#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700781 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800782
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000783/**
784 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
785 * @adapter: driver private struct
786 **/
787static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
788{
789
790 /* Do the reset outside of interrupt context */
791 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
792 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
793 ixgbe_service_event_schedule(adapter);
794 }
795}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700796
Auke Kok9a799d72007-09-15 14:07:45 -0700797/**
798 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000799 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700800 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700801 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000802static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000803 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700804{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000805 struct ixgbe_adapter *adapter = q_vector->adapter;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800806 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
807 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700808 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyckb9537992010-11-16 19:26:58 -0800809 u16 i, eop, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700810
811 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800812 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000813 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800814
815 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000816 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800817 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000818 rmb(); /* read buffer_info after eop_desc */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800819 for ( ; !cleaned; count++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000820 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700821 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700822
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800823 tx_desc->wb.status = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800824 cleaned = (i == eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800825
Auke Kok9a799d72007-09-15 14:07:45 -0700826 i++;
827 if (i == tx_ring->count)
828 i = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800829
830 if (cleaned && tx_buffer_info->skb) {
831 total_bytes += tx_buffer_info->bytecount;
832 total_packets += tx_buffer_info->gso_segs;
833 }
834
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800835 ixgbe_unmap_and_free_tx_resource(tx_ring,
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800836 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700837 }
838
John Fastabendc84d3242010-11-16 19:27:12 -0800839 tx_ring->tx_stats.completed++;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800840 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000841 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800842 }
843
Auke Kok9a799d72007-09-15 14:07:45 -0700844 tx_ring->next_to_clean = i;
Alexander Duyckb9537992010-11-16 19:26:58 -0800845 tx_ring->total_bytes += total_bytes;
846 tx_ring->total_packets += total_packets;
847 u64_stats_update_begin(&tx_ring->syncp);
848 tx_ring->stats.packets += total_packets;
849 tx_ring->stats.bytes += total_bytes;
850 u64_stats_update_end(&tx_ring->syncp);
851
John Fastabendc84d3242010-11-16 19:27:12 -0800852 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800853 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800854 struct ixgbe_hw *hw = &adapter->hw;
855 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
856 e_err(drv, "Detected Tx Unit Hang\n"
857 " Tx Queue <%d>\n"
858 " TDH, TDT <%x>, <%x>\n"
859 " next_to_use <%x>\n"
860 " next_to_clean <%x>\n"
861 "tx_buffer_info[next_to_clean]\n"
862 " time_stamp <%lx>\n"
863 " jiffies <%lx>\n",
864 tx_ring->queue_index,
865 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
866 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
867 tx_ring->next_to_use, eop,
868 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
869
870 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
871
872 e_info(probe,
873 "tx hang %d detected on queue %d, resetting adapter\n",
874 adapter->tx_timeout_count + 1, tx_ring->queue_index);
875
876 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000877 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800878
879 /* the adapter is about to reset, no point in enabling stuff */
880 return true;
881 }
Auke Kok9a799d72007-09-15 14:07:45 -0700882
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800883#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800884 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000885 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800886 /* Make sure that anybody stopping the queue after this
887 * sees the new next_to_clean.
888 */
889 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800890 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800891 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800892 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800893 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800894 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800895 }
Auke Kok9a799d72007-09-15 14:07:45 -0700896
Eric Dumazet807540b2010-09-23 05:40:09 +0000897 return count < tx_ring->work_limit;
Auke Kok9a799d72007-09-15 14:07:45 -0700898}
899
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400900#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800901static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800902 struct ixgbe_ring *rx_ring,
903 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800904{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800905 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800906 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800907 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800908
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800909 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
910 switch (hw->mac.type) {
911 case ixgbe_mac_82598EB:
912 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
913 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
914 break;
915 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800916 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800917 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
918 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
919 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
920 break;
921 default:
922 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800923 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800924 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
925 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
926 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800927 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800928}
929
930static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800931 struct ixgbe_ring *tx_ring,
932 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800933{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000934 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800935 u32 txctrl;
936 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800937
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800938 switch (hw->mac.type) {
939 case ixgbe_mac_82598EB:
940 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
941 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
942 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
943 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800944 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
945 break;
946 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800947 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800948 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
949 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
950 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
951 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
952 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800953 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
954 break;
955 default:
956 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800957 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800958}
959
960static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
961{
962 struct ixgbe_adapter *adapter = q_vector->adapter;
963 int cpu = get_cpu();
964 long r_idx;
965 int i;
966
967 if (q_vector->cpu == cpu)
968 goto out_no_update;
969
970 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
971 for (i = 0; i < q_vector->txr_count; i++) {
972 ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu);
973 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
974 r_idx + 1);
975 }
976
977 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
978 for (i = 0; i < q_vector->rxr_count; i++) {
979 ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu);
980 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
981 r_idx + 1);
982 }
983
984 q_vector->cpu = cpu;
985out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800986 put_cpu();
987}
988
989static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
990{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800991 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800992 int i;
993
994 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
995 return;
996
Alexander Duycke35ec122009-05-21 13:07:12 +0000997 /* always use CB2 mode, difference is masked in the CB driver */
998 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
999
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001000 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1001 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1002 else
1003 num_q_vectors = 1;
1004
1005 for (i = 0; i < num_q_vectors; i++) {
1006 adapter->q_vector[i]->cpu = -1;
1007 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001008 }
1009}
1010
1011static int __ixgbe_notify_dca(struct device *dev, void *data)
1012{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001013 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001014 unsigned long event = *(unsigned long *)data;
1015
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001016 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1017 return 0;
1018
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001019 switch (event) {
1020 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001021 /* if we're already enabled, don't do it again */
1022 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1023 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001024 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001025 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001026 ixgbe_setup_dca(adapter);
1027 break;
1028 }
1029 /* Fall Through since DCA is disabled. */
1030 case DCA_PROVIDER_REMOVE:
1031 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1032 dca_remove_requester(dev);
1033 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1034 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1035 }
1036 break;
1037 }
1038
Denis V. Lunev652f0932008-03-27 14:39:17 +03001039 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001040}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001041#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001042
1043static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
1044 struct sk_buff *skb)
1045{
1046 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1047}
1048
Auke Kok9a799d72007-09-15 14:07:45 -07001049/**
1050 * ixgbe_receive_skb - Send a completed packet up the stack
1051 * @adapter: board private structure
1052 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001053 * @status: hardware indication of status of receive
1054 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1055 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001056 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001057static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001058 struct sk_buff *skb, u8 status,
1059 struct ixgbe_ring *ring,
1060 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001061{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001062 struct ixgbe_adapter *adapter = q_vector->adapter;
1063 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001064 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1065 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001066
Jesse Grossf62bbb52010-10-20 13:56:10 +00001067 if (is_vlan && (tag & VLAN_VID_MASK))
1068 __vlan_hwaccel_put_tag(skb, tag);
1069
1070 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1071 napi_gro_receive(napi, skb);
1072 else
1073 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001074}
1075
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001076/**
1077 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1078 * @adapter: address of board private structure
1079 * @status_err: hardware indication of status of receive
1080 * @skb: skb currently being received and modified
1081 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001082static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001083 union ixgbe_adv_rx_desc *rx_desc,
1084 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001085{
Don Skidmore8bae1b22009-07-23 18:00:39 +00001086 u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
1087
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001088 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001089
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001090 /* Rx csum disabled */
1091 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001092 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001093
1094 /* if IP and error */
1095 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1096 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001097 adapter->hw_csum_rx_error++;
1098 return;
1099 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001100
1101 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1102 return;
1103
1104 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001105 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1106
1107 /*
1108 * 82599 errata, UDP frames with a 0 checksum can be marked as
1109 * checksum errors.
1110 */
1111 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1112 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1113 return;
1114
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001115 adapter->hw_csum_rx_error++;
1116 return;
1117 }
1118
Auke Kok9a799d72007-09-15 14:07:45 -07001119 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001120 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001121}
1122
Alexander Duyck84ea2592010-11-16 19:26:49 -08001123static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001124{
1125 /*
1126 * Force memory writes to complete before letting h/w
1127 * know there are new descriptors to fetch. (Only
1128 * applicable for weak-ordered memory model archs,
1129 * such as IA-64).
1130 */
1131 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001132 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001133}
1134
Auke Kok9a799d72007-09-15 14:07:45 -07001135/**
1136 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001137 * @rx_ring: ring to place buffers on
1138 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001139 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001140void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001141{
Auke Kok9a799d72007-09-15 14:07:45 -07001142 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001143 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001144 struct sk_buff *skb;
1145 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001146
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001147 /* do nothing if no valid netdev defined */
1148 if (!rx_ring->netdev)
1149 return;
1150
Auke Kok9a799d72007-09-15 14:07:45 -07001151 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001152 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001153 bi = &rx_ring->rx_buffer_info[i];
1154 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001155
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001156 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001157 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001158 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001159 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001160 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001161 goto no_buffers;
1162 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001163 /* initialize queue mapping */
1164 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001165 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001166 }
Auke Kok9a799d72007-09-15 14:07:45 -07001167
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001168 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001169 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001170 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001171 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001172 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001173 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001174 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001175 bi->dma = 0;
1176 goto no_buffers;
1177 }
Auke Kok9a799d72007-09-15 14:07:45 -07001178 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001179
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001180 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001181 if (!bi->page) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001182 bi->page = netdev_alloc_page(rx_ring->netdev);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001183 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001184 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001185 goto no_buffers;
1186 }
1187 }
1188
1189 if (!bi->page_dma) {
1190 /* use a half page if we're re-using */
1191 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001192 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001193 bi->page,
1194 bi->page_offset,
1195 PAGE_SIZE / 2,
1196 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001197 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001198 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001199 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001200 bi->page_dma = 0;
1201 goto no_buffers;
1202 }
1203 }
1204
1205 /* Refresh the desc even if buffer_addrs didn't change
1206 * because each write-back erases this info. */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001207 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1208 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001209 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001210 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001211 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001212 }
1213
1214 i++;
1215 if (i == rx_ring->count)
1216 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001217 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001218
Auke Kok9a799d72007-09-15 14:07:45 -07001219no_buffers:
1220 if (rx_ring->next_to_use != i) {
1221 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001222 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001223 }
1224}
1225
Alexander Duyckc267fc12010-11-16 19:27:00 -08001226static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001227{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001228 /* HW will not DMA in data larger than the given buffer, even if it
1229 * parses the (NFS, of course) header to be larger. In that case, it
1230 * fills the header buffer and spills the rest into the page.
1231 */
1232 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1233 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1234 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1235 if (hlen > IXGBE_RX_HDR_SIZE)
1236 hlen = IXGBE_RX_HDR_SIZE;
1237 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001238}
1239
Alexander Duyckf8212f92009-04-27 22:42:37 +00001240/**
1241 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1242 * @skb: pointer to the last skb in the rsc queue
1243 *
1244 * This function changes a queue full of hw rsc buffers into a completed
1245 * packet. It uses the ->prev pointers to find the first packet and then
1246 * turns it into the frag list owner.
1247 **/
Alexander Duyckaa801752010-11-16 19:27:02 -08001248static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001249{
1250 unsigned int frag_list_size = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001251 unsigned int skb_cnt = 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001252
1253 while (skb->prev) {
1254 struct sk_buff *prev = skb->prev;
1255 frag_list_size += skb->len;
1256 skb->prev = NULL;
1257 skb = prev;
Alexander Duyckaa801752010-11-16 19:27:02 -08001258 skb_cnt++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001259 }
1260
1261 skb_shinfo(skb)->frag_list = skb->next;
1262 skb->next = NULL;
1263 skb->len += frag_list_size;
1264 skb->data_len += frag_list_size;
1265 skb->truesize += frag_list_size;
Alexander Duyckaa801752010-11-16 19:27:02 -08001266 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1267
Alexander Duyckf8212f92009-04-27 22:42:37 +00001268 return skb;
1269}
1270
Alexander Duyckaa801752010-11-16 19:27:02 -08001271static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1272{
1273 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1274 IXGBE_RXDADV_RSCCNT_MASK);
1275}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001276
Alexander Duyckc267fc12010-11-16 19:27:00 -08001277static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001278 struct ixgbe_ring *rx_ring,
1279 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -07001280{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001281 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001282 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1283 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1284 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001285 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001286 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001287#ifdef IXGBE_FCOE
1288 int ddp_bytes = 0;
1289#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001290 u32 staterr;
1291 u16 i;
1292 u16 cleaned_count = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001293 bool pkt_is_rsc = false;
Auke Kok9a799d72007-09-15 14:07:45 -07001294
1295 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001296 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001297 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001298
1299 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001300 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001301
Milton Miller3c945e52010-02-19 17:44:42 +00001302 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001303
Alexander Duyckc267fc12010-11-16 19:27:00 -08001304 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1305
Auke Kok9a799d72007-09-15 14:07:45 -07001306 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001307 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001308 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001309
Alexander Duyckc267fc12010-11-16 19:27:00 -08001310 if (ring_is_rsc_enabled(rx_ring))
Alexander Duyckaa801752010-11-16 19:27:02 -08001311 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001312
1313 /* if this is a skb from previous receive DMA will be 0 */
Alexander Duyck21fa4e62009-06-04 15:59:49 +00001314 if (rx_buffer_info->dma) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001315 u16 hlen;
Alexander Duyckaa801752010-11-16 19:27:02 -08001316 if (pkt_is_rsc &&
Alexander Duyckc267fc12010-11-16 19:27:00 -08001317 !(staterr & IXGBE_RXD_STAT_EOP) &&
1318 !skb->prev) {
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001319 /*
1320 * When HWRSC is enabled, delay unmapping
1321 * of the first packet. It carries the
1322 * header information, HW may still
1323 * access the header after the writeback.
1324 * Only unmap it when EOP is reached
1325 */
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001326 IXGBE_RSC_CB(skb)->delay_unmap = true;
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001327 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001328 } else {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001329 dma_unmap_single(rx_ring->dev,
Joe Perchese8e9f692010-09-07 21:34:53 +00001330 rx_buffer_info->dma,
1331 rx_ring->rx_buf_len,
1332 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001333 }
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00001334 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001335
1336 if (ring_is_ps_enabled(rx_ring)) {
1337 hlen = ixgbe_get_hlen(rx_desc);
1338 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1339 } else {
1340 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1341 }
1342
1343 skb_put(skb, hlen);
1344 } else {
1345 /* assume packet split since header is unmapped */
1346 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001347 }
1348
1349 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001350 dma_unmap_page(rx_ring->dev,
1351 rx_buffer_info->page_dma,
1352 PAGE_SIZE / 2,
1353 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001354 rx_buffer_info->page_dma = 0;
1355 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001356 rx_buffer_info->page,
1357 rx_buffer_info->page_offset,
1358 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001359
Alexander Duyckc267fc12010-11-16 19:27:00 -08001360 if ((page_count(rx_buffer_info->page) == 1) &&
1361 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001362 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001363 else
1364 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001365
1366 skb->len += upper_len;
1367 skb->data_len += upper_len;
1368 skb->truesize += upper_len;
1369 }
1370
1371 i++;
1372 if (i == rx_ring->count)
1373 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001374
Alexander Duyck31f05a22010-08-19 13:40:31 +00001375 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001376 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001377 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001378
Alexander Duyckaa801752010-11-16 19:27:02 -08001379 if (pkt_is_rsc) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001380 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1381 IXGBE_RXDADV_NEXTP_SHIFT;
1382 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +00001383 } else {
1384 next_buffer = &rx_ring->rx_buffer_info[i];
1385 }
1386
Alexander Duyckc267fc12010-11-16 19:27:00 -08001387 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001388 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001389 rx_buffer_info->skb = next_buffer->skb;
1390 rx_buffer_info->dma = next_buffer->dma;
1391 next_buffer->skb = skb;
1392 next_buffer->dma = 0;
1393 } else {
1394 skb->next = next_buffer->skb;
1395 skb->next->prev = skb;
1396 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001397 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001398 goto next_desc;
1399 }
1400
Alexander Duyckaa801752010-11-16 19:27:02 -08001401 if (skb->prev) {
1402 skb = ixgbe_transform_rsc_queue(skb);
1403 /* if we got here without RSC the packet is invalid */
1404 if (!pkt_is_rsc) {
1405 __pskb_trim(skb, 0);
1406 rx_buffer_info->skb = skb;
1407 goto next_desc;
1408 }
1409 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001410
1411 if (ring_is_rsc_enabled(rx_ring)) {
1412 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1413 dma_unmap_single(rx_ring->dev,
1414 IXGBE_RSC_CB(skb)->dma,
1415 rx_ring->rx_buf_len,
1416 DMA_FROM_DEVICE);
1417 IXGBE_RSC_CB(skb)->dma = 0;
1418 IXGBE_RSC_CB(skb)->delay_unmap = false;
1419 }
Alexander Duyckaa801752010-11-16 19:27:02 -08001420 }
1421 if (pkt_is_rsc) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001422 if (ring_is_ps_enabled(rx_ring))
1423 rx_ring->rx_stats.rsc_count +=
Alexander Duyckaa801752010-11-16 19:27:02 -08001424 skb_shinfo(skb)->nr_frags;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001425 else
Alexander Duyckaa801752010-11-16 19:27:02 -08001426 rx_ring->rx_stats.rsc_count +=
1427 IXGBE_RSC_CB(skb)->skb_cnt;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001428 rx_ring->rx_stats.rsc_flush++;
1429 }
1430
1431 /* ERR_MASK will only have valid bits if EOP set */
Auke Kok9a799d72007-09-15 14:07:45 -07001432 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001433 /* trim packet back to size 0 and recycle it */
1434 __pskb_trim(skb, 0);
1435 rx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001436 goto next_desc;
1437 }
1438
Don Skidmore8bae1b22009-07-23 18:00:39 +00001439 ixgbe_rx_checksum(adapter, rx_desc, skb);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001440 if (adapter->netdev->features & NETIF_F_RXHASH)
1441 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001442
1443 /* probably a little skewed due to removing CRC */
1444 total_rx_bytes += skb->len;
1445 total_rx_packets++;
1446
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001447 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001448#ifdef IXGBE_FCOE
1449 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +00001450 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1451 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
1452 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +00001453 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +00001454 }
Yi Zou332d4a72009-05-13 13:11:53 +00001455#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001456 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001457
1458next_desc:
1459 rx_desc->wb.upper.status_error = 0;
1460
Alexander Duyckc267fc12010-11-16 19:27:00 -08001461 (*work_done)++;
1462 if (*work_done >= work_to_do)
1463 break;
1464
Auke Kok9a799d72007-09-15 14:07:45 -07001465 /* return some buffers to hardware, one at a time is too slow */
1466 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001467 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001468 cleaned_count = 0;
1469 }
1470
1471 /* use prefetched values */
1472 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001473 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001474 }
1475
Auke Kok9a799d72007-09-15 14:07:45 -07001476 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001477 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001478
1479 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001480 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001481
Yi Zou3d8fd382009-06-08 14:38:44 +00001482#ifdef IXGBE_FCOE
1483 /* include DDPed FCoE data */
1484 if (ddp_bytes > 0) {
1485 unsigned int mss;
1486
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001487 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001488 sizeof(struct fc_frame_header) -
1489 sizeof(struct fcoe_crc_eof);
1490 if (mss > 512)
1491 mss &= ~511;
1492 total_rx_bytes += ddp_bytes;
1493 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1494 }
1495#endif /* IXGBE_FCOE */
1496
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001497 rx_ring->total_packets += total_rx_packets;
1498 rx_ring->total_bytes += total_rx_bytes;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001499 u64_stats_update_begin(&rx_ring->syncp);
1500 rx_ring->stats.packets += total_rx_packets;
1501 rx_ring->stats.bytes += total_rx_bytes;
1502 u64_stats_update_end(&rx_ring->syncp);
Auke Kok9a799d72007-09-15 14:07:45 -07001503}
1504
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001505static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001506/**
1507 * ixgbe_configure_msix - Configure MSI-X hardware
1508 * @adapter: board private structure
1509 *
1510 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1511 * interrupts.
1512 **/
1513static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1514{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001515 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001516 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001517 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001518
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001519 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1520
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001521 /*
1522 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001523 * corresponding register.
1524 */
1525 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001526 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001527 /* XXX for_each_set_bit(...) */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001528 r_idx = find_first_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001529 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001530
1531 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001532 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1533 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001534 r_idx = find_next_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001535 adapter->num_rx_queues,
1536 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001537 }
1538 r_idx = find_first_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001539 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001540
1541 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001542 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1543 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001544 r_idx = find_next_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001545 adapter->num_tx_queues,
1546 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001547 }
1548
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001549 if (q_vector->txr_count && !q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001550 /* tx only */
1551 q_vector->eitr = adapter->tx_eitr_param;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001552 else if (q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001553 /* rx or mixed */
1554 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001555
Alexander Duyckfe49f042009-06-04 16:00:09 +00001556 ixgbe_write_eitr(q_vector);
Alexander Duyck03ecf912011-05-20 07:36:17 +00001557 /* If ATR is enabled, set interrupt affinity */
1558 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001559 /*
1560 * Allocate the affinity_hint cpumask, assign the mask
1561 * for this vector, and set our affinity_hint for
1562 * this irq.
1563 */
1564 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1565 GFP_KERNEL))
1566 return;
1567 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1568 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1569 q_vector->affinity_mask);
1570 }
Auke Kok9a799d72007-09-15 14:07:45 -07001571 }
1572
Alexander Duyckbd508172010-11-16 19:27:03 -08001573 switch (adapter->hw.mac.type) {
1574 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001575 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001576 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001577 break;
1578 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001579 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001580 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001581 break;
1582
1583 default:
1584 break;
1585 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001586 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001587
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001588 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001589 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001590 if (adapter->num_vfs)
1591 mask &= ~(IXGBE_EIMS_OTHER |
1592 IXGBE_EIMS_MAILBOX |
1593 IXGBE_EIMS_LSC);
1594 else
1595 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001596 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001597}
1598
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001599enum latency_range {
1600 lowest_latency = 0,
1601 low_latency = 1,
1602 bulk_latency = 2,
1603 latency_invalid = 255
1604};
1605
1606/**
1607 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1608 * @adapter: pointer to adapter
1609 * @eitr: eitr setting (ints per sec) to give last timeslice
1610 * @itr_setting: current throttle rate in ints/second
1611 * @packets: the number of packets during this measurement interval
1612 * @bytes: the number of bytes during this measurement interval
1613 *
1614 * Stores a new ITR value based on packets and byte
1615 * counts during the last interrupt. The advantage of per interrupt
1616 * computation is faster updates and more accurate ITR for the current
1617 * traffic pattern. Constants in this function were computed
1618 * based on theoretical maximum wire speed and thresholds were set based
1619 * on testing data as well as attempting to minimize response time
1620 * while increasing bulk throughput.
1621 * this functionality is controlled by the InterruptThrottleRate module
1622 * parameter (see ixgbe_param.c)
1623 **/
1624static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001625 u32 eitr, u8 itr_setting,
1626 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001627{
1628 unsigned int retval = itr_setting;
1629 u32 timepassed_us;
1630 u64 bytes_perint;
1631
1632 if (packets == 0)
1633 goto update_itr_done;
1634
1635
1636 /* simple throttlerate management
1637 * 0-20MB/s lowest (100000 ints/s)
1638 * 20-100MB/s low (20000 ints/s)
1639 * 100-1249MB/s bulk (8000 ints/s)
1640 */
1641 /* what was last interrupt timeslice? */
1642 timepassed_us = 1000000/eitr;
1643 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1644
1645 switch (itr_setting) {
1646 case lowest_latency:
1647 if (bytes_perint > adapter->eitr_low)
1648 retval = low_latency;
1649 break;
1650 case low_latency:
1651 if (bytes_perint > adapter->eitr_high)
1652 retval = bulk_latency;
1653 else if (bytes_perint <= adapter->eitr_low)
1654 retval = lowest_latency;
1655 break;
1656 case bulk_latency:
1657 if (bytes_perint <= adapter->eitr_high)
1658 retval = low_latency;
1659 break;
1660 }
1661
1662update_itr_done:
1663 return retval;
1664}
1665
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001666/**
1667 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001668 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001669 *
1670 * This function is made to be called by ethtool and by the driver
1671 * when it needs to update EITR registers at runtime. Hardware
1672 * specific quirks/differences are taken care of here.
1673 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001674void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001675{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001676 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001677 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001678 int v_idx = q_vector->v_idx;
1679 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1680
Alexander Duyckbd508172010-11-16 19:27:03 -08001681 switch (adapter->hw.mac.type) {
1682 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001683 /* must write high and low 16 bits to reset counter */
1684 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001685 break;
1686 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001687 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001688 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001689 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001690 * max interrupt rate, but there is an errata where it can
1691 * not be zero with RSC
1692 */
1693 if (itr_reg == 8 &&
1694 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1695 itr_reg = 0;
1696
1697 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001698 * set the WDIS bit to not clear the timer bits and cause an
1699 * immediate assertion of the interrupt
1700 */
1701 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001702 break;
1703 default:
1704 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001705 }
1706 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1707}
1708
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001709static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1710{
1711 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck125601b2010-11-16 19:27:08 -08001712 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001713 u32 new_itr;
1714 u8 current_itr, ret_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001715
1716 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1717 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001718 struct ixgbe_ring *tx_ring = adapter->tx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001719 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001720 q_vector->tx_itr,
1721 tx_ring->total_packets,
1722 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001723 /* if the result for this queue would decrease interrupt
1724 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001725 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001726 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001727 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001728 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001729 }
1730
1731 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1732 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001733 struct ixgbe_ring *rx_ring = adapter->rx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001734 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001735 q_vector->rx_itr,
1736 rx_ring->total_packets,
1737 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001738 /* if the result for this queue would decrease interrupt
1739 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001740 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001741 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001742 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001743 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001744 }
1745
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001746 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001747
1748 switch (current_itr) {
1749 /* counts and packets in update_itr are dependent on these numbers */
1750 case lowest_latency:
1751 new_itr = 100000;
1752 break;
1753 case low_latency:
1754 new_itr = 20000; /* aka hwitr = ~200 */
1755 break;
1756 case bulk_latency:
1757 default:
1758 new_itr = 8000;
1759 break;
1760 }
1761
1762 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001763 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001764 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001765
1766 /* save the algorithm value here, not the smoothed one */
1767 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001768
1769 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001770 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001771}
1772
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001773/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001774 * ixgbe_check_overtemp_subtask - check for over tempurature
1775 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001776 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001777static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001778{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001779 struct ixgbe_hw *hw = &adapter->hw;
1780 u32 eicr = adapter->interrupt_event;
1781
Alexander Duyckf0f97782011-04-22 04:08:09 +00001782 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001783 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001784
Alexander Duyckf0f97782011-04-22 04:08:09 +00001785 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1786 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1787 return;
1788
1789 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1790
Joe Perches7ca647b2010-09-07 21:35:40 +00001791 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001792 case IXGBE_DEV_ID_82599_T3_LOM:
1793 /*
1794 * Since the warning interrupt is for both ports
1795 * we don't have to check if:
1796 * - This interrupt wasn't for our port.
1797 * - We may have missed the interrupt so always have to
1798 * check if we got a LSC
1799 */
1800 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1801 !(eicr & IXGBE_EICR_LSC))
1802 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001803
Alexander Duyckf0f97782011-04-22 04:08:09 +00001804 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1805 u32 autoneg;
1806 bool link_up = false;
1807
Joe Perches7ca647b2010-09-07 21:35:40 +00001808 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1809
Alexander Duyckf0f97782011-04-22 04:08:09 +00001810 if (link_up)
1811 return;
1812 }
1813
1814 /* Check if this is not due to overtemp */
1815 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1816 return;
1817
1818 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001819 default:
1820 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1821 return;
1822 break;
1823 }
1824 e_crit(drv,
1825 "Network adapter has been stopped because it has over heated. "
1826 "Restart the computer. If the problem persists, "
1827 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001828
1829 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001830}
1831
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001832static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1833{
1834 struct ixgbe_hw *hw = &adapter->hw;
1835
1836 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1837 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001838 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001839 /* write to clear the interrupt */
1840 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1841 }
1842}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001843
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001844static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1845{
1846 struct ixgbe_hw *hw = &adapter->hw;
1847
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001848 if (eicr & IXGBE_EICR_GPI_SDP2) {
1849 /* Clear the interrupt */
1850 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001851 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1852 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1853 ixgbe_service_event_schedule(adapter);
1854 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001855 }
1856
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001857 if (eicr & IXGBE_EICR_GPI_SDP1) {
1858 /* Clear the interrupt */
1859 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001860 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1861 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1862 ixgbe_service_event_schedule(adapter);
1863 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001864 }
1865}
1866
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001867static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1868{
1869 struct ixgbe_hw *hw = &adapter->hw;
1870
1871 adapter->lsc_int++;
1872 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1873 adapter->link_check_timeout = jiffies;
1874 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1875 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001876 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001877 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001878 }
1879}
1880
Auke Kok9a799d72007-09-15 14:07:45 -07001881static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1882{
Alexander Duycka65151ba22011-05-27 05:31:32 +00001883 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07001884 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001885 u32 eicr;
1886
1887 /*
1888 * Workaround for Silicon errata. Use clear-by-write instead
1889 * of clear-by-read. Reading with EICS will return the
1890 * interrupt causes without clearing, which later be done
1891 * with the write to EICR.
1892 */
1893 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1894 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001895
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001896 if (eicr & IXGBE_EICR_LSC)
1897 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001898
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001899 if (eicr & IXGBE_EICR_MAILBOX)
1900 ixgbe_msg_task(adapter);
1901
Alexander Duyckbd508172010-11-16 19:27:03 -08001902 switch (hw->mac.type) {
1903 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001904 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001905 /* Handle Flow Director Full threshold interrupt */
1906 if (eicr & IXGBE_EICR_FLOW_DIR) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001907 int reinit_count = 0;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001908 int i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001909 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001910 struct ixgbe_ring *ring = adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001911 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckd034acf2011-04-27 09:25:34 +00001912 &ring->state))
1913 reinit_count++;
1914 }
1915 if (reinit_count) {
1916 /* no more flow director interrupts until after init */
1917 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1918 eicr &= ~IXGBE_EICR_FLOW_DIR;
1919 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1920 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001921 }
1922 }
Alexander Duyckf0f97782011-04-22 04:08:09 +00001923 ixgbe_check_sfp_event(adapter, eicr);
1924 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1925 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1926 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1927 adapter->interrupt_event = eicr;
1928 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1929 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001930 }
1931 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001932 break;
1933 default:
1934 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001935 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001936
1937 ixgbe_check_fan_failure(adapter, eicr);
1938
Alexander Duyck70864002011-04-27 09:13:56 +00001939 /* re-enable the original interrupt state, no lsc, no queues */
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001940 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck70864002011-04-27 09:13:56 +00001941 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
1942 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
Auke Kok9a799d72007-09-15 14:07:45 -07001943
1944 return IRQ_HANDLED;
1945}
1946
Alexander Duyckfe49f042009-06-04 16:00:09 +00001947static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1948 u64 qmask)
1949{
1950 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001951 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001952
Alexander Duyckbd508172010-11-16 19:27:03 -08001953 switch (hw->mac.type) {
1954 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001955 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001956 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1957 break;
1958 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001959 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001960 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001961 if (mask)
1962 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001963 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001964 if (mask)
1965 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1966 break;
1967 default:
1968 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001969 }
1970 /* skip the flush */
1971}
1972
1973static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001974 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00001975{
1976 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001977 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001978
Alexander Duyckbd508172010-11-16 19:27:03 -08001979 switch (hw->mac.type) {
1980 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001981 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001982 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1983 break;
1984 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001985 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001986 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001987 if (mask)
1988 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001989 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001990 if (mask)
1991 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1992 break;
1993 default:
1994 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001995 }
1996 /* skip the flush */
1997}
1998
Auke Kok9a799d72007-09-15 14:07:45 -07001999static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
2000{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002001 struct ixgbe_q_vector *q_vector = data;
2002 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002003 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002004 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002005
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002006 if (!q_vector->txr_count)
2007 return IRQ_HANDLED;
2008
2009 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2010 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002011 tx_ring = adapter->tx_ring[r_idx];
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002012 tx_ring->total_bytes = 0;
2013 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002014 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002015 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002016 }
2017
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002018 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002019 napi_schedule(&q_vector->napi);
2020
Auke Kok9a799d72007-09-15 14:07:45 -07002021 return IRQ_HANDLED;
2022}
2023
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002024/**
2025 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2026 * @irq: unused
2027 * @data: pointer to our q_vector struct for this interrupt vector
2028 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002029static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2030{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002031 struct ixgbe_q_vector *q_vector = data;
2032 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002033 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002034 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002035 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002036
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002037#ifdef CONFIG_IXGBE_DCA
2038 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2039 ixgbe_update_dca(q_vector);
2040#endif
2041
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002042 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002043 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002044 rx_ring = adapter->rx_ring[r_idx];
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002045 rx_ring->total_bytes = 0;
2046 rx_ring->total_packets = 0;
2047 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002048 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002049 }
2050
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002051 if (!q_vector->rxr_count)
2052 return IRQ_HANDLED;
2053
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002054 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002055 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002056
Auke Kok9a799d72007-09-15 14:07:45 -07002057 return IRQ_HANDLED;
2058}
2059
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002060static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2061{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002062 struct ixgbe_q_vector *q_vector = data;
2063 struct ixgbe_adapter *adapter = q_vector->adapter;
2064 struct ixgbe_ring *ring;
2065 int r_idx;
2066 int i;
2067
2068 if (!q_vector->txr_count && !q_vector->rxr_count)
2069 return IRQ_HANDLED;
2070
2071 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2072 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002073 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002074 ring->total_bytes = 0;
2075 ring->total_packets = 0;
2076 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002077 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002078 }
2079
2080 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2081 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002082 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002083 ring->total_bytes = 0;
2084 ring->total_packets = 0;
2085 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002086 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002087 }
2088
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002089 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002090 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002091
2092 return IRQ_HANDLED;
2093}
2094
2095/**
2096 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2097 * @napi: napi struct with our devices info in it
2098 * @budget: amount of work driver is allowed to do this pass, in packets
2099 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002100 * This function is optimized for cleaning one queue only on a single
2101 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002102 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002103static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2104{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002105 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002106 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002107 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002108 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002109 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002110 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002111
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002112#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002113 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002114 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002115#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002116
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002117 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2118 rx_ring = adapter->rx_ring[r_idx];
2119
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002120 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002121
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002122 /* If all Rx work done, exit the polling mode */
2123 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002124 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002125 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002126 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002127 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002128 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002129 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07002130 }
2131
2132 return work_done;
2133}
2134
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002135/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002136 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002137 * @napi: napi struct with our devices info in it
2138 * @budget: amount of work driver is allowed to do this pass, in packets
2139 *
2140 * This function will clean more than one rx queue associated with a
2141 * q_vector.
2142 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002143static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002144{
2145 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002146 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002147 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002148 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002149 int work_done = 0, i;
2150 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002151 bool tx_clean_complete = true;
2152
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002153#ifdef CONFIG_IXGBE_DCA
2154 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2155 ixgbe_update_dca(q_vector);
2156#endif
2157
Alexander Duyck91281fd2009-06-04 16:00:27 +00002158 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2159 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002160 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002161 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
2162 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002163 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002164 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002165
2166 /* attempt to distribute budget to each queue fairly, but don't allow
2167 * the budget to go below 1 because we'll exit polling */
2168 budget /= (q_vector->rxr_count ?: 1);
2169 budget = max(budget, 1);
2170 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2171 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002172 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002173 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002174 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002175 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002176 }
2177
2178 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002179 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002180 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002181 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002182 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002183 if (adapter->rx_itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002184 ixgbe_set_itr_msix(q_vector);
2185 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002186 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002187 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002188 return 0;
2189 }
2190
2191 return work_done;
2192}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002193
2194/**
2195 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2196 * @napi: napi struct with our devices info in it
2197 * @budget: amount of work driver is allowed to do this pass, in packets
2198 *
2199 * This function is optimized for cleaning one queue only on a single
2200 * q_vector!!!
2201 **/
2202static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2203{
2204 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002205 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002206 struct ixgbe_adapter *adapter = q_vector->adapter;
2207 struct ixgbe_ring *tx_ring = NULL;
2208 int work_done = 0;
2209 long r_idx;
2210
Alexander Duyck91281fd2009-06-04 16:00:27 +00002211#ifdef CONFIG_IXGBE_DCA
2212 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002213 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002214#endif
2215
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002216 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2217 tx_ring = adapter->tx_ring[r_idx];
2218
Alexander Duyck91281fd2009-06-04 16:00:27 +00002219 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2220 work_done = budget;
2221
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002222 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002223 if (work_done < budget) {
2224 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002225 if (adapter->tx_itr_setting & 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002226 ixgbe_set_itr_msix(q_vector);
2227 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002228 ixgbe_irq_enable_queues(adapter,
2229 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002230 }
2231
2232 return work_done;
2233}
2234
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002235static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002236 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002237{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002238 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002239 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002240
2241 set_bit(r_idx, q_vector->rxr_idx);
2242 q_vector->rxr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002243 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002244}
Auke Kok9a799d72007-09-15 14:07:45 -07002245
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002246static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002247 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002248{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002249 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002250 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002251
2252 set_bit(t_idx, q_vector->txr_idx);
2253 q_vector->txr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002254 tx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002255}
Auke Kok9a799d72007-09-15 14:07:45 -07002256
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002257/**
2258 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2259 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002260 *
2261 * This function maps descriptor rings to the queue-specific vectors
2262 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2263 * one vector per ring/queue, but on a constrained vector budget, we
2264 * group the rings as "efficiently" as possible. You would add new
2265 * mapping configurations in here.
2266 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002267static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002268{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002269 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002270 int v_start = 0;
2271 int rxr_idx = 0, txr_idx = 0;
2272 int rxr_remaining = adapter->num_rx_queues;
2273 int txr_remaining = adapter->num_tx_queues;
2274 int i, j;
2275 int rqpv, tqpv;
2276 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002277
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002278 /* No mapping required if MSI-X is disabled. */
2279 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002280 goto out;
2281
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002282 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2283
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002284 /*
2285 * The ideal configuration...
2286 * We have enough vectors to map one per queue.
2287 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002288 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002289 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2290 map_vector_to_rxq(adapter, v_start, rxr_idx);
2291
2292 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2293 map_vector_to_txq(adapter, v_start, txr_idx);
2294
2295 goto out;
2296 }
2297
2298 /*
2299 * If we don't have enough vectors for a 1-to-1
2300 * mapping, we'll have to group them so there are
2301 * multiple queues per vector.
2302 */
2303 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002304 for (i = v_start; i < q_vectors; i++) {
2305 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002306 for (j = 0; j < rqpv; j++) {
2307 map_vector_to_rxq(adapter, i, rxr_idx);
2308 rxr_idx++;
2309 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002310 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002311 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002312 for (j = 0; j < tqpv; j++) {
2313 map_vector_to_txq(adapter, i, txr_idx);
2314 txr_idx++;
2315 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002316 }
Auke Kok9a799d72007-09-15 14:07:45 -07002317 }
Auke Kok9a799d72007-09-15 14:07:45 -07002318out:
Auke Kok9a799d72007-09-15 14:07:45 -07002319 return err;
2320}
2321
2322/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002323 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2324 * @adapter: board private structure
2325 *
2326 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2327 * interrupts from the kernel.
2328 **/
2329static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2330{
2331 struct net_device *netdev = adapter->netdev;
2332 irqreturn_t (*handler)(int, void *);
2333 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002334 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002335
2336 /* Decrement for Other and TCP Timer vectors */
2337 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2338
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002339 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002340 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002341 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002342
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002343#define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
2344 ? &ixgbe_msix_clean_many : \
2345 (_v)->rxr_count ? &ixgbe_msix_clean_rx : \
2346 (_v)->txr_count ? &ixgbe_msix_clean_tx : \
2347 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002348 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002349 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2350 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002351
Joe Perchese8e9f692010-09-07 21:34:53 +00002352 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002353 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2354 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002355 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002356 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2357 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002358 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002359 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2360 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002361 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002362 } else {
2363 /* skip this unused q_vector */
2364 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002365 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002366 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002367 handler, 0, q_vector->name,
2368 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002369 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002370 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002371 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002372 goto free_queue_irqs;
2373 }
2374 }
2375
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002376 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002377 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002378 ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002379 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002380 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002381 goto free_queue_irqs;
2382 }
2383
2384 return 0;
2385
2386free_queue_irqs:
2387 for (i = vector - 1; i >= 0; i--)
2388 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002389 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002390 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2391 pci_disable_msix(adapter->pdev);
2392 kfree(adapter->msix_entries);
2393 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002394 return err;
2395}
2396
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002397static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
2398{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002399 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002400 struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
2401 struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
Alexander Duyck125601b2010-11-16 19:27:08 -08002402 u32 new_itr = q_vector->eitr;
2403 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002404
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002405 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002406 q_vector->tx_itr,
2407 tx_ring->total_packets,
2408 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002409 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002410 q_vector->rx_itr,
2411 rx_ring->total_packets,
2412 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002413
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002414 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002415
2416 switch (current_itr) {
2417 /* counts and packets in update_itr are dependent on these numbers */
2418 case lowest_latency:
2419 new_itr = 100000;
2420 break;
2421 case low_latency:
2422 new_itr = 20000; /* aka hwitr = ~200 */
2423 break;
2424 case bulk_latency:
2425 new_itr = 8000;
2426 break;
2427 default:
2428 break;
2429 }
2430
2431 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002432 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08002433 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002434
Alexander Duyck125601b2010-11-16 19:27:08 -08002435 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002436 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002437
2438 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002439 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002440}
2441
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002442/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002443 * ixgbe_irq_enable - Enable default interrupt generation settings
2444 * @adapter: board private structure
2445 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002446static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2447 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002448{
2449 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002450
2451 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002452 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2453 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002454 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2455 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002456 switch (adapter->hw.mac.type) {
2457 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002458 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002459 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002460 mask |= IXGBE_EIMS_GPI_SDP1;
2461 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002462 if (adapter->num_vfs)
2463 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002464 break;
2465 default:
2466 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002467 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00002468 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002469 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002470
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002471 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002472 if (queues)
2473 ixgbe_irq_enable_queues(adapter, ~0);
2474 if (flush)
2475 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002476
2477 if (adapter->num_vfs > 32) {
2478 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2479 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2480 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002481}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002482
2483/**
2484 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002485 * @irq: interrupt number
2486 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002487 **/
2488static irqreturn_t ixgbe_intr(int irq, void *data)
2489{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002490 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002491 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002492 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002493 u32 eicr;
2494
Don Skidmore54037502009-02-21 15:42:56 -08002495 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002496 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002497 * before the read of EICR.
2498 */
2499 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2500
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002501 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2502 * therefore no explict interrupt disable is necessary */
2503 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002504 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002505 /*
2506 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002507 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002508 * have disabled interrupts due to EIAM
2509 * finish the workaround of silicon errata on 82598. Unmask
2510 * the interrupt that we masked before the EICR read.
2511 */
2512 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2513 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002514 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002515 }
Auke Kok9a799d72007-09-15 14:07:45 -07002516
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002517 if (eicr & IXGBE_EICR_LSC)
2518 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002519
Alexander Duyckbd508172010-11-16 19:27:03 -08002520 switch (hw->mac.type) {
2521 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002522 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002523 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2524 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002525 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2526 adapter->interrupt_event = eicr;
2527 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2528 ixgbe_service_event_schedule(adapter);
2529 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002530 }
2531 break;
2532 default:
2533 break;
2534 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002535
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002536 ixgbe_check_fan_failure(adapter, eicr);
2537
Alexander Duyck7a921c92009-05-06 10:43:28 +00002538 if (napi_schedule_prep(&(q_vector->napi))) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002539 adapter->tx_ring[0]->total_packets = 0;
2540 adapter->tx_ring[0]->total_bytes = 0;
2541 adapter->rx_ring[0]->total_packets = 0;
2542 adapter->rx_ring[0]->total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002543 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002544 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002545 }
2546
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002547 /*
2548 * re-enable link(maybe) and non-queue interrupts, no flush.
2549 * ixgbe_poll will re-enable the queue interrupts
2550 */
2551
2552 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2553 ixgbe_irq_enable(adapter, false, false);
2554
Auke Kok9a799d72007-09-15 14:07:45 -07002555 return IRQ_HANDLED;
2556}
2557
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002558static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2559{
2560 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2561
2562 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002563 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002564 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
2565 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
2566 q_vector->rxr_count = 0;
2567 q_vector->txr_count = 0;
2568 }
2569}
2570
Auke Kok9a799d72007-09-15 14:07:45 -07002571/**
2572 * ixgbe_request_irq - initialize interrupts
2573 * @adapter: board private structure
2574 *
2575 * Attempts to configure interrupts using the best available
2576 * capabilities of the hardware and kernel.
2577 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002578static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002579{
2580 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002581 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002582
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002583 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2584 err = ixgbe_request_msix_irqs(adapter);
2585 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002586 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002587 netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002588 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002589 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002590 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002591 }
2592
Auke Kok9a799d72007-09-15 14:07:45 -07002593 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002594 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002595
Auke Kok9a799d72007-09-15 14:07:45 -07002596 return err;
2597}
2598
2599static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2600{
Auke Kok9a799d72007-09-15 14:07:45 -07002601 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002602 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002603
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002604 q_vectors = adapter->num_msix_vectors;
2605
2606 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002607 free_irq(adapter->msix_entries[i].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002608
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002609 i--;
2610 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002611 /* free only the irqs that were actually requested */
2612 if (!adapter->q_vector[i]->rxr_count &&
2613 !adapter->q_vector[i]->txr_count)
2614 continue;
2615
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002616 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002617 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002618 }
2619
2620 ixgbe_reset_q_vectors(adapter);
2621 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002622 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002623 }
2624}
2625
2626/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002627 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2628 * @adapter: board private structure
2629 **/
2630static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2631{
Alexander Duyckbd508172010-11-16 19:27:03 -08002632 switch (adapter->hw.mac.type) {
2633 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002634 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002635 break;
2636 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002637 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002638 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2639 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002640 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002641 if (adapter->num_vfs > 32)
2642 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002643 break;
2644 default:
2645 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002646 }
2647 IXGBE_WRITE_FLUSH(&adapter->hw);
2648 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2649 int i;
2650 for (i = 0; i < adapter->num_msix_vectors; i++)
2651 synchronize_irq(adapter->msix_entries[i].vector);
2652 } else {
2653 synchronize_irq(adapter->pdev->irq);
2654 }
2655}
2656
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002657/**
Auke Kok9a799d72007-09-15 14:07:45 -07002658 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2659 *
2660 **/
2661static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2662{
Auke Kok9a799d72007-09-15 14:07:45 -07002663 struct ixgbe_hw *hw = &adapter->hw;
2664
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002665 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002666 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002667
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002668 ixgbe_set_ivar(adapter, 0, 0, 0);
2669 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002670
2671 map_vector_to_rxq(adapter, 0, 0);
2672 map_vector_to_txq(adapter, 0, 0);
2673
Emil Tantilov396e7992010-07-01 20:05:12 +00002674 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002675}
2676
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002677/**
2678 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2679 * @adapter: board private structure
2680 * @ring: structure containing ring specific data
2681 *
2682 * Configure the Tx descriptor ring after a reset.
2683 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002684void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2685 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002686{
2687 struct ixgbe_hw *hw = &adapter->hw;
2688 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002689 int wait_loop = 10;
2690 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002691 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002692
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002693 /* disable queue to avoid issues while updating state */
2694 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2695 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2696 txdctl & ~IXGBE_TXDCTL_ENABLE);
2697 IXGBE_WRITE_FLUSH(hw);
2698
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002699 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002700 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002701 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2702 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2703 ring->count * sizeof(union ixgbe_adv_tx_desc));
2704 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2705 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002706 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002707
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002708 /* configure fetching thresholds */
2709 if (adapter->rx_itr_setting == 0) {
2710 /* cannot set wthresh when itr==0 */
2711 txdctl &= ~0x007F0000;
2712 } else {
2713 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2714 txdctl |= (8 << 16);
2715 }
2716 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2717 /* PThresh workaround for Tx hang with DFP enabled. */
2718 txdctl |= 32;
2719 }
2720
2721 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002722 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2723 adapter->atr_sample_rate) {
2724 ring->atr_sample_rate = adapter->atr_sample_rate;
2725 ring->atr_count = 0;
2726 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2727 } else {
2728 ring->atr_sample_rate = 0;
2729 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002730
John Fastabendc84d3242010-11-16 19:27:12 -08002731 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2732
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002733 /* enable queue */
2734 txdctl |= IXGBE_TXDCTL_ENABLE;
2735 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2736
2737 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2738 if (hw->mac.type == ixgbe_mac_82598EB &&
2739 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2740 return;
2741
2742 /* poll to verify queue is enabled */
2743 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002744 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002745 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2746 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2747 if (!wait_loop)
2748 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002749}
2750
Alexander Duyck120ff942010-08-19 13:34:50 +00002751static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2752{
2753 struct ixgbe_hw *hw = &adapter->hw;
2754 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002755 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002756 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002757
2758 if (hw->mac.type == ixgbe_mac_82598EB)
2759 return;
2760
2761 /* disable the arbiter while setting MTQC */
2762 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2763 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2764 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2765
2766 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002767 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002768 case (IXGBE_FLAG_SRIOV_ENABLED):
2769 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2770 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2771 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002772 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002773 if (!tcs)
2774 reg = IXGBE_MTQC_64Q_1PB;
2775 else if (tcs <= 4)
2776 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2777 else
2778 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2779
2780 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2781
2782 /* Enable Security TX Buffer IFG for multiple pb */
2783 if (tcs) {
2784 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2785 reg |= IXGBE_SECTX_DCB;
2786 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2787 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002788 break;
2789 }
2790
2791 /* re-enable the arbiter */
2792 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2793 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2794}
2795
Auke Kok9a799d72007-09-15 14:07:45 -07002796/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002797 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002798 * @adapter: board private structure
2799 *
2800 * Configure the Tx unit of the MAC after a reset.
2801 **/
2802static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2803{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002804 struct ixgbe_hw *hw = &adapter->hw;
2805 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002806 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002807
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002808 ixgbe_setup_mtqc(adapter);
2809
2810 if (hw->mac.type != ixgbe_mac_82598EB) {
2811 /* DMATXCTL.EN must be before Tx queues are enabled */
2812 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2813 dmatxctl |= IXGBE_DMATXCTL_TE;
2814 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2815 }
2816
Auke Kok9a799d72007-09-15 14:07:45 -07002817 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002818 for (i = 0; i < adapter->num_tx_queues; i++)
2819 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002820}
2821
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002822#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002823
Yi Zoua6616b42009-08-06 13:05:23 +00002824static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002825 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002826{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002827 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002828 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002829
Alexander Duyckbd508172010-11-16 19:27:03 -08002830 switch (adapter->hw.mac.type) {
2831 case ixgbe_mac_82598EB: {
2832 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2833 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002834 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002835 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002836 break;
2837 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002838 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002839 default:
2840 break;
2841 }
2842
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002843 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002844
2845 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2846 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002847 if (adapter->num_vfs)
2848 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002849
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002850 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2851 IXGBE_SRRCTL_BSIZEHDR_MASK;
2852
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002853 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002854#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2855 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2856#else
2857 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2858#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002859 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002860 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002861 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2862 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002863 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002864 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002865
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002866 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002867}
2868
Alexander Duyck05abb122010-08-19 13:35:41 +00002869static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002870{
Alexander Duyck05abb122010-08-19 13:35:41 +00002871 struct ixgbe_hw *hw = &adapter->hw;
2872 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002873 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2874 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002875 u32 mrqc = 0, reta = 0;
2876 u32 rxcsum;
2877 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002878 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002879 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2880
2881 if (tcs)
2882 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002883
Alexander Duyck05abb122010-08-19 13:35:41 +00002884 /* Fill out hash function seeds */
2885 for (i = 0; i < 10; i++)
2886 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002887
Alexander Duyck05abb122010-08-19 13:35:41 +00002888 /* Fill out redirection table */
2889 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002890 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002891 j = 0;
2892 /* reta = 4-byte sliding window of
2893 * 0x00..(indices-1)(indices-1)00..etc. */
2894 reta = (reta << 8) | (j * 0x11);
2895 if ((i & 3) == 3)
2896 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2897 }
2898
2899 /* Disable indicating checksum in descriptor, enables RSS hash */
2900 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2901 rxcsum |= IXGBE_RXCSUM_PCSD;
2902 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2903
John Fastabend8b1c0b22011-05-03 02:26:48 +00002904 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2905 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002906 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002907 } else {
2908 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2909 | IXGBE_FLAG_SRIOV_ENABLED);
2910
2911 switch (mask) {
2912 case (IXGBE_FLAG_RSS_ENABLED):
2913 if (!tcs)
2914 mrqc = IXGBE_MRQC_RSSEN;
2915 else if (tcs <= 4)
2916 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2917 else
2918 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2919 break;
2920 case (IXGBE_FLAG_SRIOV_ENABLED):
2921 mrqc = IXGBE_MRQC_VMDQEN;
2922 break;
2923 default:
2924 break;
2925 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002926 }
2927
Alexander Duyck05abb122010-08-19 13:35:41 +00002928 /* Perform hash on these packet types */
2929 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2930 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2931 | IXGBE_MRQC_RSS_FIELD_IPV6
2932 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2933
2934 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002935}
2936
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002937/**
Don Skidmoreb93a2222010-11-16 19:27:17 -08002938 * ixgbe_clear_rscctl - disable RSC for the indicated ring
2939 * @adapter: address of board private structure
2940 * @ring: structure containing ring specific data
2941 **/
2942void ixgbe_clear_rscctl(struct ixgbe_adapter *adapter,
2943 struct ixgbe_ring *ring)
2944{
2945 struct ixgbe_hw *hw = &adapter->hw;
2946 u32 rscctrl;
2947 u8 reg_idx = ring->reg_idx;
2948
2949 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
2950 rscctrl &= ~IXGBE_RSCCTL_RSCEN;
2951 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
2952}
2953
2954/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002955 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2956 * @adapter: address of board private structure
2957 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002958 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -08002959void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002960 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002961{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002962 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002963 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002964 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002965 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002966
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002967 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002968 return;
2969
2970 rx_buf_len = ring->rx_buf_len;
2971 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002972 rscctrl |= IXGBE_RSCCTL_RSCEN;
2973 /*
2974 * we must limit the number of descriptors so that the
2975 * total size of max desc * buf_len is not greater
2976 * than 65535
2977 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002978 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002979#if (MAX_SKB_FRAGS > 16)
2980 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2981#elif (MAX_SKB_FRAGS > 8)
2982 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2983#elif (MAX_SKB_FRAGS > 4)
2984 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2985#else
2986 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2987#endif
2988 } else {
2989 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2990 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2991 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2992 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2993 else
2994 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2995 }
Alexander Duyck73670962010-08-19 13:38:34 +00002996 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002997}
2998
Alexander Duyck9e10e042010-08-19 13:40:06 +00002999/**
3000 * ixgbe_set_uta - Set unicast filter table address
3001 * @adapter: board private structure
3002 *
3003 * The unicast table address is a register array of 32-bit registers.
3004 * The table is meant to be used in a way similar to how the MTA is used
3005 * however due to certain limitations in the hardware it is necessary to
3006 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
3007 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
3008 **/
3009static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
3010{
3011 struct ixgbe_hw *hw = &adapter->hw;
3012 int i;
3013
3014 /* The UTA table only exists on 82599 hardware and newer */
3015 if (hw->mac.type < ixgbe_mac_82599EB)
3016 return;
3017
3018 /* we only need to do this if VMDq is enabled */
3019 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3020 return;
3021
3022 for (i = 0; i < 128; i++)
3023 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
3024}
3025
3026#define IXGBE_MAX_RX_DESC_POLL 10
3027static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3028 struct ixgbe_ring *ring)
3029{
3030 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003031 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3032 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003033 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003034
3035 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3036 if (hw->mac.type == ixgbe_mac_82598EB &&
3037 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3038 return;
3039
3040 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003041 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003042 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3043 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3044
3045 if (!wait_loop) {
3046 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3047 "the polling period\n", reg_idx);
3048 }
3049}
3050
Yi Zou2d39d572011-01-06 14:29:56 +00003051void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3052 struct ixgbe_ring *ring)
3053{
3054 struct ixgbe_hw *hw = &adapter->hw;
3055 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3056 u32 rxdctl;
3057 u8 reg_idx = ring->reg_idx;
3058
3059 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3060 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3061
3062 /* write value back with RXDCTL.ENABLE bit cleared */
3063 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3064
3065 if (hw->mac.type == ixgbe_mac_82598EB &&
3066 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3067 return;
3068
3069 /* the hardware may take up to 100us to really disable the rx queue */
3070 do {
3071 udelay(10);
3072 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3073 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3074
3075 if (!wait_loop) {
3076 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3077 "the polling period\n", reg_idx);
3078 }
3079}
3080
Alexander Duyck84418e32010-08-19 13:40:54 +00003081void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3082 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003083{
3084 struct ixgbe_hw *hw = &adapter->hw;
3085 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003086 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003087 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003088
Alexander Duyck9e10e042010-08-19 13:40:06 +00003089 /* disable queue to avoid issues while updating state */
3090 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003091 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003092
Alexander Duyckacd37172010-08-19 13:36:05 +00003093 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3094 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3095 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3096 ring->count * sizeof(union ixgbe_adv_rx_desc));
3097 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3098 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003099 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003100
3101 ixgbe_configure_srrctl(adapter, ring);
3102 ixgbe_configure_rscctl(adapter, ring);
3103
Greg Rosee9f98072011-01-26 01:06:07 +00003104 /* If operating in IOV mode set RLPML for X540 */
3105 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3106 hw->mac.type == ixgbe_mac_X540) {
3107 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3108 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3109 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3110 }
3111
Alexander Duyck9e10e042010-08-19 13:40:06 +00003112 if (hw->mac.type == ixgbe_mac_82598EB) {
3113 /*
3114 * enable cache line friendly hardware writes:
3115 * PTHRESH=32 descriptors (half the internal cache),
3116 * this also removes ugly rx_no_buffer_count increment
3117 * HTHRESH=4 descriptors (to minimize latency on fetch)
3118 * WTHRESH=8 burst writeback up to two cache lines
3119 */
3120 rxdctl &= ~0x3FFFFF;
3121 rxdctl |= 0x080420;
3122 }
3123
3124 /* enable receive descriptor ring */
3125 rxdctl |= IXGBE_RXDCTL_ENABLE;
3126 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3127
3128 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003129 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003130}
3131
Alexander Duyck48654522010-08-19 13:36:27 +00003132static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3133{
3134 struct ixgbe_hw *hw = &adapter->hw;
3135 int p;
3136
3137 /* PSRTYPE must be initialized in non 82598 adapters */
3138 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003139 IXGBE_PSRTYPE_UDPHDR |
3140 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003141 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003142 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003143
3144 if (hw->mac.type == ixgbe_mac_82598EB)
3145 return;
3146
3147 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3148 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3149
3150 for (p = 0; p < adapter->num_rx_pools; p++)
3151 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3152 psrtype);
3153}
3154
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003155static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3156{
3157 struct ixgbe_hw *hw = &adapter->hw;
3158 u32 gcr_ext;
3159 u32 vt_reg_bits;
3160 u32 reg_offset, vf_shift;
3161 u32 vmdctl;
3162
3163 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3164 return;
3165
3166 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3167 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3168 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3169 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3170
3171 vf_shift = adapter->num_vfs % 32;
3172 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3173
3174 /* Enable only the PF's pool for Tx/Rx */
3175 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3176 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3177 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3178 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3179 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3180
3181 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3182 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3183
3184 /*
3185 * Set up VF register offsets for selected VT Mode,
3186 * i.e. 32 or 64 VFs for SR-IOV
3187 */
3188 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3189 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3190 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3191 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3192
3193 /* enable Tx loopback for VF/PF communication */
3194 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003195 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003196 hw->mac.ops.set_mac_anti_spoofing(hw,
3197 (adapter->antispoofing_enabled =
3198 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003199 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003200}
3201
Alexander Duyck477de6e2010-08-19 13:38:11 +00003202static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003203{
Auke Kok9a799d72007-09-15 14:07:45 -07003204 struct ixgbe_hw *hw = &adapter->hw;
3205 struct net_device *netdev = adapter->netdev;
3206 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003207 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003208 struct ixgbe_ring *rx_ring;
3209 int i;
3210 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003211
Auke Kok9a799d72007-09-15 14:07:45 -07003212 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003213 /* On by default */
3214 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3215
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003216 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003217 if (adapter->num_vfs)
3218 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3219
3220 /* Disable packet split due to 82599 erratum #45 */
3221 if (hw->mac.type == ixgbe_mac_82599EB)
3222 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003223
3224 /* Set the RX buffer length according to the mode */
3225 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003226 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003227 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003228 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003229 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003230 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003231 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003232 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3233 }
3234
3235#ifdef IXGBE_FCOE
3236 /* adjust max frame to be able to do baby jumbo for FCoE */
3237 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3238 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3239 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3240
3241#endif /* IXGBE_FCOE */
3242 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3243 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3244 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3245 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3246
3247 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003248 }
3249
Auke Kok9a799d72007-09-15 14:07:45 -07003250 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003251 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3252 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003253 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3254
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003255 /*
3256 * Setup the HW Rx Head and Tail Descriptor Pointers and
3257 * the Base and Length of the Rx Descriptor Ring
3258 */
Auke Kok9a799d72007-09-15 14:07:45 -07003259 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003260 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003261 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003262
Yi Zou6e455b892009-08-06 13:05:44 +00003263 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003264 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003265 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003266 clear_ring_ps_enabled(rx_ring);
3267
3268 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3269 set_ring_rsc_enabled(rx_ring);
3270 else
3271 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003272
Yi Zou63f39bd2009-05-17 12:34:35 +00003273#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003274 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003275 struct ixgbe_ring_feature *f;
3276 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003277 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003278 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003279 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3280 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003281 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003282 } else if (!ring_is_rsc_enabled(rx_ring) &&
3283 !ring_is_ps_enabled(rx_ring)) {
3284 rx_ring->rx_buf_len =
3285 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003286 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003287 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003288#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003289 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003290}
3291
Alexander Duyck73670962010-08-19 13:38:34 +00003292static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3293{
3294 struct ixgbe_hw *hw = &adapter->hw;
3295 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3296
3297 switch (hw->mac.type) {
3298 case ixgbe_mac_82598EB:
3299 /*
3300 * For VMDq support of different descriptor types or
3301 * buffer sizes through the use of multiple SRRCTL
3302 * registers, RDRXCTL.MVMEN must be set to 1
3303 *
3304 * also, the manual doesn't mention it clearly but DCA hints
3305 * will only use queue 0's tags unless this bit is set. Side
3306 * effects of setting this bit are only that SRRCTL must be
3307 * fully programmed [0..15]
3308 */
3309 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3310 break;
3311 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003312 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003313 /* Disable RSC for ACK packets */
3314 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3315 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3316 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3317 /* hardware requires some bits to be set by default */
3318 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3319 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3320 break;
3321 default:
3322 /* We should do nothing since we don't know this hardware */
3323 return;
3324 }
3325
3326 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3327}
3328
Alexander Duyck477de6e2010-08-19 13:38:11 +00003329/**
3330 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3331 * @adapter: board private structure
3332 *
3333 * Configure the Rx unit of the MAC after a reset.
3334 **/
3335static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3336{
3337 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003338 int i;
3339 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003340
3341 /* disable receives while setting up the descriptors */
3342 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3343 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3344
3345 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003346 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003347
Alexander Duyck9e10e042010-08-19 13:40:06 +00003348 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003349 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003350
Alexander Duyck9e10e042010-08-19 13:40:06 +00003351 ixgbe_set_uta(adapter);
3352
Alexander Duyck477de6e2010-08-19 13:38:11 +00003353 /* set_rx_buffer_len must be called before ring initialization */
3354 ixgbe_set_rx_buffer_len(adapter);
3355
3356 /*
3357 * Setup the HW Rx Head and Tail Descriptor Pointers and
3358 * the Base and Length of the Rx Descriptor Ring
3359 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003360 for (i = 0; i < adapter->num_rx_queues; i++)
3361 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003362
Alexander Duyck9e10e042010-08-19 13:40:06 +00003363 /* disable drop enable for 82598 parts */
3364 if (hw->mac.type == ixgbe_mac_82598EB)
3365 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3366
3367 /* enable all receives */
3368 rxctrl |= IXGBE_RXCTRL_RXEN;
3369 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003370}
3371
Auke Kok9a799d72007-09-15 14:07:45 -07003372static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3373{
3374 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003375 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003376 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003377
3378 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003379 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003380 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003381}
3382
3383static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3384{
3385 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003386 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003387 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003388
Auke Kok9a799d72007-09-15 14:07:45 -07003389 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003390 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003391 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003392}
3393
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003394/**
3395 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3396 * @adapter: driver data
3397 */
3398static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3399{
3400 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003401 u32 vlnctrl;
3402
3403 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3404 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3405 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3406}
3407
3408/**
3409 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3410 * @adapter: driver data
3411 */
3412static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3413{
3414 struct ixgbe_hw *hw = &adapter->hw;
3415 u32 vlnctrl;
3416
3417 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3418 vlnctrl |= IXGBE_VLNCTRL_VFE;
3419 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3420 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3421}
3422
3423/**
3424 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3425 * @adapter: driver data
3426 */
3427static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3428{
3429 struct ixgbe_hw *hw = &adapter->hw;
3430 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003431 int i, j;
3432
3433 switch (hw->mac.type) {
3434 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003435 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3436 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003437 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3438 break;
3439 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003440 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003441 for (i = 0; i < adapter->num_rx_queues; i++) {
3442 j = adapter->rx_ring[i]->reg_idx;
3443 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3444 vlnctrl &= ~IXGBE_RXDCTL_VME;
3445 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3446 }
3447 break;
3448 default:
3449 break;
3450 }
3451}
3452
3453/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003454 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003455 * @adapter: driver data
3456 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003457static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003458{
3459 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003460 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003461 int i, j;
3462
3463 switch (hw->mac.type) {
3464 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003465 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3466 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003467 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3468 break;
3469 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003470 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003471 for (i = 0; i < adapter->num_rx_queues; i++) {
3472 j = adapter->rx_ring[i]->reg_idx;
3473 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3474 vlnctrl |= IXGBE_RXDCTL_VME;
3475 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3476 }
3477 break;
3478 default:
3479 break;
3480 }
3481}
3482
Auke Kok9a799d72007-09-15 14:07:45 -07003483static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3484{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003485 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003486
Jesse Grossf62bbb52010-10-20 13:56:10 +00003487 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3488
3489 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3490 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003491}
3492
3493/**
Alexander Duyck28500622010-06-15 09:25:48 +00003494 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3495 * @netdev: network interface device structure
3496 *
3497 * Writes unicast address list to the RAR table.
3498 * Returns: -ENOMEM on failure/insufficient address space
3499 * 0 on no addresses written
3500 * X on writing X addresses to the RAR table
3501 **/
3502static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3503{
3504 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3505 struct ixgbe_hw *hw = &adapter->hw;
3506 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003507 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003508 int count = 0;
3509
3510 /* return ENOMEM indicating insufficient memory for addresses */
3511 if (netdev_uc_count(netdev) > rar_entries)
3512 return -ENOMEM;
3513
3514 if (!netdev_uc_empty(netdev) && rar_entries) {
3515 struct netdev_hw_addr *ha;
3516 /* return error if we do not support writing to RAR table */
3517 if (!hw->mac.ops.set_rar)
3518 return -ENOMEM;
3519
3520 netdev_for_each_uc_addr(ha, netdev) {
3521 if (!rar_entries)
3522 break;
3523 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3524 vfn, IXGBE_RAH_AV);
3525 count++;
3526 }
3527 }
3528 /* write the addresses in reverse order to avoid write combining */
3529 for (; rar_entries > 0 ; rar_entries--)
3530 hw->mac.ops.clear_rar(hw, rar_entries);
3531
3532 return count;
3533}
3534
3535/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003536 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003537 * @netdev: network interface device structure
3538 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003539 * The set_rx_method entry point is called whenever the unicast/multicast
3540 * address list or the network interface flags are updated. This routine is
3541 * responsible for configuring the hardware for proper unicast, multicast and
3542 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003543 **/
Greg Rose7f870472010-01-09 02:25:29 +00003544void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003545{
3546 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3547 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003548 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3549 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003550
3551 /* Check for Promiscuous and All Multicast modes */
3552
3553 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3554
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003555 /* set all bits that we expect to always be set */
3556 fctrl |= IXGBE_FCTRL_BAM;
3557 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3558 fctrl |= IXGBE_FCTRL_PMCF;
3559
Alexander Duyck28500622010-06-15 09:25:48 +00003560 /* clear the bits we are changing the status of */
3561 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3562
Auke Kok9a799d72007-09-15 14:07:45 -07003563 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003564 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003565 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003566 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003567 /* don't hardware filter vlans in promisc mode */
3568 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003569 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003570 if (netdev->flags & IFF_ALLMULTI) {
3571 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003572 vmolr |= IXGBE_VMOLR_MPE;
3573 } else {
3574 /*
3575 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003576 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003577 * that we can at least receive multicast traffic
3578 */
3579 hw->mac.ops.update_mc_addr_list(hw, netdev);
3580 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003581 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003582 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003583 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003584 /*
3585 * Write addresses to available RAR registers, if there is not
3586 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003587 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003588 */
3589 count = ixgbe_write_uc_addr_list(netdev);
3590 if (count < 0) {
3591 fctrl |= IXGBE_FCTRL_UPE;
3592 vmolr |= IXGBE_VMOLR_ROPE;
3593 }
3594 }
3595
3596 if (adapter->num_vfs) {
3597 ixgbe_restore_vf_multicasts(adapter);
3598 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3599 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3600 IXGBE_VMOLR_ROPE);
3601 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003602 }
3603
3604 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003605
3606 if (netdev->features & NETIF_F_HW_VLAN_RX)
3607 ixgbe_vlan_strip_enable(adapter);
3608 else
3609 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003610}
3611
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003612static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3613{
3614 int q_idx;
3615 struct ixgbe_q_vector *q_vector;
3616 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3617
3618 /* legacy and MSI only use one vector */
3619 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3620 q_vectors = 1;
3621
3622 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003623 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003624 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003625 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003626 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3627 if (!q_vector->rxr_count || !q_vector->txr_count) {
3628 if (q_vector->txr_count == 1)
3629 napi->poll = &ixgbe_clean_txonly;
3630 else if (q_vector->rxr_count == 1)
3631 napi->poll = &ixgbe_clean_rxonly;
3632 }
3633 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003634
3635 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003636 }
3637}
3638
3639static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3640{
3641 int q_idx;
3642 struct ixgbe_q_vector *q_vector;
3643 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3644
3645 /* legacy and MSI only use one vector */
3646 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3647 q_vectors = 1;
3648
3649 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003650 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003651 napi_disable(&q_vector->napi);
3652 }
3653}
3654
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003655#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003656/*
3657 * ixgbe_configure_dcb - Configure DCB hardware
3658 * @adapter: ixgbe adapter struct
3659 *
3660 * This is called by the driver on open to configure the DCB hardware.
3661 * This is also called by the gennetlink interface when reconfiguring
3662 * the DCB state.
3663 */
3664static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3665{
3666 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003667 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003668
Alexander Duyck67ebd792010-08-19 13:34:04 +00003669 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3670 if (hw->mac.type == ixgbe_mac_82598EB)
3671 netif_set_gso_max_size(adapter->netdev, 65536);
3672 return;
3673 }
3674
3675 if (hw->mac.type == ixgbe_mac_82598EB)
3676 netif_set_gso_max_size(adapter->netdev, 32768);
3677
Alexander Duyck2f90b862008-11-20 20:52:10 -08003678
Alexander Duyck2f90b862008-11-20 20:52:10 -08003679 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003680 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003681
Alexander Duyck2f90b862008-11-20 20:52:10 -08003682 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003683
3684 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003685 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003686#ifdef CONFIG_FCOE
3687 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3688 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3689#endif
3690 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3691 DCB_TX_CONFIG);
3692 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3693 DCB_RX_CONFIG);
3694 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3695 } else {
3696 struct net_device *dev = adapter->netdev;
3697
3698 if (adapter->ixgbe_ieee_ets)
3699 dev->dcbnl_ops->ieee_setets(dev,
3700 adapter->ixgbe_ieee_ets);
3701 if (adapter->ixgbe_ieee_pfc)
3702 dev->dcbnl_ops->ieee_setpfc(dev,
3703 adapter->ixgbe_ieee_pfc);
3704 }
John Fastabend8187cd42011-02-23 05:58:08 +00003705
3706 /* Enable RSS Hash per TC */
3707 if (hw->mac.type != ixgbe_mac_82598EB) {
3708 int i;
3709 u32 reg = 0;
3710
3711 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3712 u8 msb = 0;
3713 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3714
3715 while (cnt >>= 1)
3716 msb++;
3717
3718 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3719 }
3720 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3721 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003722}
3723
3724#endif
John Fastabend80605c652011-05-02 12:34:10 +00003725
3726static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3727{
3728 int hdrm = 0;
3729 int num_tc = netdev_get_num_tc(adapter->netdev);
3730 struct ixgbe_hw *hw = &adapter->hw;
3731
3732 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3733 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3734 hdrm = 64 << adapter->fdir_pballoc;
3735
3736 hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL);
3737}
3738
Alexander Duycke4911d52011-05-11 07:18:52 +00003739static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3740{
3741 struct ixgbe_hw *hw = &adapter->hw;
3742 struct hlist_node *node, *node2;
3743 struct ixgbe_fdir_filter *filter;
3744
3745 spin_lock(&adapter->fdir_perfect_lock);
3746
3747 if (!hlist_empty(&adapter->fdir_filter_list))
3748 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3749
3750 hlist_for_each_entry_safe(filter, node, node2,
3751 &adapter->fdir_filter_list, fdir_node) {
3752 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003753 &filter->filter,
3754 filter->sw_idx,
3755 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3756 IXGBE_FDIR_DROP_QUEUE :
3757 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003758 }
3759
3760 spin_unlock(&adapter->fdir_perfect_lock);
3761}
3762
Auke Kok9a799d72007-09-15 14:07:45 -07003763static void ixgbe_configure(struct ixgbe_adapter *adapter)
3764{
3765 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003766 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003767 int i;
3768
John Fastabend80605c652011-05-02 12:34:10 +00003769 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003770#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003771 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003772#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003773
Jesse Grossf62bbb52010-10-20 13:56:10 +00003774 ixgbe_set_rx_mode(netdev);
3775 ixgbe_restore_vlan(adapter);
3776
Yi Zoueacd73f2009-05-13 13:11:06 +00003777#ifdef IXGBE_FCOE
3778 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3779 ixgbe_configure_fcoe(adapter);
3780
3781#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003782 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3783 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003784 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003785 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003786 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003787 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3788 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3789 adapter->fdir_pballoc);
3790 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003791 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003792 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003793
Auke Kok9a799d72007-09-15 14:07:45 -07003794 ixgbe_configure_tx(adapter);
3795 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003796}
3797
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003798static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3799{
3800 switch (hw->phy.type) {
3801 case ixgbe_phy_sfp_avago:
3802 case ixgbe_phy_sfp_ftl:
3803 case ixgbe_phy_sfp_intel:
3804 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003805 case ixgbe_phy_sfp_passive_tyco:
3806 case ixgbe_phy_sfp_passive_unknown:
3807 case ixgbe_phy_sfp_active_unknown:
3808 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003809 return true;
3810 default:
3811 return false;
3812 }
3813}
3814
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003815/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003816 * ixgbe_sfp_link_config - set up SFP+ link
3817 * @adapter: pointer to private adapter struct
3818 **/
3819static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3820{
Alexander Duyck70864002011-04-27 09:13:56 +00003821 /*
3822 * We are assuming the worst case scenerio here, and that
3823 * is that an SFP was inserted/removed after the reset
3824 * but before SFP detection was enabled. As such the best
3825 * solution is to just start searching as soon as we start
3826 */
3827 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3828 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003829
Alexander Duyck70864002011-04-27 09:13:56 +00003830 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003831}
3832
3833/**
3834 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003835 * @hw: pointer to private hardware struct
3836 *
3837 * Returns 0 on success, negative on failure
3838 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003839static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003840{
3841 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003842 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003843 u32 ret = IXGBE_ERR_LINK_SETUP;
3844
3845 if (hw->mac.ops.check_link)
3846 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3847
3848 if (ret)
3849 goto link_cfg_out;
3850
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003851 autoneg = hw->phy.autoneg_advertised;
3852 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003853 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3854 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003855 if (ret)
3856 goto link_cfg_out;
3857
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003858 if (hw->mac.ops.setup_link)
3859 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003860link_cfg_out:
3861 return ret;
3862}
3863
Alexander Duycka34bcff2010-08-19 13:39:20 +00003864static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003865{
Auke Kok9a799d72007-09-15 14:07:45 -07003866 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003867 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003868
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003869 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003870 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3871 IXGBE_GPIE_OCD;
3872 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003873 /*
3874 * use EIAM to auto-mask when MSI-X interrupt is asserted
3875 * this saves a register write for every interrupt
3876 */
3877 switch (hw->mac.type) {
3878 case ixgbe_mac_82598EB:
3879 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3880 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003881 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003882 case ixgbe_mac_X540:
3883 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003884 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3885 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3886 break;
3887 }
3888 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003889 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3890 * specifically only auto mask tx and rx interrupts */
3891 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003892 }
3893
Alexander Duycka34bcff2010-08-19 13:39:20 +00003894 /* XXX: to interrupt immediately for EICS writes, enable this */
3895 /* gpie |= IXGBE_GPIE_EIMEN; */
3896
3897 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3898 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3899 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003900 }
3901
Alexander Duycka34bcff2010-08-19 13:39:20 +00003902 /* Enable fan failure interrupt */
3903 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003904 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003905
Don Skidmore2698b202011-04-13 07:01:52 +00003906 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003907 gpie |= IXGBE_SDP1_GPIEN;
3908 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003909 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003910
3911 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3912}
3913
3914static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3915{
3916 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003917 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003918 u32 ctrl_ext;
3919
3920 ixgbe_get_hw_control(adapter);
3921 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003922
Auke Kok9a799d72007-09-15 14:07:45 -07003923 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3924 ixgbe_configure_msix(adapter);
3925 else
3926 ixgbe_configure_msi_and_legacy(adapter);
3927
Don Skidmorec6ecf392010-12-03 03:31:51 +00003928 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3929 if (hw->mac.ops.enable_tx_laser &&
3930 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003931 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003932 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003933 hw->mac.ops.enable_tx_laser(hw);
3934
Auke Kok9a799d72007-09-15 14:07:45 -07003935 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003936 ixgbe_napi_enable_all(adapter);
3937
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003938 if (ixgbe_is_sfp(hw)) {
3939 ixgbe_sfp_link_config(adapter);
3940 } else {
3941 err = ixgbe_non_sfp_link_config(hw);
3942 if (err)
3943 e_err(probe, "link_config FAILED %d\n", err);
3944 }
3945
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003946 /* clear any pending interrupts, may auto mask */
3947 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003948 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003949
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003950 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003951 * If this adapter has a fan, check to see if we had a failure
3952 * before we enabled the interrupt.
3953 */
3954 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3955 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3956 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003957 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003958 }
3959
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003960 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003961 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003962
Auke Kok9a799d72007-09-15 14:07:45 -07003963 /* bring the link up in the watchdog, this could race with our first
3964 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003965 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3966 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003967 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003968
3969 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3970 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3971 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3972 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3973
Auke Kok9a799d72007-09-15 14:07:45 -07003974 return 0;
3975}
3976
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003977void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3978{
3979 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003980 /* put off any impending NetWatchDogTimeout */
3981 adapter->netdev->trans_start = jiffies;
3982
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003983 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003984 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003985 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003986 /*
3987 * If SR-IOV enabled then wait a bit before bringing the adapter
3988 * back up to give the VFs time to respond to the reset. The
3989 * two second wait is based upon the watchdog timer cycle in
3990 * the VF driver.
3991 */
3992 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3993 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003994 ixgbe_up(adapter);
3995 clear_bit(__IXGBE_RESETTING, &adapter->state);
3996}
3997
Auke Kok9a799d72007-09-15 14:07:45 -07003998int ixgbe_up(struct ixgbe_adapter *adapter)
3999{
4000 /* hardware has been reset, we need to reload some things */
4001 ixgbe_configure(adapter);
4002
4003 return ixgbe_up_complete(adapter);
4004}
4005
4006void ixgbe_reset(struct ixgbe_adapter *adapter)
4007{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004008 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004009 int err;
4010
Alexander Duyck70864002011-04-27 09:13:56 +00004011 /* lock SFP init bit to prevent race conditions with the watchdog */
4012 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4013 usleep_range(1000, 2000);
4014
4015 /* clear all SFP and link config related flags while holding SFP_INIT */
4016 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4017 IXGBE_FLAG2_SFP_NEEDS_RESET);
4018 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4019
Don Skidmore8ca783a2009-05-26 20:40:47 -07004020 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004021 switch (err) {
4022 case 0:
4023 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004024 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004025 break;
4026 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004027 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004028 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004029 case IXGBE_ERR_EEPROM_VERSION:
4030 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004031 e_dev_warn("This device is a pre-production adapter/LOM. "
4032 "Please be aware there may be issuesassociated with "
4033 "your hardware. If you are experiencing problems "
4034 "please contact your Intel or hardware "
4035 "representative who provided you with this "
4036 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004037 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004038 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004039 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004040 }
Auke Kok9a799d72007-09-15 14:07:45 -07004041
Alexander Duyck70864002011-04-27 09:13:56 +00004042 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4043
Auke Kok9a799d72007-09-15 14:07:45 -07004044 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004045 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4046 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004047}
4048
Auke Kok9a799d72007-09-15 14:07:45 -07004049/**
4050 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004051 * @rx_ring: ring to free buffers from
4052 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004053static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004054{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004055 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004056 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004057 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004058
Alexander Duyck84418e32010-08-19 13:40:54 +00004059 /* ring already cleared, nothing to do */
4060 if (!rx_ring->rx_buffer_info)
4061 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004062
Alexander Duyck84418e32010-08-19 13:40:54 +00004063 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004064 for (i = 0; i < rx_ring->count; i++) {
4065 struct ixgbe_rx_buffer *rx_buffer_info;
4066
4067 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4068 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004069 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004070 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004071 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004072 rx_buffer_info->dma = 0;
4073 }
4074 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004075 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004076 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004077 do {
4078 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004079 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004080 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00004081 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004082 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004083 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004084 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004085 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004086 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00004087 skb = skb->prev;
4088 dev_kfree_skb(this);
4089 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004090 }
4091 if (!rx_buffer_info->page)
4092 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004093 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004094 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004095 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004096 rx_buffer_info->page_dma = 0;
4097 }
Auke Kok9a799d72007-09-15 14:07:45 -07004098 put_page(rx_buffer_info->page);
4099 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004100 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004101 }
4102
4103 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4104 memset(rx_ring->rx_buffer_info, 0, size);
4105
4106 /* Zero out the descriptor ring */
4107 memset(rx_ring->desc, 0, rx_ring->size);
4108
4109 rx_ring->next_to_clean = 0;
4110 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004111}
4112
4113/**
4114 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004115 * @tx_ring: ring to be cleaned
4116 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004117static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004118{
4119 struct ixgbe_tx_buffer *tx_buffer_info;
4120 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004121 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004122
Alexander Duyck84418e32010-08-19 13:40:54 +00004123 /* ring already cleared, nothing to do */
4124 if (!tx_ring->tx_buffer_info)
4125 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004126
Alexander Duyck84418e32010-08-19 13:40:54 +00004127 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004128 for (i = 0; i < tx_ring->count; i++) {
4129 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004130 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004131 }
4132
4133 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4134 memset(tx_ring->tx_buffer_info, 0, size);
4135
4136 /* Zero out the descriptor ring */
4137 memset(tx_ring->desc, 0, tx_ring->size);
4138
4139 tx_ring->next_to_use = 0;
4140 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004141}
4142
4143/**
Auke Kok9a799d72007-09-15 14:07:45 -07004144 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4145 * @adapter: board private structure
4146 **/
4147static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4148{
4149 int i;
4150
4151 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004152 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004153}
4154
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004155/**
4156 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4157 * @adapter: board private structure
4158 **/
4159static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4160{
4161 int i;
4162
4163 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004164 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004165}
4166
Alexander Duycke4911d52011-05-11 07:18:52 +00004167static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4168{
4169 struct hlist_node *node, *node2;
4170 struct ixgbe_fdir_filter *filter;
4171
4172 spin_lock(&adapter->fdir_perfect_lock);
4173
4174 hlist_for_each_entry_safe(filter, node, node2,
4175 &adapter->fdir_filter_list, fdir_node) {
4176 hlist_del(&filter->fdir_node);
4177 kfree(filter);
4178 }
4179 adapter->fdir_filter_count = 0;
4180
4181 spin_unlock(&adapter->fdir_perfect_lock);
4182}
4183
Auke Kok9a799d72007-09-15 14:07:45 -07004184void ixgbe_down(struct ixgbe_adapter *adapter)
4185{
4186 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004187 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004188 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004189 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004190 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004191
4192 /* signal that we are down to the interrupt handler */
4193 set_bit(__IXGBE_DOWN, &adapter->state);
4194
4195 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004196 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4197 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004198
Yi Zou2d39d572011-01-06 14:29:56 +00004199 /* disable all enabled rx queues */
4200 for (i = 0; i < adapter->num_rx_queues; i++)
4201 /* this call also flushes the previous write */
4202 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4203
Don Skidmore032b4322011-03-18 09:32:53 +00004204 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004205
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004206 netif_tx_stop_all_queues(netdev);
4207
Alexander Duyck70864002011-04-27 09:13:56 +00004208 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004209 netif_carrier_off(netdev);
4210 netif_tx_disable(netdev);
4211
4212 ixgbe_irq_disable(adapter);
4213
4214 ixgbe_napi_disable_all(adapter);
4215
Alexander Duyckd034acf2011-04-27 09:25:34 +00004216 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4217 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004218 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4219
4220 del_timer_sync(&adapter->service_timer);
4221
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004222 /* disable receive for all VFs and wait one second */
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004223 if (adapter->num_vfs) {
4224 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004225 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004226
Auke Kok9a799d72007-09-15 14:07:45 -07004227 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004228 ixgbe_disable_tx_rx(adapter);
4229
4230 /* Mark all the VFs as inactive */
4231 for (i = 0 ; i < adapter->num_vfs; i++)
4232 adapter->vfinfo[i].clear_to_send = 0;
4233 }
4234
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004235 /* Cleanup the affinity_hint CPU mask memory and callback */
4236 for (i = 0; i < num_q_vectors; i++) {
4237 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4238 /* clear the affinity_mask in the IRQ descriptor */
4239 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4240 /* release the CPU mask memory */
4241 free_cpumask_var(q_vector->affinity_mask);
4242 }
4243
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004244 /* disable transmits in the hardware now that interrupts are off */
4245 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004246 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004247 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004248 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004249
4250 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004251 switch (hw->mac.type) {
4252 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004253 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004254 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004255 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4256 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004257 break;
4258 default:
4259 break;
4260 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004261
Paul Larson6f4a0e42008-06-24 17:00:56 -07004262 if (!pci_channel_offline(adapter->pdev))
4263 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004264
4265 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4266 if (hw->mac.ops.disable_tx_laser &&
4267 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004268 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004269 (hw->mac.type == ixgbe_mac_82599EB))))
4270 hw->mac.ops.disable_tx_laser(hw);
4271
Auke Kok9a799d72007-09-15 14:07:45 -07004272 ixgbe_clean_all_tx_rings(adapter);
4273 ixgbe_clean_all_rx_rings(adapter);
4274
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004275#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004276 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004277 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004278#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004279}
4280
Auke Kok9a799d72007-09-15 14:07:45 -07004281/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004282 * ixgbe_poll - NAPI Rx polling callback
4283 * @napi: structure for representing this polling device
4284 * @budget: how many packets driver is allowed to clean
4285 *
4286 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004287 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004288static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004289{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004290 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004291 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004292 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004293 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004294
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004295#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004296 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4297 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004298#endif
4299
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004300 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4301 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004302
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004303 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004304 work_done = budget;
4305
David S. Miller53e52c72008-01-07 21:06:12 -08004306 /* If budget not fully consumed, exit the polling mode */
4307 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004308 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004309 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08004310 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004311 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004312 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004313 }
Auke Kok9a799d72007-09-15 14:07:45 -07004314 return work_done;
4315}
4316
4317/**
4318 * ixgbe_tx_timeout - Respond to a Tx Hang
4319 * @netdev: network interface device structure
4320 **/
4321static void ixgbe_tx_timeout(struct net_device *netdev)
4322{
4323 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4324
4325 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004326 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004327}
4328
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004329/**
4330 * ixgbe_set_rss_queues: Allocate queues for RSS
4331 * @adapter: board private structure to initialize
4332 *
4333 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4334 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4335 *
4336 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004337static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4338{
4339 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004340 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004341
4342 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004343 f->mask = 0xF;
4344 adapter->num_rx_queues = f->indices;
4345 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004346 ret = true;
4347 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004348 ret = false;
4349 }
4350
4351 return ret;
4352}
4353
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004354/**
4355 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4356 * @adapter: board private structure to initialize
4357 *
4358 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4359 * to the original CPU that initiated the Tx session. This runs in addition
4360 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4361 * Rx load across CPUs using RSS.
4362 *
4363 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004364static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004365{
4366 bool ret = false;
4367 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4368
4369 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4370 f_fdir->mask = 0;
4371
4372 /* Flow Director must have RSS enabled */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004373 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4374 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004375 adapter->num_tx_queues = f_fdir->indices;
4376 adapter->num_rx_queues = f_fdir->indices;
4377 ret = true;
4378 } else {
4379 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004380 }
4381 return ret;
4382}
4383
Yi Zou0331a832009-05-17 12:33:52 +00004384#ifdef IXGBE_FCOE
4385/**
4386 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4387 * @adapter: board private structure to initialize
4388 *
4389 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4390 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4391 * rx queues out of the max number of rx queues, instead, it is used as the
4392 * index of the first rx queue used by FCoE.
4393 *
4394 **/
4395static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4396{
Yi Zou0331a832009-05-17 12:33:52 +00004397 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4398
John Fastabende5b64632011-03-08 03:44:52 +00004399 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4400 return false;
4401
John Fastabende901acd2011-04-26 07:26:08 +00004402 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004403
John Fastabende901acd2011-04-26 07:26:08 +00004404 adapter->num_rx_queues = 1;
4405 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004406
John Fastabende901acd2011-04-26 07:26:08 +00004407 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4408 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004409 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004410 ixgbe_set_fdir_queues(adapter);
4411 else
4412 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004413 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004414
John Fastabende901acd2011-04-26 07:26:08 +00004415 /* adding FCoE rx rings to the end */
4416 f->mask = adapter->num_rx_queues;
4417 adapter->num_rx_queues += f->indices;
4418 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004419
John Fastabende5b64632011-03-08 03:44:52 +00004420 return true;
4421}
4422#endif /* IXGBE_FCOE */
4423
John Fastabende901acd2011-04-26 07:26:08 +00004424/* Artificial max queue cap per traffic class in DCB mode */
4425#define DCB_QUEUE_CAP 8
4426
John Fastabende5b64632011-03-08 03:44:52 +00004427#ifdef CONFIG_IXGBE_DCB
4428static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4429{
John Fastabende901acd2011-04-26 07:26:08 +00004430 int per_tc_q, q, i, offset = 0;
4431 struct net_device *dev = adapter->netdev;
4432 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004433
John Fastabende901acd2011-04-26 07:26:08 +00004434 if (!tcs)
4435 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004436
John Fastabende901acd2011-04-26 07:26:08 +00004437 /* Map queue offset and counts onto allocated tx queues */
4438 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4439 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004440
John Fastabend8b1c0b22011-05-03 02:26:48 +00004441 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004442 netdev_set_prio_tc_map(dev, i, i);
4443 netdev_set_tc_queue(dev, i, q, offset);
4444 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004445 }
4446
John Fastabende901acd2011-04-26 07:26:08 +00004447 adapter->num_tx_queues = q * tcs;
4448 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004449
4450#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004451 /* FCoE enabled queues require special configuration indexed
4452 * by feature specific indices and mask. Here we map FCoE
4453 * indices onto the DCB queue pairs allowing FCoE to own
4454 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004455 */
John Fastabende901acd2011-04-26 07:26:08 +00004456 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4457 int tc;
4458 struct ixgbe_ring_feature *f =
4459 &adapter->ring_feature[RING_F_FCOE];
4460
4461 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4462 f->indices = dev->tc_to_txq[tc].count;
4463 f->mask = dev->tc_to_txq[tc].offset;
4464 }
John Fastabende5b64632011-03-08 03:44:52 +00004465#endif
4466
John Fastabende901acd2011-04-26 07:26:08 +00004467 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004468}
John Fastabende5b64632011-03-08 03:44:52 +00004469#endif
Yi Zou0331a832009-05-17 12:33:52 +00004470
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004471/**
4472 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4473 * @adapter: board private structure to initialize
4474 *
4475 * IOV doesn't actually use anything, so just NAK the
4476 * request for now and let the other queue routines
4477 * figure out what to do.
4478 */
4479static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4480{
4481 return false;
4482}
4483
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004484/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004485 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004486 * @adapter: board private structure to initialize
4487 *
4488 * This is the top level queue allocation routine. The order here is very
4489 * important, starting with the "most" number of features turned on at once,
4490 * and ending with the smallest set of features. This way large combinations
4491 * can be allocated if they're turned on, and smaller combinations are the
4492 * fallthrough conditions.
4493 *
4494 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004495static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004496{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004497 /* Start with base case */
4498 adapter->num_rx_queues = 1;
4499 adapter->num_tx_queues = 1;
4500 adapter->num_rx_pools = adapter->num_rx_queues;
4501 adapter->num_rx_queues_per_pool = 1;
4502
4503 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004504 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004505
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004506#ifdef CONFIG_IXGBE_DCB
4507 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004508 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004509
4510#endif
John Fastabende5b64632011-03-08 03:44:52 +00004511#ifdef IXGBE_FCOE
4512 if (ixgbe_set_fcoe_queues(adapter))
4513 goto done;
4514
4515#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004516 if (ixgbe_set_fdir_queues(adapter))
4517 goto done;
4518
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004519 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004520 goto done;
4521
4522 /* fallback to base case */
4523 adapter->num_rx_queues = 1;
4524 adapter->num_tx_queues = 1;
4525
4526done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004527 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004528 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004529 return netif_set_real_num_rx_queues(adapter->netdev,
4530 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004531}
4532
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004533static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004534 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004535{
4536 int err, vector_threshold;
4537
4538 /* We'll want at least 3 (vector_threshold):
4539 * 1) TxQ[0] Cleanup
4540 * 2) RxQ[0] Cleanup
4541 * 3) Other (Link Status Change, etc.)
4542 * 4) TCP Timer (optional)
4543 */
4544 vector_threshold = MIN_MSIX_COUNT;
4545
4546 /* The more we get, the more we will assign to Tx/Rx Cleanup
4547 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4548 * Right now, we simply care about how many we'll get; we'll
4549 * set them up later while requesting irq's.
4550 */
4551 while (vectors >= vector_threshold) {
4552 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004553 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004554 if (!err) /* Success in acquiring all requested vectors. */
4555 break;
4556 else if (err < 0)
4557 vectors = 0; /* Nasty failure, quit now */
4558 else /* err == number of vectors we should try again with */
4559 vectors = err;
4560 }
4561
4562 if (vectors < vector_threshold) {
4563 /* Can't allocate enough MSI-X interrupts? Oh well.
4564 * This just means we'll go with either a single MSI
4565 * vector or fall back to legacy interrupts.
4566 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004567 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4568 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004569 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4570 kfree(adapter->msix_entries);
4571 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004572 } else {
4573 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004574 /*
4575 * Adjust for only the vectors we'll use, which is minimum
4576 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4577 * vectors we were allocated.
4578 */
4579 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004580 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004581 }
4582}
4583
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004584/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004585 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004586 * @adapter: board private structure to initialize
4587 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004588 * Cache the descriptor ring offsets for RSS to the assigned rings.
4589 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004590 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004591static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004592{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004593 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004594
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004595 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4596 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004597
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004598 for (i = 0; i < adapter->num_rx_queues; i++)
4599 adapter->rx_ring[i]->reg_idx = i;
4600 for (i = 0; i < adapter->num_tx_queues; i++)
4601 adapter->tx_ring[i]->reg_idx = i;
4602
4603 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004604}
4605
4606#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004607
4608/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004609static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4610 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004611{
4612 struct net_device *dev = adapter->netdev;
4613 struct ixgbe_hw *hw = &adapter->hw;
4614 u8 num_tcs = netdev_get_num_tc(dev);
4615
4616 *tx = 0;
4617 *rx = 0;
4618
4619 switch (hw->mac.type) {
4620 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004621 *tx = tc << 2;
4622 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004623 break;
4624 case ixgbe_mac_82599EB:
4625 case ixgbe_mac_X540:
4626 if (num_tcs == 8) {
4627 if (tc < 3) {
4628 *tx = tc << 5;
4629 *rx = tc << 4;
4630 } else if (tc < 5) {
4631 *tx = ((tc + 2) << 4);
4632 *rx = tc << 4;
4633 } else if (tc < num_tcs) {
4634 *tx = ((tc + 8) << 3);
4635 *rx = tc << 4;
4636 }
4637 } else if (num_tcs == 4) {
4638 *rx = tc << 5;
4639 switch (tc) {
4640 case 0:
4641 *tx = 0;
4642 break;
4643 case 1:
4644 *tx = 64;
4645 break;
4646 case 2:
4647 *tx = 96;
4648 break;
4649 case 3:
4650 *tx = 112;
4651 break;
4652 default:
4653 break;
4654 }
4655 }
4656 break;
4657 default:
4658 break;
4659 }
4660}
4661
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004662/**
4663 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4664 * @adapter: board private structure to initialize
4665 *
4666 * Cache the descriptor ring offsets for DCB to the assigned rings.
4667 *
4668 **/
4669static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4670{
John Fastabende5b64632011-03-08 03:44:52 +00004671 struct net_device *dev = adapter->netdev;
4672 int i, j, k;
4673 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004674
John Fastabend8b1c0b22011-05-03 02:26:48 +00004675 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004676 return false;
4677
John Fastabende5b64632011-03-08 03:44:52 +00004678 for (i = 0, k = 0; i < num_tcs; i++) {
4679 unsigned int tx_s, rx_s;
4680 u16 count = dev->tc_to_txq[i].count;
4681
4682 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4683 for (j = 0; j < count; j++, k++) {
4684 adapter->tx_ring[k]->reg_idx = tx_s + j;
4685 adapter->rx_ring[k]->reg_idx = rx_s + j;
4686 adapter->tx_ring[k]->dcb_tc = i;
4687 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004688 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004689 }
John Fastabende5b64632011-03-08 03:44:52 +00004690
4691 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004692}
4693#endif
4694
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004695/**
4696 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4697 * @adapter: board private structure to initialize
4698 *
4699 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4700 *
4701 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004702static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004703{
4704 int i;
4705 bool ret = false;
4706
Alexander Duyck03ecf912011-05-20 07:36:17 +00004707 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4708 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004709 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004710 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004711 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004712 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004713 ret = true;
4714 }
4715
4716 return ret;
4717}
4718
Yi Zou0331a832009-05-17 12:33:52 +00004719#ifdef IXGBE_FCOE
4720/**
4721 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4722 * @adapter: board private structure to initialize
4723 *
4724 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4725 *
4726 */
4727static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4728{
Yi Zou0331a832009-05-17 12:33:52 +00004729 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004730 int i;
4731 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004732
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004733 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4734 return false;
4735
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004736 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004737 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004738 ixgbe_cache_ring_fdir(adapter);
4739 else
4740 ixgbe_cache_ring_rss(adapter);
4741
4742 fcoe_rx_i = f->mask;
4743 fcoe_tx_i = f->mask;
4744 }
4745 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4746 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4747 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4748 }
4749 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004750}
4751
4752#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004753/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004754 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4755 * @adapter: board private structure to initialize
4756 *
4757 * SR-IOV doesn't use any descriptor rings but changes the default if
4758 * no other mapping is used.
4759 *
4760 */
4761static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4762{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004763 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4764 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004765 if (adapter->num_vfs)
4766 return true;
4767 else
4768 return false;
4769}
4770
4771/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004772 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4773 * @adapter: board private structure to initialize
4774 *
4775 * Once we know the feature-set enabled for the device, we'll cache
4776 * the register offset the descriptor ring is assigned to.
4777 *
4778 * Note, the order the various feature calls is important. It must start with
4779 * the "most" features enabled at the same time, then trickle down to the
4780 * least amount of features turned on at once.
4781 **/
4782static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4783{
4784 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004785 adapter->rx_ring[0]->reg_idx = 0;
4786 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004787
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004788 if (ixgbe_cache_ring_sriov(adapter))
4789 return;
4790
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004791#ifdef CONFIG_IXGBE_DCB
4792 if (ixgbe_cache_ring_dcb(adapter))
4793 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004794#endif
John Fastabende5b64632011-03-08 03:44:52 +00004795
4796#ifdef IXGBE_FCOE
4797 if (ixgbe_cache_ring_fcoe(adapter))
4798 return;
4799#endif /* IXGBE_FCOE */
4800
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004801 if (ixgbe_cache_ring_fdir(adapter))
4802 return;
4803
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004804 if (ixgbe_cache_ring_rss(adapter))
4805 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004806}
4807
Auke Kok9a799d72007-09-15 14:07:45 -07004808/**
4809 * ixgbe_alloc_queues - Allocate memory for all rings
4810 * @adapter: board private structure to initialize
4811 *
4812 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004813 * number of queues at compile-time. The polling_netdev array is
4814 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004815 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004816static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004817{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004818 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004819
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004820 if (nid < 0 || !node_online(nid))
4821 nid = first_online_node;
4822
4823 for (; tx < adapter->num_tx_queues; tx++) {
4824 struct ixgbe_ring *ring;
4825
4826 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004827 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004828 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004829 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004830 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004831 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004832 ring->queue_index = tx;
4833 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004834 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004835 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004836
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004837 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004838 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004839
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004840 for (; rx < adapter->num_rx_queues; rx++) {
4841 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004842
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004843 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004844 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004845 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004846 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004847 goto err_allocation;
4848 ring->count = adapter->rx_ring_count;
4849 ring->queue_index = rx;
4850 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004851 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004852 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004853
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004854 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004855 }
4856
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004857 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004858
4859 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004860
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004861err_allocation:
4862 while (tx)
4863 kfree(adapter->tx_ring[--tx]);
4864
4865 while (rx)
4866 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004867 return -ENOMEM;
4868}
4869
4870/**
4871 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4872 * @adapter: board private structure to initialize
4873 *
4874 * Attempt to configure the interrupts using the best available
4875 * capabilities of the hardware and the kernel.
4876 **/
Al Virofeea6a52008-11-27 15:34:07 -08004877static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004878{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004879 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004880 int err = 0;
4881 int vector, v_budget;
4882
4883 /*
4884 * It's easy to be greedy for MSI-X vectors, but it really
4885 * doesn't do us much good if we have a lot more vectors
4886 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004887 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004888 */
4889 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004890 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004891
4892 /*
4893 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004894 * hw.mac->max_msix_vectors vectors. With features
4895 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4896 * descriptor queues supported by our device. Thus, we cap it off in
4897 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004898 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004899 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004900
4901 /* A failure in MSI-X entry allocation isn't fatal, but it does
4902 * mean we disable MSI-X capabilities of the adapter. */
4903 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004904 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004905 if (adapter->msix_entries) {
4906 for (vector = 0; vector < v_budget; vector++)
4907 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004908
Alexander Duyck7a921c92009-05-06 10:43:28 +00004909 ixgbe_acquire_msix_vectors(adapter, v_budget);
4910
4911 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4912 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004913 }
David S. Miller26d27842010-05-03 15:18:22 -07004914
Alexander Duyck7a921c92009-05-06 10:43:28 +00004915 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4916 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004917 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004918 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004919 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004920 "queues are disabled. Disabling Flow Director\n");
4921 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004922 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004923 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004924 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4925 ixgbe_disable_sriov(adapter);
4926
Ben Hutchings847f53f2010-09-27 08:28:56 +00004927 err = ixgbe_set_num_queues(adapter);
4928 if (err)
4929 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004930
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004931 err = pci_enable_msi(adapter->pdev);
4932 if (!err) {
4933 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4934 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004935 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4936 "Unable to allocate MSI interrupt, "
4937 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004938 /* reset err */
4939 err = 0;
4940 }
4941
4942out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004943 return err;
4944}
4945
Alexander Duyck7a921c92009-05-06 10:43:28 +00004946/**
4947 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4948 * @adapter: board private structure to initialize
4949 *
4950 * We allocate one q_vector per queue interrupt. If allocation fails we
4951 * return -ENOMEM.
4952 **/
4953static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4954{
4955 int q_idx, num_q_vectors;
4956 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004957 int (*poll)(struct napi_struct *, int);
4958
4959 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4960 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004961 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004962 } else {
4963 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004964 poll = &ixgbe_poll;
4965 }
4966
4967 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004968 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004969 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004970 if (!q_vector)
4971 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004972 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004973 if (!q_vector)
4974 goto err_out;
4975 q_vector->adapter = adapter;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004976 if (q_vector->txr_count && !q_vector->rxr_count)
4977 q_vector->eitr = adapter->tx_eitr_param;
4978 else
4979 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004980 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004981 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004982 adapter->q_vector[q_idx] = q_vector;
4983 }
4984
4985 return 0;
4986
4987err_out:
4988 while (q_idx) {
4989 q_idx--;
4990 q_vector = adapter->q_vector[q_idx];
4991 netif_napi_del(&q_vector->napi);
4992 kfree(q_vector);
4993 adapter->q_vector[q_idx] = NULL;
4994 }
4995 return -ENOMEM;
4996}
4997
4998/**
4999 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5000 * @adapter: board private structure to initialize
5001 *
5002 * This function frees the memory allocated to the q_vectors. In addition if
5003 * NAPI is enabled it will delete any references to the NAPI struct prior
5004 * to freeing the q_vector.
5005 **/
5006static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5007{
5008 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005009
Alexander Duyck91281fd2009-06-04 16:00:27 +00005010 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005011 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005012 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00005013 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005014
5015 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
5016 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00005017 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005018 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005019 kfree(q_vector);
5020 }
5021}
5022
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005023static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005024{
5025 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5026 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5027 pci_disable_msix(adapter->pdev);
5028 kfree(adapter->msix_entries);
5029 adapter->msix_entries = NULL;
5030 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5031 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5032 pci_disable_msi(adapter->pdev);
5033 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005034}
5035
5036/**
5037 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5038 * @adapter: board private structure to initialize
5039 *
5040 * We determine which interrupt scheme to use based on...
5041 * - Kernel support (MSI, MSI-X)
5042 * - which can be user-defined (via MODULE_PARAM)
5043 * - Hardware queue count (num_*_queues)
5044 * - defined by miscellaneous hardware support/features (RSS, etc.)
5045 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005046int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005047{
5048 int err;
5049
5050 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005051 err = ixgbe_set_num_queues(adapter);
5052 if (err)
5053 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005054
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005055 err = ixgbe_set_interrupt_capability(adapter);
5056 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005057 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005058 goto err_set_interrupt;
5059 }
5060
Alexander Duyck7a921c92009-05-06 10:43:28 +00005061 err = ixgbe_alloc_q_vectors(adapter);
5062 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005063 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005064 goto err_alloc_q_vectors;
5065 }
5066
5067 err = ixgbe_alloc_queues(adapter);
5068 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005069 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005070 goto err_alloc_queues;
5071 }
5072
Emil Tantilov849c4542010-06-03 16:53:41 +00005073 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005074 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5075 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005076
5077 set_bit(__IXGBE_DOWN, &adapter->state);
5078
5079 return 0;
5080
Alexander Duyck7a921c92009-05-06 10:43:28 +00005081err_alloc_queues:
5082 ixgbe_free_q_vectors(adapter);
5083err_alloc_q_vectors:
5084 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005085err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005086 return err;
5087}
5088
5089/**
5090 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5091 * @adapter: board private structure to clear interrupt scheme on
5092 *
5093 * We go through and clear interrupt specific resources and reset the structure
5094 * to pre-load conditions
5095 **/
5096void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5097{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005098 int i;
5099
5100 for (i = 0; i < adapter->num_tx_queues; i++) {
5101 kfree(adapter->tx_ring[i]);
5102 adapter->tx_ring[i] = NULL;
5103 }
5104 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005105 struct ixgbe_ring *ring = adapter->rx_ring[i];
5106
5107 /* ixgbe_get_stats64() might access this ring, we must wait
5108 * a grace period before freeing it.
5109 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005110 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005111 adapter->rx_ring[i] = NULL;
5112 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005113
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005114 adapter->num_tx_queues = 0;
5115 adapter->num_rx_queues = 0;
5116
Alexander Duyck7a921c92009-05-06 10:43:28 +00005117 ixgbe_free_q_vectors(adapter);
5118 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005119}
5120
5121/**
5122 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5123 * @adapter: board private structure to initialize
5124 *
5125 * ixgbe_sw_init initializes the Adapter private data structure.
5126 * Fields are initialized based on PCI device information and
5127 * OS network device settings (MTU size).
5128 **/
5129static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5130{
5131 struct ixgbe_hw *hw = &adapter->hw;
5132 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005133 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005134 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005135#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005136 int j;
5137 struct tc_configuration *tc;
5138#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005139 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005140
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005141 /* PCI config space info */
5142
5143 hw->vendor_id = pdev->vendor;
5144 hw->device_id = pdev->device;
5145 hw->revision_id = pdev->revision;
5146 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5147 hw->subsystem_device_id = pdev->subsystem_device;
5148
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005149 /* Set capability flags */
5150 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5151 adapter->ring_feature[RING_F_RSS].indices = rss;
5152 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005153 switch (hw->mac.type) {
5154 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005155 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5156 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005157 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005158 break;
5159 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005160 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005161 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005162 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5163 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005164 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5165 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005166 /* n-tuple support exists, always init our spinlock */
5167 spin_lock_init(&adapter->fdir_perfect_lock);
5168 /* Flow Director hash filters enabled */
5169 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5170 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005171 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005172 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005173 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005174#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005175 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5176 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5177 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005178#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005179 /* Default traffic class to use for FCoE */
5180 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
John Fastabend56075a92010-07-26 20:41:31 +00005181 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005182#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005183#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005184 break;
5185 default:
5186 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005187 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005188
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005189#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005190 /* Configure DCB traffic classes */
5191 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5192 tc = &adapter->dcb_cfg.tc_config[j];
5193 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5194 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5195 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5196 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5197 tc->dcb_pfc = pfc_disabled;
5198 }
5199 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5200 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005201 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005202 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005203 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005204 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005205 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005206
5207#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005208
5209 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005210 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005211 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005212#ifdef CONFIG_DCB
5213 adapter->last_lfc_mode = hw->fc.current_mode;
5214#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005215 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5216 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005217 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5218 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005219 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005220
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005221 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005222 adapter->rx_itr_setting = 1;
5223 adapter->rx_eitr_param = 20000;
5224 adapter->tx_itr_setting = 1;
5225 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005226
5227 /* set defaults for eitr in MegaBytes */
5228 adapter->eitr_low = 10;
5229 adapter->eitr_high = 20;
5230
5231 /* set default ring sizes */
5232 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5233 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5234
Auke Kok9a799d72007-09-15 14:07:45 -07005235 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005236 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005237 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005238 return -EIO;
5239 }
5240
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005241 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005242 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5243
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005244 /* get assigned NUMA node */
5245 adapter->node = dev_to_node(&pdev->dev);
5246
Auke Kok9a799d72007-09-15 14:07:45 -07005247 set_bit(__IXGBE_DOWN, &adapter->state);
5248
5249 return 0;
5250}
5251
5252/**
5253 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005254 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005255 *
5256 * Return 0 on success, negative on failure
5257 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005258int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005259{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005260 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005261 int size;
5262
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005263 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005264 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005265 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005266 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005267 if (!tx_ring->tx_buffer_info)
5268 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005269
5270 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005271 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005272 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005273
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005274 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005275 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005276 if (!tx_ring->desc)
5277 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005278
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005279 tx_ring->next_to_use = 0;
5280 tx_ring->next_to_clean = 0;
5281 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07005282 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005283
5284err:
5285 vfree(tx_ring->tx_buffer_info);
5286 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005287 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005288 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005289}
5290
5291/**
Alexander Duyck69888672008-09-11 20:05:39 -07005292 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5293 * @adapter: board private structure
5294 *
5295 * If this function returns with an error, then it's possible one or
5296 * more of the rings is populated (while the rest are not). It is the
5297 * callers duty to clean those orphaned rings.
5298 *
5299 * Return 0 on success, negative on failure
5300 **/
5301static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5302{
5303 int i, err = 0;
5304
5305 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005306 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005307 if (!err)
5308 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005309 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005310 break;
5311 }
5312
5313 return err;
5314}
5315
5316/**
Auke Kok9a799d72007-09-15 14:07:45 -07005317 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005318 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005319 *
5320 * Returns 0 on success, negative on failure
5321 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005322int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005323{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005324 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005325 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005326
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005327 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005328 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005329 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005330 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005331 if (!rx_ring->rx_buffer_info)
5332 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005333
Auke Kok9a799d72007-09-15 14:07:45 -07005334 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005335 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5336 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005337
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005338 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005339 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005340
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005341 if (!rx_ring->desc)
5342 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005343
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005344 rx_ring->next_to_clean = 0;
5345 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005346
5347 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005348err:
5349 vfree(rx_ring->rx_buffer_info);
5350 rx_ring->rx_buffer_info = NULL;
5351 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005352 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005353}
5354
5355/**
Alexander Duyck69888672008-09-11 20:05:39 -07005356 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5357 * @adapter: board private structure
5358 *
5359 * If this function returns with an error, then it's possible one or
5360 * more of the rings is populated (while the rest are not). It is the
5361 * callers duty to clean those orphaned rings.
5362 *
5363 * Return 0 on success, negative on failure
5364 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005365static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5366{
5367 int i, err = 0;
5368
5369 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005370 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005371 if (!err)
5372 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005373 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005374 break;
5375 }
5376
5377 return err;
5378}
5379
5380/**
Auke Kok9a799d72007-09-15 14:07:45 -07005381 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005382 * @tx_ring: Tx descriptor ring for a specific queue
5383 *
5384 * Free all transmit software resources
5385 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005386void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005387{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005388 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005389
5390 vfree(tx_ring->tx_buffer_info);
5391 tx_ring->tx_buffer_info = NULL;
5392
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005393 /* if not set, then don't free */
5394 if (!tx_ring->desc)
5395 return;
5396
5397 dma_free_coherent(tx_ring->dev, tx_ring->size,
5398 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005399
5400 tx_ring->desc = NULL;
5401}
5402
5403/**
5404 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5405 * @adapter: board private structure
5406 *
5407 * Free all transmit software resources
5408 **/
5409static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5410{
5411 int i;
5412
5413 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005414 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005415 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005416}
5417
5418/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005419 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005420 * @rx_ring: ring to clean the resources from
5421 *
5422 * Free all receive software resources
5423 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005424void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005425{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005426 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005427
5428 vfree(rx_ring->rx_buffer_info);
5429 rx_ring->rx_buffer_info = NULL;
5430
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005431 /* if not set, then don't free */
5432 if (!rx_ring->desc)
5433 return;
5434
5435 dma_free_coherent(rx_ring->dev, rx_ring->size,
5436 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005437
5438 rx_ring->desc = NULL;
5439}
5440
5441/**
5442 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5443 * @adapter: board private structure
5444 *
5445 * Free all receive software resources
5446 **/
5447static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5448{
5449 int i;
5450
5451 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005452 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005453 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005454}
5455
5456/**
Auke Kok9a799d72007-09-15 14:07:45 -07005457 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5458 * @netdev: network interface device structure
5459 * @new_mtu: new value for maximum frame size
5460 *
5461 * Returns 0 on success, negative on failure
5462 **/
5463static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5464{
5465 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005466 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005467 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5468
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005469 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005470 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5471 hw->mac.type != ixgbe_mac_X540) {
5472 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5473 return -EINVAL;
5474 } else {
5475 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5476 return -EINVAL;
5477 }
Auke Kok9a799d72007-09-15 14:07:45 -07005478
Emil Tantilov396e7992010-07-01 20:05:12 +00005479 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005480 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005481 netdev->mtu = new_mtu;
5482
John Fastabend16b61be2010-11-16 19:26:44 -08005483 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5484 hw->fc.low_water = FC_LOW_WATER(max_frame);
5485
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005486 if (netif_running(netdev))
5487 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005488
5489 return 0;
5490}
5491
5492/**
5493 * ixgbe_open - Called when a network interface is made active
5494 * @netdev: network interface device structure
5495 *
5496 * Returns 0 on success, negative value on failure
5497 *
5498 * The open entry point is called when a network interface is made
5499 * active by the system (IFF_UP). At this point all resources needed
5500 * for transmit and receive operations are allocated, the interrupt
5501 * handler is registered with the OS, the watchdog timer is started,
5502 * and the stack is notified that the interface is ready.
5503 **/
5504static int ixgbe_open(struct net_device *netdev)
5505{
5506 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5507 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005508
Auke Kok4bebfaa2008-02-11 09:26:01 -08005509 /* disallow open during test */
5510 if (test_bit(__IXGBE_TESTING, &adapter->state))
5511 return -EBUSY;
5512
Jesse Brandeburg54386462009-04-17 20:44:27 +00005513 netif_carrier_off(netdev);
5514
Auke Kok9a799d72007-09-15 14:07:45 -07005515 /* allocate transmit descriptors */
5516 err = ixgbe_setup_all_tx_resources(adapter);
5517 if (err)
5518 goto err_setup_tx;
5519
Auke Kok9a799d72007-09-15 14:07:45 -07005520 /* allocate receive descriptors */
5521 err = ixgbe_setup_all_rx_resources(adapter);
5522 if (err)
5523 goto err_setup_rx;
5524
5525 ixgbe_configure(adapter);
5526
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005527 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005528 if (err)
5529 goto err_req_irq;
5530
Auke Kok9a799d72007-09-15 14:07:45 -07005531 err = ixgbe_up_complete(adapter);
5532 if (err)
5533 goto err_up;
5534
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005535 netif_tx_start_all_queues(netdev);
5536
Auke Kok9a799d72007-09-15 14:07:45 -07005537 return 0;
5538
5539err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005540 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005541 ixgbe_free_irq(adapter);
5542err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005543err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005544 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005545err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005546 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005547 ixgbe_reset(adapter);
5548
5549 return err;
5550}
5551
5552/**
5553 * ixgbe_close - Disables a network interface
5554 * @netdev: network interface device structure
5555 *
5556 * Returns 0, this is not allowed to fail
5557 *
5558 * The close entry point is called when an interface is de-activated
5559 * by the OS. The hardware is still under the drivers control, but
5560 * needs to be disabled. A global MAC reset is issued to stop the
5561 * hardware, and all transmit and receive resources are freed.
5562 **/
5563static int ixgbe_close(struct net_device *netdev)
5564{
5565 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005566
5567 ixgbe_down(adapter);
5568 ixgbe_free_irq(adapter);
5569
Alexander Duycke4911d52011-05-11 07:18:52 +00005570 ixgbe_fdir_filter_exit(adapter);
5571
Auke Kok9a799d72007-09-15 14:07:45 -07005572 ixgbe_free_all_tx_resources(adapter);
5573 ixgbe_free_all_rx_resources(adapter);
5574
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005575 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005576
5577 return 0;
5578}
5579
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005580#ifdef CONFIG_PM
5581static int ixgbe_resume(struct pci_dev *pdev)
5582{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005583 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5584 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005585 u32 err;
5586
5587 pci_set_power_state(pdev, PCI_D0);
5588 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005589 /*
5590 * pci_restore_state clears dev->state_saved so call
5591 * pci_save_state to restore it.
5592 */
5593 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005594
5595 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005596 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005597 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005598 return err;
5599 }
5600 pci_set_master(pdev);
5601
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005602 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005603
5604 err = ixgbe_init_interrupt_scheme(adapter);
5605 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005606 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005607 return err;
5608 }
5609
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005610 ixgbe_reset(adapter);
5611
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005612 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5613
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005614 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005615 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005616 if (err)
5617 return err;
5618 }
5619
5620 netif_device_attach(netdev);
5621
5622 return 0;
5623}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005624#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005625
5626static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005627{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005628 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5629 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005630 struct ixgbe_hw *hw = &adapter->hw;
5631 u32 ctrl, fctrl;
5632 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005633#ifdef CONFIG_PM
5634 int retval = 0;
5635#endif
5636
5637 netif_device_detach(netdev);
5638
5639 if (netif_running(netdev)) {
5640 ixgbe_down(adapter);
5641 ixgbe_free_irq(adapter);
5642 ixgbe_free_all_tx_resources(adapter);
5643 ixgbe_free_all_rx_resources(adapter);
5644 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005645
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005646 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005647#ifdef CONFIG_DCB
5648 kfree(adapter->ixgbe_ieee_pfc);
5649 kfree(adapter->ixgbe_ieee_ets);
5650#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005651
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005652#ifdef CONFIG_PM
5653 retval = pci_save_state(pdev);
5654 if (retval)
5655 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005656
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005657#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005658 if (wufc) {
5659 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005660
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005661 /* turn on all-multi mode if wake on multicast is enabled */
5662 if (wufc & IXGBE_WUFC_MC) {
5663 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5664 fctrl |= IXGBE_FCTRL_MPE;
5665 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5666 }
5667
5668 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5669 ctrl |= IXGBE_CTRL_GIO_DIS;
5670 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5671
5672 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5673 } else {
5674 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5675 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5676 }
5677
Alexander Duyckbd508172010-11-16 19:27:03 -08005678 switch (hw->mac.type) {
5679 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005680 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005681 break;
5682 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005683 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005684 pci_wake_from_d3(pdev, !!wufc);
5685 break;
5686 default:
5687 break;
5688 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005689
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005690 *enable_wake = !!wufc;
5691
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005692 ixgbe_release_hw_control(adapter);
5693
5694 pci_disable_device(pdev);
5695
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005696 return 0;
5697}
5698
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005699#ifdef CONFIG_PM
5700static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5701{
5702 int retval;
5703 bool wake;
5704
5705 retval = __ixgbe_shutdown(pdev, &wake);
5706 if (retval)
5707 return retval;
5708
5709 if (wake) {
5710 pci_prepare_to_sleep(pdev);
5711 } else {
5712 pci_wake_from_d3(pdev, false);
5713 pci_set_power_state(pdev, PCI_D3hot);
5714 }
5715
5716 return 0;
5717}
5718#endif /* CONFIG_PM */
5719
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005720static void ixgbe_shutdown(struct pci_dev *pdev)
5721{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005722 bool wake;
5723
5724 __ixgbe_shutdown(pdev, &wake);
5725
5726 if (system_state == SYSTEM_POWER_OFF) {
5727 pci_wake_from_d3(pdev, wake);
5728 pci_set_power_state(pdev, PCI_D3hot);
5729 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005730}
5731
5732/**
Auke Kok9a799d72007-09-15 14:07:45 -07005733 * ixgbe_update_stats - Update the board statistics counters.
5734 * @adapter: board private structure
5735 **/
5736void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5737{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005738 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005739 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005740 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005741 u64 total_mpc = 0;
5742 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005743 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5744 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5745 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005746
Don Skidmored08935c2010-06-11 13:20:29 +00005747 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5748 test_bit(__IXGBE_RESETTING, &adapter->state))
5749 return;
5750
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005751 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005752 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005753 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005754 for (i = 0; i < 16; i++)
5755 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005756 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005757 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005758 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5759 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005760 }
5761 adapter->rsc_total_count = rsc_count;
5762 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005763 }
5764
Alexander Duyck5b7da512010-11-16 19:26:50 -08005765 for (i = 0; i < adapter->num_rx_queues; i++) {
5766 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5767 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5768 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5769 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5770 bytes += rx_ring->stats.bytes;
5771 packets += rx_ring->stats.packets;
5772 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005773 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005774 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5775 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5776 netdev->stats.rx_bytes = bytes;
5777 netdev->stats.rx_packets = packets;
5778
5779 bytes = 0;
5780 packets = 0;
5781 /* gather some stats to the adapter struct that are per queue */
5782 for (i = 0; i < adapter->num_tx_queues; i++) {
5783 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5784 restart_queue += tx_ring->tx_stats.restart_queue;
5785 tx_busy += tx_ring->tx_stats.tx_busy;
5786 bytes += tx_ring->stats.bytes;
5787 packets += tx_ring->stats.packets;
5788 }
5789 adapter->restart_queue = restart_queue;
5790 adapter->tx_busy = tx_busy;
5791 netdev->stats.tx_bytes = bytes;
5792 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005793
Joe Perches7ca647b2010-09-07 21:35:40 +00005794 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005795 for (i = 0; i < 8; i++) {
5796 /* for packet buffers not used, the register should read 0 */
5797 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5798 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005799 hwstats->mpc[i] += mpc;
5800 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005801 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005802 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5803 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5804 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5805 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5806 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005807 switch (hw->mac.type) {
5808 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005809 hwstats->pxonrxc[i] +=
5810 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005811 break;
5812 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005813 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005814 hwstats->pxonrxc[i] +=
5815 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005816 break;
5817 default:
5818 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005819 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005820 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5821 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005822 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005823 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005824 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005825 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005826
John Fastabendc84d3242010-11-16 19:27:12 -08005827 ixgbe_update_xoff_received(adapter);
5828
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005829 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005830 switch (hw->mac.type) {
5831 case ixgbe_mac_82598EB:
5832 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005833 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5834 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5835 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5836 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005837 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005838 /* OS2BMC stats are X540 only*/
5839 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5840 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5841 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5842 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5843 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005844 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005845 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005846 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005847 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005848 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005849 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005850 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005851 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5852 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005853#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005854 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5855 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5856 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5857 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5858 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5859 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005860#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005861 break;
5862 default:
5863 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005864 }
Auke Kok9a799d72007-09-15 14:07:45 -07005865 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005866 hwstats->bprc += bprc;
5867 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005868 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005869 hwstats->mprc -= bprc;
5870 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5871 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5872 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5873 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5874 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5875 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5876 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5877 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005878 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005879 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005880 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005881 hwstats->lxofftxc += lxoff;
5882 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5883 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5884 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005885 /*
5886 * 82598 errata - tx of flow control packets is included in tx counters
5887 */
5888 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005889 hwstats->gptc -= xon_off_tot;
5890 hwstats->mptc -= xon_off_tot;
5891 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5892 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5893 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5894 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5895 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5896 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5897 hwstats->ptc64 -= xon_off_tot;
5898 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5899 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5900 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5901 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5902 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5903 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005904
5905 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005906 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005907
5908 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005909 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005910 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005911 netdev->stats.rx_length_errors = hwstats->rlec;
5912 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005913 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005914}
5915
5916/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005917 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5918 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005919 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005920static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005921{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005922 struct ixgbe_hw *hw = &adapter->hw;
5923 int i;
5924
Alexander Duyckd034acf2011-04-27 09:25:34 +00005925 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5926 return;
5927
5928 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5929
5930 /* if interface is down do nothing */
5931 if (test_bit(__IXGBE_DOWN, &adapter->state))
5932 return;
5933
5934 /* do nothing if we are not using signature filters */
5935 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5936 return;
5937
5938 adapter->fdir_overflow++;
5939
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005940 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5941 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005942 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005943 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005944 /* re-enable flow director interrupts */
5945 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005946 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005947 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005948 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005949 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005950}
5951
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005952/**
5953 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5954 * @adapter - pointer to the device adapter structure
5955 *
5956 * This function serves two purposes. First it strobes the interrupt lines
5957 * in order to make certain interrupts are occuring. Secondly it sets the
5958 * bits needed to check for TX hangs. As a result we should immediately
5959 * determine if a hang has occured.
5960 */
5961static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5962{
Auke Kok9a799d72007-09-15 14:07:45 -07005963 struct ixgbe_hw *hw = &adapter->hw;
5964 u64 eics = 0;
5965 int i;
5966
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005967 /* If we're down or resetting, just bail */
5968 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5969 test_bit(__IXGBE_RESETTING, &adapter->state))
5970 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005971
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005972 /* Force detection of hung controller */
5973 if (netif_carrier_ok(adapter->netdev)) {
5974 for (i = 0; i < adapter->num_tx_queues; i++)
5975 set_check_for_tx_hang(adapter->tx_ring[i]);
5976 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005977
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005978 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005979 /*
5980 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005981 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005982 * would set *both* EIMS and EICS for any bit in EIAM
5983 */
5984 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5985 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005986 } else {
5987 /* get one bit for every active tx/rx interrupt vector */
5988 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5989 struct ixgbe_q_vector *qv = adapter->q_vector[i];
5990 if (qv->rxr_count || qv->txr_count)
5991 eics |= ((u64)1 << i);
5992 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005993 }
5994
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005995 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005996 ixgbe_irq_rearm_queues(adapter, eics);
5997
Alexander Duyckfe49f042009-06-04 16:00:09 +00005998}
5999
6000/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006001 * ixgbe_watchdog_update_link - update the link status
6002 * @adapter - pointer to the device adapter structure
6003 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006004 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006005static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006006{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006007 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006008 u32 link_speed = adapter->link_speed;
6009 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006010 int i;
6011
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006012 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6013 return;
6014
6015 if (hw->mac.ops.check_link) {
6016 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006017 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006018 /* always assume link is up, if no check link function */
6019 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6020 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006021 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006022 if (link_up) {
6023 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6024 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6025 hw->mac.ops.fc_enable(hw, i);
6026 } else {
6027 hw->mac.ops.fc_enable(hw, 0);
6028 }
6029 }
6030
6031 if (link_up ||
6032 time_after(jiffies, (adapter->link_check_timeout +
6033 IXGBE_TRY_LINK_TIMEOUT))) {
6034 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6035 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6036 IXGBE_WRITE_FLUSH(hw);
6037 }
6038
6039 adapter->link_up = link_up;
6040 adapter->link_speed = link_speed;
6041}
6042
6043/**
6044 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6045 * print link up message
6046 * @adapter - pointer to the device adapter structure
6047 **/
6048static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6049{
6050 struct net_device *netdev = adapter->netdev;
6051 struct ixgbe_hw *hw = &adapter->hw;
6052 u32 link_speed = adapter->link_speed;
6053 bool flow_rx, flow_tx;
6054
6055 /* only continue if link was previously down */
6056 if (netif_carrier_ok(netdev))
6057 return;
6058
6059 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6060
6061 switch (hw->mac.type) {
6062 case ixgbe_mac_82598EB: {
6063 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6064 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6065 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6066 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6067 }
6068 break;
6069 case ixgbe_mac_X540:
6070 case ixgbe_mac_82599EB: {
6071 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6072 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6073 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6074 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6075 }
6076 break;
6077 default:
6078 flow_tx = false;
6079 flow_rx = false;
6080 break;
6081 }
6082 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6083 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6084 "10 Gbps" :
6085 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6086 "1 Gbps" :
6087 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6088 "100 Mbps" :
6089 "unknown speed"))),
6090 ((flow_rx && flow_tx) ? "RX/TX" :
6091 (flow_rx ? "RX" :
6092 (flow_tx ? "TX" : "None"))));
6093
6094 netif_carrier_on(netdev);
6095#ifdef HAVE_IPLINK_VF_CONFIG
6096 ixgbe_check_vf_rate_limit(adapter);
6097#endif /* HAVE_IPLINK_VF_CONFIG */
6098}
6099
6100/**
6101 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6102 * print link down message
6103 * @adapter - pointer to the adapter structure
6104 **/
6105static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6106{
6107 struct net_device *netdev = adapter->netdev;
6108 struct ixgbe_hw *hw = &adapter->hw;
6109
6110 adapter->link_up = false;
6111 adapter->link_speed = 0;
6112
6113 /* only continue if link was up previously */
6114 if (!netif_carrier_ok(netdev))
6115 return;
6116
6117 /* poll for SFP+ cable when link is down */
6118 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6119 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6120
6121 e_info(drv, "NIC Link is Down\n");
6122 netif_carrier_off(netdev);
6123}
6124
6125/**
6126 * ixgbe_watchdog_flush_tx - flush queues on link down
6127 * @adapter - pointer to the device adapter structure
6128 **/
6129static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6130{
6131 int i;
6132 int some_tx_pending = 0;
6133
6134 if (!netif_carrier_ok(adapter->netdev)) {
6135 for (i = 0; i < adapter->num_tx_queues; i++) {
6136 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6137 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6138 some_tx_pending = 1;
6139 break;
6140 }
6141 }
6142
6143 if (some_tx_pending) {
6144 /* We've lost link, so the controller stops DMA,
6145 * but we've got queued Tx work that's never going
6146 * to get done, so reset controller to flush Tx.
6147 * (Do the reset outside of interrupt context).
6148 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006149 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006150 }
6151 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006152}
6153
Greg Rosea985b6c32010-11-18 03:02:52 +00006154static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6155{
6156 u32 ssvpc;
6157
6158 /* Do not perform spoof check for 82598 */
6159 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6160 return;
6161
6162 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6163
6164 /*
6165 * ssvpc register is cleared on read, if zero then no
6166 * spoofed packets in the last interval.
6167 */
6168 if (!ssvpc)
6169 return;
6170
6171 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6172}
6173
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006174/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006175 * ixgbe_watchdog_subtask - check and bring link up
6176 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006177 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006178static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006179{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006180 /* if interface is down do nothing */
6181 if (test_bit(__IXGBE_DOWN, &adapter->state))
6182 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006183
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006184 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006185
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006186 if (adapter->link_up)
6187 ixgbe_watchdog_link_is_up(adapter);
6188 else
6189 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006190
Greg Rosea985b6c32010-11-18 03:02:52 +00006191 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006192 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006193
6194 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006195}
6196
Alexander Duyck70864002011-04-27 09:13:56 +00006197/**
6198 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6199 * @adapter - the ixgbe adapter structure
6200 **/
6201static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6202{
6203 struct ixgbe_hw *hw = &adapter->hw;
6204 s32 err;
6205
6206 /* not searching for SFP so there is nothing to do here */
6207 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6208 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6209 return;
6210
6211 /* someone else is in init, wait until next service event */
6212 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6213 return;
6214
6215 err = hw->phy.ops.identify_sfp(hw);
6216 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6217 goto sfp_out;
6218
6219 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6220 /* If no cable is present, then we need to reset
6221 * the next time we find a good cable. */
6222 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6223 }
6224
6225 /* exit on error */
6226 if (err)
6227 goto sfp_out;
6228
6229 /* exit if reset not needed */
6230 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6231 goto sfp_out;
6232
6233 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6234
6235 /*
6236 * A module may be identified correctly, but the EEPROM may not have
6237 * support for that module. setup_sfp() will fail in that case, so
6238 * we should not allow that module to load.
6239 */
6240 if (hw->mac.type == ixgbe_mac_82598EB)
6241 err = hw->phy.ops.reset(hw);
6242 else
6243 err = hw->mac.ops.setup_sfp(hw);
6244
6245 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6246 goto sfp_out;
6247
6248 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6249 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6250
6251sfp_out:
6252 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6253
6254 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6255 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6256 e_dev_err("failed to initialize because an unsupported "
6257 "SFP+ module type was detected.\n");
6258 e_dev_err("Reload the driver after installing a "
6259 "supported module.\n");
6260 unregister_netdev(adapter->netdev);
6261 }
6262}
6263
6264/**
6265 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6266 * @adapter - the ixgbe adapter structure
6267 **/
6268static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6269{
6270 struct ixgbe_hw *hw = &adapter->hw;
6271 u32 autoneg;
6272 bool negotiation;
6273
6274 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6275 return;
6276
6277 /* someone else is in init, wait until next service event */
6278 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6279 return;
6280
6281 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6282
6283 autoneg = hw->phy.autoneg_advertised;
6284 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6285 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6286 hw->mac.autotry_restart = false;
6287 if (hw->mac.ops.setup_link)
6288 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6289
6290 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6291 adapter->link_check_timeout = jiffies;
6292 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6293}
6294
6295/**
6296 * ixgbe_service_timer - Timer Call-back
6297 * @data: pointer to adapter cast into an unsigned long
6298 **/
6299static void ixgbe_service_timer(unsigned long data)
6300{
6301 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6302 unsigned long next_event_offset;
6303
6304 /* poll faster when waiting for link */
6305 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6306 next_event_offset = HZ / 10;
6307 else
6308 next_event_offset = HZ * 2;
6309
6310 /* Reset the timer */
6311 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6312
6313 ixgbe_service_event_schedule(adapter);
6314}
6315
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006316static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6317{
6318 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6319 return;
6320
6321 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6322
6323 /* If we're already down or resetting, just bail */
6324 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6325 test_bit(__IXGBE_RESETTING, &adapter->state))
6326 return;
6327
6328 ixgbe_dump(adapter);
6329 netdev_err(adapter->netdev, "Reset adapter\n");
6330 adapter->tx_timeout_count++;
6331
6332 ixgbe_reinit_locked(adapter);
6333}
6334
Alexander Duyck70864002011-04-27 09:13:56 +00006335/**
6336 * ixgbe_service_task - manages and runs subtasks
6337 * @work: pointer to work_struct containing our data
6338 **/
6339static void ixgbe_service_task(struct work_struct *work)
6340{
6341 struct ixgbe_adapter *adapter = container_of(work,
6342 struct ixgbe_adapter,
6343 service_task);
6344
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006345 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006346 ixgbe_sfp_detection_subtask(adapter);
6347 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006348 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006349 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006350 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006351 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006352
6353 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006354}
6355
Auke Kok9a799d72007-09-15 14:07:45 -07006356static int ixgbe_tso(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006357 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
Hao Zheng5e09a102010-11-11 13:47:59 +00006358 u32 tx_flags, u8 *hdr_len, __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006359{
6360 struct ixgbe_adv_tx_context_desc *context_desc;
6361 unsigned int i;
6362 int err;
6363 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006364 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
6365 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006366
6367 if (skb_is_gso(skb)) {
6368 if (skb_header_cloned(skb)) {
6369 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6370 if (err)
6371 return err;
6372 }
6373 l4len = tcp_hdrlen(skb);
6374 *hdr_len += l4len;
6375
Hao Zheng5e09a102010-11-11 13:47:59 +00006376 if (protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006377 struct iphdr *iph = ip_hdr(skb);
6378 iph->tot_len = 0;
6379 iph->check = 0;
6380 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006381 iph->daddr, 0,
6382 IPPROTO_TCP,
6383 0);
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08006384 } else if (skb_is_gso_v6(skb)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006385 ipv6_hdr(skb)->payload_len = 0;
6386 tcp_hdr(skb)->check =
6387 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006388 &ipv6_hdr(skb)->daddr,
6389 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07006390 }
6391
6392 i = tx_ring->next_to_use;
6393
6394 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006395 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006396
6397 /* VLAN MACLEN IPLEN */
6398 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6399 vlan_macip_lens |=
6400 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6401 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006402 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006403 *hdr_len += skb_network_offset(skb);
6404 vlan_macip_lens |=
6405 (skb_transport_header(skb) - skb_network_header(skb));
6406 *hdr_len +=
6407 (skb_transport_header(skb) - skb_network_header(skb));
6408 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6409 context_desc->seqnum_seed = 0;
6410
6411 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006412 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006413 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006414
Hao Zheng5e09a102010-11-11 13:47:59 +00006415 if (protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07006416 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
6417 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6418 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
6419
6420 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006421 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07006422 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
6423 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006424 /* use index 1 for TSO */
6425 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006426 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6427
6428 tx_buffer_info->time_stamp = jiffies;
6429 tx_buffer_info->next_to_watch = i;
6430
6431 i++;
6432 if (i == tx_ring->count)
6433 i = 0;
6434 tx_ring->next_to_use = i;
6435
6436 return true;
6437 }
6438 return false;
6439}
6440
Hao Zheng5e09a102010-11-11 13:47:59 +00006441static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb,
6442 __be16 protocol)
Joe Perches7ca647b2010-09-07 21:35:40 +00006443{
6444 u32 rtn = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006445
6446 switch (protocol) {
6447 case cpu_to_be16(ETH_P_IP):
6448 rtn |= IXGBE_ADVTXD_TUCMD_IPV4;
6449 switch (ip_hdr(skb)->protocol) {
6450 case IPPROTO_TCP:
6451 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6452 break;
6453 case IPPROTO_SCTP:
6454 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6455 break;
6456 }
6457 break;
6458 case cpu_to_be16(ETH_P_IPV6):
6459 /* XXX what about other V6 headers?? */
6460 switch (ipv6_hdr(skb)->nexthdr) {
6461 case IPPROTO_TCP:
6462 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6463 break;
6464 case IPPROTO_SCTP:
6465 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6466 break;
6467 }
6468 break;
6469 default:
6470 if (unlikely(net_ratelimit()))
6471 e_warn(probe, "partial checksum but proto=%x!\n",
Hao Zheng5e09a102010-11-11 13:47:59 +00006472 protocol);
Joe Perches7ca647b2010-09-07 21:35:40 +00006473 break;
6474 }
6475
6476 return rtn;
6477}
6478
Auke Kok9a799d72007-09-15 14:07:45 -07006479static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006480 struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006481 struct sk_buff *skb, u32 tx_flags,
6482 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006483{
6484 struct ixgbe_adv_tx_context_desc *context_desc;
6485 unsigned int i;
6486 struct ixgbe_tx_buffer *tx_buffer_info;
6487 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
6488
6489 if (skb->ip_summed == CHECKSUM_PARTIAL ||
6490 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
6491 i = tx_ring->next_to_use;
6492 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006493 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006494
6495 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6496 vlan_macip_lens |=
6497 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6498 vlan_macip_lens |= (skb_network_offset(skb) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006499 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006500 if (skb->ip_summed == CHECKSUM_PARTIAL)
6501 vlan_macip_lens |= (skb_transport_header(skb) -
Joe Perchese8e9f692010-09-07 21:34:53 +00006502 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07006503
6504 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6505 context_desc->seqnum_seed = 0;
6506
6507 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006508 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006509
Joe Perches7ca647b2010-09-07 21:35:40 +00006510 if (skb->ip_summed == CHECKSUM_PARTIAL)
Hao Zheng5e09a102010-11-11 13:47:59 +00006511 type_tucmd_mlhl |= ixgbe_psum(adapter, skb, protocol);
Auke Kok9a799d72007-09-15 14:07:45 -07006512
6513 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006514 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07006515 context_desc->mss_l4len_idx = 0;
6516
6517 tx_buffer_info->time_stamp = jiffies;
6518 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006519
Auke Kok9a799d72007-09-15 14:07:45 -07006520 i++;
6521 if (i == tx_ring->count)
6522 i = 0;
6523 tx_ring->next_to_use = i;
6524
6525 return true;
6526 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006527
Auke Kok9a799d72007-09-15 14:07:45 -07006528 return false;
6529}
6530
6531static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006532 struct ixgbe_ring *tx_ring,
6533 struct sk_buff *skb, u32 tx_flags,
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006534 unsigned int first, const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006535{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006536 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006537 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00006538 unsigned int len;
6539 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07006540 unsigned int offset = 0, size, count = 0, i;
6541 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6542 unsigned int f;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006543 unsigned int bytecount = skb->len;
6544 u16 gso_segs = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07006545
6546 i = tx_ring->next_to_use;
6547
Yi Zoueacd73f2009-05-13 13:11:06 +00006548 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6549 /* excluding fcoe_crc_eof for FCoE */
6550 total -= sizeof(struct fcoe_crc_eof);
6551
6552 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07006553 while (len) {
6554 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6555 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6556
6557 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00006558 tx_buffer_info->mapped_as_page = false;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006559 tx_buffer_info->dma = dma_map_single(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006560 skb->data + offset,
Nick Nunley1b507732010-04-27 13:10:27 +00006561 size, DMA_TO_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006562 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006563 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006564 tx_buffer_info->time_stamp = jiffies;
6565 tx_buffer_info->next_to_watch = i;
6566
6567 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006568 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006569 offset += size;
6570 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006571
6572 if (len) {
6573 i++;
6574 if (i == tx_ring->count)
6575 i = 0;
6576 }
Auke Kok9a799d72007-09-15 14:07:45 -07006577 }
6578
6579 for (f = 0; f < nr_frags; f++) {
6580 struct skb_frag_struct *frag;
6581
6582 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00006583 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00006584 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07006585
6586 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006587 i++;
6588 if (i == tx_ring->count)
6589 i = 0;
6590
Auke Kok9a799d72007-09-15 14:07:45 -07006591 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6592 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6593
6594 tx_buffer_info->length = size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006595 tx_buffer_info->dma = dma_map_page(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006596 frag->page,
6597 offset, size,
Nick Nunley1b507732010-04-27 13:10:27 +00006598 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +00006599 tx_buffer_info->mapped_as_page = true;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006600 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006601 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006602 tx_buffer_info->time_stamp = jiffies;
6603 tx_buffer_info->next_to_watch = i;
6604
6605 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006606 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006607 offset += size;
6608 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07006609 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006610 if (total == 0)
6611 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006612 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006613
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006614 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6615 gso_segs = skb_shinfo(skb)->gso_segs;
6616#ifdef IXGBE_FCOE
6617 /* adjust for FCoE Sequence Offload */
6618 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6619 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6620 skb_shinfo(skb)->gso_size);
6621#endif /* IXGBE_FCOE */
6622 bytecount += (gso_segs - 1) * hdr_len;
6623
6624 /* multiply data chunks by size of headers */
6625 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6626 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006627 tx_ring->tx_buffer_info[i].skb = skb;
6628 tx_ring->tx_buffer_info[first].next_to_watch = i;
6629
6630 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00006631
6632dma_error:
Emil Tantilov849c4542010-06-03 16:53:41 +00006633 e_dev_err("TX DMA map failed\n");
Alexander Duycke5a43542009-12-02 16:46:56 +00006634
6635 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6636 tx_buffer_info->dma = 0;
6637 tx_buffer_info->time_stamp = 0;
6638 tx_buffer_info->next_to_watch = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006639 if (count)
6640 count--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006641
6642 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00006643 while (count--) {
Joe Perchese8e9f692010-09-07 21:34:53 +00006644 if (i == 0)
Alexander Duycke5a43542009-12-02 16:46:56 +00006645 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006646 i--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006647 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006648 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duycke5a43542009-12-02 16:46:56 +00006649 }
6650
Anton Blancharde44d38e2010-02-03 13:12:51 +00006651 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006652}
6653
Alexander Duyck84ea2592010-11-16 19:26:49 -08006654static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
Joe Perchese8e9f692010-09-07 21:34:53 +00006655 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006656{
6657 union ixgbe_adv_tx_desc *tx_desc = NULL;
6658 struct ixgbe_tx_buffer *tx_buffer_info;
6659 u32 olinfo_status = 0, cmd_type_len = 0;
6660 unsigned int i;
6661 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6662
6663 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6664
6665 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6666
6667 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6668 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6669
6670 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6671 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6672
6673 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006674 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006675
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006676 /* use index 1 context for tso */
6677 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006678 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6679 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006680 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006681
6682 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6683 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006684 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006685
Yi Zoueacd73f2009-05-13 13:11:06 +00006686 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6687 olinfo_status |= IXGBE_ADVTXD_CC;
6688 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6689 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6690 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6691 }
6692
Auke Kok9a799d72007-09-15 14:07:45 -07006693 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6694
6695 i = tx_ring->next_to_use;
6696 while (count--) {
6697 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006698 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006699 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6700 tx_desc->read.cmd_type_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00006701 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07006702 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07006703 i++;
6704 if (i == tx_ring->count)
6705 i = 0;
6706 }
6707
6708 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6709
6710 /*
6711 * Force memory writes to complete before letting h/w
6712 * know there are new descriptors to fetch. (Only
6713 * applicable for weak-ordered memory model archs,
6714 * such as IA-64).
6715 */
6716 wmb();
6717
6718 tx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08006719 writel(i, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07006720}
6721
Alexander Duyck69830522011-01-06 14:29:58 +00006722static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6723 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006724{
Alexander Duyck69830522011-01-06 14:29:58 +00006725 struct ixgbe_q_vector *q_vector = ring->q_vector;
6726 union ixgbe_atr_hash_dword input = { .dword = 0 };
6727 union ixgbe_atr_hash_dword common = { .dword = 0 };
6728 union {
6729 unsigned char *network;
6730 struct iphdr *ipv4;
6731 struct ipv6hdr *ipv6;
6732 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006733 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006734 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006735
Alexander Duyck69830522011-01-06 14:29:58 +00006736 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6737 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006738 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006739
Alexander Duyck69830522011-01-06 14:29:58 +00006740 /* do nothing if sampling is disabled */
6741 if (!ring->atr_sample_rate)
6742 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006743
Alexander Duyck69830522011-01-06 14:29:58 +00006744 ring->atr_count++;
6745
6746 /* snag network header to get L4 type and address */
6747 hdr.network = skb_network_header(skb);
6748
6749 /* Currently only IPv4/IPv6 with TCP is supported */
6750 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6751 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6752 (protocol != __constant_htons(ETH_P_IP) ||
6753 hdr.ipv4->protocol != IPPROTO_TCP))
6754 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006755
6756 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006757
Alexander Duyck69830522011-01-06 14:29:58 +00006758 /* skip this packet since the socket is closing */
6759 if (th->fin)
6760 return;
6761
6762 /* sample on all syn packets or once every atr sample count */
6763 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6764 return;
6765
6766 /* reset sample count */
6767 ring->atr_count = 0;
6768
6769 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6770
6771 /*
6772 * src and dst are inverted, think how the receiver sees them
6773 *
6774 * The input is broken into two sections, a non-compressed section
6775 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6776 * is XORed together and stored in the compressed dword.
6777 */
6778 input.formatted.vlan_id = vlan_id;
6779
6780 /*
6781 * since src port and flex bytes occupy the same word XOR them together
6782 * and write the value to source port portion of compressed dword
6783 */
6784 if (vlan_id)
6785 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6786 else
6787 common.port.src ^= th->dest ^ protocol;
6788 common.port.dst ^= th->source;
6789
6790 if (protocol == __constant_htons(ETH_P_IP)) {
6791 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6792 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6793 } else {
6794 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6795 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6796 hdr.ipv6->saddr.s6_addr32[1] ^
6797 hdr.ipv6->saddr.s6_addr32[2] ^
6798 hdr.ipv6->saddr.s6_addr32[3] ^
6799 hdr.ipv6->daddr.s6_addr32[0] ^
6800 hdr.ipv6->daddr.s6_addr32[1] ^
6801 hdr.ipv6->daddr.s6_addr32[2] ^
6802 hdr.ipv6->daddr.s6_addr32[3];
6803 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006804
6805 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006806 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6807 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006808}
6809
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006810static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006811{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006812 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006813 /* Herbert's original patch had:
6814 * smp_mb__after_netif_stop_queue();
6815 * but since that doesn't exist yet, just open code it. */
6816 smp_mb();
6817
6818 /* We need to check again in a case another CPU has just
6819 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006820 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006821 return -EBUSY;
6822
6823 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006824 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006825 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006826 return 0;
6827}
6828
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006829static int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006830{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006831 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006832 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006833 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006834}
6835
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006836static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6837{
6838 struct ixgbe_adapter *adapter = netdev_priv(dev);
Yi Zou5f715822009-12-03 11:32:44 +00006839 int txq = smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006840#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00006841 __be16 protocol;
6842
6843 protocol = vlan_get_protocol(skb);
6844
John Fastabende5b64632011-03-08 03:44:52 +00006845 if (((protocol == htons(ETH_P_FCOE)) ||
6846 (protocol == htons(ETH_P_FIP))) &&
6847 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6848 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6849 txq += adapter->ring_feature[RING_F_FCOE].mask;
6850 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006851 }
6852#endif
6853
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006854 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6855 while (unlikely(txq >= dev->real_num_tx_queues))
6856 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006857 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006858 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006859
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006860 return skb_tx_hash(dev, skb);
6861}
6862
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006863netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006864 struct ixgbe_adapter *adapter,
6865 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006866{
Auke Kok9a799d72007-09-15 14:07:45 -07006867 unsigned int first;
6868 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08006869 u8 hdr_len = 0;
Yi Zou5f715822009-12-03 11:32:44 +00006870 int tso;
Auke Kok9a799d72007-09-15 14:07:45 -07006871 int count = 0;
6872 unsigned int f;
Hao Zheng5e09a102010-11-11 13:47:59 +00006873 __be16 protocol;
6874
6875 protocol = vlan_get_protocol(skb);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006876
Jesse Grosseab6d182010-10-20 13:56:03 +00006877 if (vlan_tx_tag_present(skb)) {
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006878 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006879 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6880 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabende5b64632011-03-08 03:44:52 +00006881 tx_flags |= tx_ring->dcb_tc << 13;
Alexander Duyck2f90b862008-11-20 20:52:10 -08006882 }
6883 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6884 tx_flags |= IXGBE_TX_FLAGS_VLAN;
John Fastabend33c66bd2010-05-18 16:00:11 +00006885 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6886 skb->priority != TC_PRIO_CONTROL) {
John Fastabende5b64632011-03-08 03:44:52 +00006887 tx_flags |= tx_ring->dcb_tc << 13;
John Fastabend2ea186a2010-02-27 03:28:24 -08006888 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6889 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006890 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006891
Yi Zou09ad1cc2009-09-03 14:56:10 +00006892#ifdef IXGBE_FCOE
John Fastabend56075a92010-07-26 20:41:31 +00006893 /* for FCoE with DCB, we force the priority to what
6894 * was specified by the switch */
6895 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
John Fastabende5b64632011-03-08 03:44:52 +00006896 (protocol == htons(ETH_P_FCOE)))
6897 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Robert Loveca77cd52010-03-24 12:45:00 +00006898#endif
6899
Yi Zoueacd73f2009-05-13 13:11:06 +00006900 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006901 if (skb_is_gso(skb) ||
6902 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00006903 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
6904 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07006905 count++;
6906
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006907 count += TXD_USE_COUNT(skb_headlen(skb));
6908 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07006909 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6910
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006911 if (ixgbe_maybe_stop_tx(tx_ring, count)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006912 tx_ring->tx_stats.tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07006913 return NETDEV_TX_BUSY;
6914 }
Auke Kok9a799d72007-09-15 14:07:45 -07006915
Auke Kok9a799d72007-09-15 14:07:45 -07006916 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00006917 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6918#ifdef IXGBE_FCOE
6919 /* setup tx offload for FCoE */
6920 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
6921 if (tso < 0) {
6922 dev_kfree_skb_any(skb);
6923 return NETDEV_TX_OK;
6924 }
6925 if (tso)
6926 tx_flags |= IXGBE_TX_FLAGS_FSO;
6927#endif /* IXGBE_FCOE */
6928 } else {
Hao Zheng5e09a102010-11-11 13:47:59 +00006929 if (protocol == htons(ETH_P_IP))
Yi Zoueacd73f2009-05-13 13:11:06 +00006930 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Hao Zheng5e09a102010-11-11 13:47:59 +00006931 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len,
6932 protocol);
Yi Zoueacd73f2009-05-13 13:11:06 +00006933 if (tso < 0) {
6934 dev_kfree_skb_any(skb);
6935 return NETDEV_TX_OK;
6936 }
6937
6938 if (tso)
6939 tx_flags |= IXGBE_TX_FLAGS_TSO;
Hao Zheng5e09a102010-11-11 13:47:59 +00006940 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags,
6941 protocol) &&
Yi Zoueacd73f2009-05-13 13:11:06 +00006942 (skb->ip_summed == CHECKSUM_PARTIAL))
6943 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006944 }
6945
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006946 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006947 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006948 /* add the ATR filter if ATR is on */
Alexander Duyck69830522011-01-06 14:29:58 +00006949 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6950 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
Alexander Duyck84ea2592010-11-16 19:26:49 -08006951 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006952 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006953
Alexander Duyck44df32c2009-03-31 21:34:23 +00006954 } else {
6955 dev_kfree_skb_any(skb);
6956 tx_ring->tx_buffer_info[first].time_stamp = 0;
6957 tx_ring->next_to_use = first;
6958 }
Auke Kok9a799d72007-09-15 14:07:45 -07006959
6960 return NETDEV_TX_OK;
6961}
6962
Alexander Duyck84418e32010-08-19 13:40:54 +00006963static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6964{
6965 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6966 struct ixgbe_ring *tx_ring;
6967
6968 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006969 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00006970}
6971
Auke Kok9a799d72007-09-15 14:07:45 -07006972/**
Auke Kok9a799d72007-09-15 14:07:45 -07006973 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6974 * @netdev: network interface device structure
6975 * @p: pointer to an address structure
6976 *
6977 * Returns 0 on success, negative on failure
6978 **/
6979static int ixgbe_set_mac(struct net_device *netdev, void *p)
6980{
6981 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006982 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07006983 struct sockaddr *addr = p;
6984
6985 if (!is_valid_ether_addr(addr->sa_data))
6986 return -EADDRNOTAVAIL;
6987
6988 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006989 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07006990
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006991 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6992 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006993
6994 return 0;
6995}
6996
Ben Hutchings6b73e102009-04-29 08:08:58 +00006997static int
6998ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6999{
7000 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7001 struct ixgbe_hw *hw = &adapter->hw;
7002 u16 value;
7003 int rc;
7004
7005 if (prtad != hw->phy.mdio.prtad)
7006 return -EINVAL;
7007 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7008 if (!rc)
7009 rc = value;
7010 return rc;
7011}
7012
7013static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7014 u16 addr, u16 value)
7015{
7016 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7017 struct ixgbe_hw *hw = &adapter->hw;
7018
7019 if (prtad != hw->phy.mdio.prtad)
7020 return -EINVAL;
7021 return hw->phy.ops.write_reg(hw, addr, devad, value);
7022}
7023
7024static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7025{
7026 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7027
7028 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7029}
7030
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007031/**
7032 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007033 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007034 * @netdev: network interface device structure
7035 *
7036 * Returns non-zero on failure
7037 **/
7038static int ixgbe_add_sanmac_netdev(struct net_device *dev)
7039{
7040 int err = 0;
7041 struct ixgbe_adapter *adapter = netdev_priv(dev);
7042 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7043
7044 if (is_valid_ether_addr(mac->san_addr)) {
7045 rtnl_lock();
7046 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7047 rtnl_unlock();
7048 }
7049 return err;
7050}
7051
7052/**
7053 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007054 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007055 * @netdev: network interface device structure
7056 *
7057 * Returns non-zero on failure
7058 **/
7059static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7060{
7061 int err = 0;
7062 struct ixgbe_adapter *adapter = netdev_priv(dev);
7063 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7064
7065 if (is_valid_ether_addr(mac->san_addr)) {
7066 rtnl_lock();
7067 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7068 rtnl_unlock();
7069 }
7070 return err;
7071}
7072
Auke Kok9a799d72007-09-15 14:07:45 -07007073#ifdef CONFIG_NET_POLL_CONTROLLER
7074/*
7075 * Polling 'interrupt' - used by things like netconsole to send skbs
7076 * without having to re-enable interrupts. It's not called while
7077 * the interrupt routine is executing.
7078 */
7079static void ixgbe_netpoll(struct net_device *netdev)
7080{
7081 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007082 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007083
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007084 /* if interface is down do nothing */
7085 if (test_bit(__IXGBE_DOWN, &adapter->state))
7086 return;
7087
Auke Kok9a799d72007-09-15 14:07:45 -07007088 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007089 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
7090 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
7091 for (i = 0; i < num_q_vectors; i++) {
7092 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7093 ixgbe_msix_clean_many(0, q_vector);
7094 }
7095 } else {
7096 ixgbe_intr(adapter->pdev->irq, netdev);
7097 }
Auke Kok9a799d72007-09-15 14:07:45 -07007098 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07007099}
7100#endif
7101
Eric Dumazetde1036b2010-10-20 23:00:04 +00007102static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7103 struct rtnl_link_stats64 *stats)
7104{
7105 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7106 int i;
7107
Eric Dumazet1a515022010-11-16 19:26:42 -08007108 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007109 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007110 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007111 u64 bytes, packets;
7112 unsigned int start;
7113
Eric Dumazet1a515022010-11-16 19:26:42 -08007114 if (ring) {
7115 do {
7116 start = u64_stats_fetch_begin_bh(&ring->syncp);
7117 packets = ring->stats.packets;
7118 bytes = ring->stats.bytes;
7119 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7120 stats->rx_packets += packets;
7121 stats->rx_bytes += bytes;
7122 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007123 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007124
7125 for (i = 0; i < adapter->num_tx_queues; i++) {
7126 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7127 u64 bytes, packets;
7128 unsigned int start;
7129
7130 if (ring) {
7131 do {
7132 start = u64_stats_fetch_begin_bh(&ring->syncp);
7133 packets = ring->stats.packets;
7134 bytes = ring->stats.bytes;
7135 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7136 stats->tx_packets += packets;
7137 stats->tx_bytes += bytes;
7138 }
7139 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007140 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007141 /* following stats updated by ixgbe_watchdog_task() */
7142 stats->multicast = netdev->stats.multicast;
7143 stats->rx_errors = netdev->stats.rx_errors;
7144 stats->rx_length_errors = netdev->stats.rx_length_errors;
7145 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7146 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7147 return stats;
7148}
7149
John Fastabend8b1c0b22011-05-03 02:26:48 +00007150/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7151 * #adapter: pointer to ixgbe_adapter
7152 * @tc: number of traffic classes currently enabled
7153 *
7154 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7155 * 802.1Q priority maps to a packet buffer that exists.
7156 */
7157static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7158{
7159 struct ixgbe_hw *hw = &adapter->hw;
7160 u32 reg, rsave;
7161 int i;
7162
7163 /* 82598 have a static priority to TC mapping that can not
7164 * be changed so no validation is needed.
7165 */
7166 if (hw->mac.type == ixgbe_mac_82598EB)
7167 return;
7168
7169 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7170 rsave = reg;
7171
7172 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7173 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7174
7175 /* If up2tc is out of bounds default to zero */
7176 if (up2tc > tc)
7177 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7178 }
7179
7180 if (reg != rsave)
7181 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7182
7183 return;
7184}
7185
7186
7187/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7188 * classes.
7189 *
7190 * @netdev: net device to configure
7191 * @tc: number of traffic classes to enable
7192 */
7193int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7194{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007195 struct ixgbe_adapter *adapter = netdev_priv(dev);
7196 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007197
7198 /* If DCB is anabled do not remove traffic classes, multiple
7199 * traffic classes are required to implement DCB
7200 */
7201 if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7202 return 0;
7203
7204 /* Hardware supports up to 8 traffic classes */
7205 if (tc > MAX_TRAFFIC_CLASS ||
7206 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7207 return -EINVAL;
7208
7209 /* Hardware has to reinitialize queues and interrupts to
7210 * match packet buffer alignment. Unfortunantly, the
7211 * hardware is not flexible enough to do this dynamically.
7212 */
7213 if (netif_running(dev))
7214 ixgbe_close(dev);
7215 ixgbe_clear_interrupt_scheme(adapter);
7216
7217 if (tc)
7218 netdev_set_num_tc(dev, tc);
7219 else
7220 netdev_reset_tc(dev);
7221
John Fastabend8b1c0b22011-05-03 02:26:48 +00007222 ixgbe_init_interrupt_scheme(adapter);
7223 ixgbe_validate_rtr(adapter, tc);
7224 if (netif_running(dev))
7225 ixgbe_open(dev);
7226
7227 return 0;
7228}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007229
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007230static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007231 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007232 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007233 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007234 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007235 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007236 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7237 .ndo_validate_addr = eth_validate_addr,
7238 .ndo_set_mac_address = ixgbe_set_mac,
7239 .ndo_change_mtu = ixgbe_change_mtu,
7240 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007241 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7242 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007243 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007244 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7245 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7246 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7247 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007248 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007249 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007250#ifdef CONFIG_NET_POLL_CONTROLLER
7251 .ndo_poll_controller = ixgbe_netpoll,
7252#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007253#ifdef IXGBE_FCOE
7254 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007255 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007256 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007257 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7258 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007259 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007260#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007261};
7262
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007263static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7264 const struct ixgbe_info *ii)
7265{
7266#ifdef CONFIG_PCI_IOV
7267 struct ixgbe_hw *hw = &adapter->hw;
7268 int err;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007269 int num_vf_macvlans, i;
7270 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007271
Greg Rose3377eba792010-12-07 08:16:45 +00007272 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007273 return;
7274
7275 /* The 82599 supports up to 64 VFs per physical function
7276 * but this implementation limits allocation to 63 so that
7277 * basic networking resources are still available to the
7278 * physical function
7279 */
7280 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7281 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7282 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7283 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007284 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007285 goto err_novfs;
7286 }
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007287
7288 num_vf_macvlans = hw->mac.num_rar_entries -
7289 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7290
7291 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7292 sizeof(struct vf_macvlans),
7293 GFP_KERNEL);
7294 if (mv_list) {
7295 /* Initialize list of VF macvlans */
7296 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7297 for (i = 0; i < num_vf_macvlans; i++) {
7298 mv_list->vf = -1;
7299 mv_list->free = true;
7300 mv_list->rar_entry = hw->mac.num_rar_entries -
7301 (i + adapter->num_vfs + 1);
7302 list_add(&mv_list->l, &adapter->vf_mvs.l);
7303 mv_list++;
7304 }
7305 }
7306
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007307 /* If call to enable VFs succeeded then allocate memory
7308 * for per VF control structures.
7309 */
7310 adapter->vfinfo =
7311 kcalloc(adapter->num_vfs,
7312 sizeof(struct vf_data_storage), GFP_KERNEL);
7313 if (adapter->vfinfo) {
7314 /* Now that we're sure SR-IOV is enabled
7315 * and memory allocated set up the mailbox parameters
7316 */
7317 ixgbe_init_mbx_params_pf(hw);
7318 memcpy(&hw->mbx.ops, ii->mbx_ops,
7319 sizeof(hw->mbx.ops));
7320
7321 /* Disable RSC when in SR-IOV mode */
7322 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7323 IXGBE_FLAG2_RSC_ENABLED);
7324 return;
7325 }
7326
7327 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007328 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7329 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007330 pci_disable_sriov(adapter->pdev);
7331
7332err_novfs:
7333 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7334 adapter->num_vfs = 0;
7335#endif /* CONFIG_PCI_IOV */
7336}
7337
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007338/**
Auke Kok9a799d72007-09-15 14:07:45 -07007339 * ixgbe_probe - Device Initialization Routine
7340 * @pdev: PCI device information struct
7341 * @ent: entry in ixgbe_pci_tbl
7342 *
7343 * Returns 0 on success, negative on failure
7344 *
7345 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7346 * The OS initialization, configuring of the adapter private structure,
7347 * and a hardware reset occur.
7348 **/
7349static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007350 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007351{
7352 struct net_device *netdev;
7353 struct ixgbe_adapter *adapter = NULL;
7354 struct ixgbe_hw *hw;
7355 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007356 static int cards_found;
7357 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007358 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007359 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007360#ifdef IXGBE_FCOE
7361 u16 device_caps;
7362#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007363 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007364
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007365 /* Catch broken hardware that put the wrong VF device ID in
7366 * the PCIe SR-IOV capability.
7367 */
7368 if (pdev->is_virtfn) {
7369 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7370 pci_name(pdev), pdev->vendor, pdev->device);
7371 return -EINVAL;
7372 }
7373
gouji-new9ce77662009-05-06 10:44:45 +00007374 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007375 if (err)
7376 return err;
7377
Nick Nunley1b507732010-04-27 13:10:27 +00007378 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7379 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007380 pci_using_dac = 1;
7381 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007382 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007383 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007384 err = dma_set_coherent_mask(&pdev->dev,
7385 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007386 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007387 dev_err(&pdev->dev,
7388 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007389 goto err_dma;
7390 }
7391 }
7392 pci_using_dac = 0;
7393 }
7394
gouji-new9ce77662009-05-06 10:44:45 +00007395 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007396 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007397 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007398 dev_err(&pdev->dev,
7399 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007400 goto err_pci_reg;
7401 }
7402
Frans Pop19d5afd2009-10-02 10:04:12 -07007403 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007404
Auke Kok9a799d72007-09-15 14:07:45 -07007405 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007406 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007407
John Fastabende901acd2011-04-26 07:26:08 +00007408#ifdef CONFIG_IXGBE_DCB
7409 indices *= MAX_TRAFFIC_CLASS;
7410#endif
7411
John Fastabendc85a2612010-02-25 23:15:21 +00007412 if (ii->mac == ixgbe_mac_82598EB)
7413 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7414 else
7415 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7416
John Fastabende901acd2011-04-26 07:26:08 +00007417#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007418 indices += min_t(unsigned int, num_possible_cpus(),
7419 IXGBE_MAX_FCOE_INDICES);
7420#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007421 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007422 if (!netdev) {
7423 err = -ENOMEM;
7424 goto err_alloc_etherdev;
7425 }
7426
Auke Kok9a799d72007-09-15 14:07:45 -07007427 SET_NETDEV_DEV(netdev, &pdev->dev);
7428
Auke Kok9a799d72007-09-15 14:07:45 -07007429 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007430 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007431
7432 adapter->netdev = netdev;
7433 adapter->pdev = pdev;
7434 hw = &adapter->hw;
7435 hw->back = adapter;
7436 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7437
Jeff Kirsher05857982008-09-11 19:57:00 -07007438 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007439 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007440 if (!hw->hw_addr) {
7441 err = -EIO;
7442 goto err_ioremap;
7443 }
7444
7445 for (i = 1; i <= 5; i++) {
7446 if (pci_resource_len(pdev, i) == 0)
7447 continue;
7448 }
7449
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007450 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007451 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007452 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007453 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007454
Auke Kok9a799d72007-09-15 14:07:45 -07007455 adapter->bd_number = cards_found;
7456
Auke Kok9a799d72007-09-15 14:07:45 -07007457 /* Setup hw api */
7458 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007459 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007460
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007461 /* EEPROM */
7462 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7463 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7464 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7465 if (!(eec & (1 << 8)))
7466 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7467
7468 /* PHY */
7469 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007470 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007471 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7472 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7473 hw->phy.mdio.mmds = 0;
7474 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7475 hw->phy.mdio.dev = netdev;
7476 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7477 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007478
Don Skidmore8ca783a2009-05-26 20:40:47 -07007479 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007480
7481 /* setup the private structure */
7482 err = ixgbe_sw_init(adapter);
7483 if (err)
7484 goto err_sw_init;
7485
Don Skidmoree86bff02010-02-11 04:14:08 +00007486 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007487 switch (adapter->hw.mac.type) {
7488 case ixgbe_mac_82599EB:
7489 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007490 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007491 break;
7492 default:
7493 break;
7494 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007495
Don Skidmorebf069c92009-05-07 10:39:54 +00007496 /*
7497 * If there is a fan on this device and it has failed log the
7498 * failure.
7499 */
7500 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7501 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7502 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007503 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007504 }
7505
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007506 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007507 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007508 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007509 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007510 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7511 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007512 err = 0;
7513 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007514 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007515 "module type was detected.\n");
7516 e_dev_err("Reload the driver after installing a supported "
7517 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007518 goto err_sw_init;
7519 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007520 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007521 goto err_sw_init;
7522 }
7523
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007524 ixgbe_probe_vf(adapter, ii);
7525
Emil Tantilov396e7992010-07-01 20:05:12 +00007526 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007527 NETIF_F_IP_CSUM |
7528 NETIF_F_HW_VLAN_TX |
7529 NETIF_F_HW_VLAN_RX |
7530 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07007531
Jesse Brandeburge9990a92008-08-26 04:27:24 -07007532 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007533 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07007534 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08007535 netdev->features |= NETIF_F_GRO;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007536 netdev->features |= NETIF_F_RXHASH;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007537
Don Skidmore58be7662011-04-12 09:42:11 +00007538 switch (adapter->hw.mac.type) {
7539 case ixgbe_mac_82599EB:
7540 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007541 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore58be7662011-04-12 09:42:11 +00007542 break;
7543 default:
7544 break;
7545 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007546
Jeff Kirsherad31c402008-06-05 04:05:30 -07007547 netdev->vlan_features |= NETIF_F_TSO;
7548 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007549 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007550 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007551 netdev->vlan_features |= NETIF_F_SG;
7552
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007553 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7554 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7555 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007556
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007557#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007558 netdev->dcbnl_ops = &dcbnl_ops;
7559#endif
7560
Yi Zoueacd73f2009-05-13 13:11:06 +00007561#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007562 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007563 if (hw->mac.ops.get_device_caps) {
7564 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007565 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7566 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007567 }
7568 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007569 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7570 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7571 netdev->vlan_features |= NETIF_F_FSO;
7572 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7573 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007574#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007575 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007576 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007577 netdev->vlan_features |= NETIF_F_HIGHDMA;
7578 }
Auke Kok9a799d72007-09-15 14:07:45 -07007579
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007580 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007581 netdev->features |= NETIF_F_LRO;
7582
Auke Kok9a799d72007-09-15 14:07:45 -07007583 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007584 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007585 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007586 err = -EIO;
7587 goto err_eeprom;
7588 }
7589
7590 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7591 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7592
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007593 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007594 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007595 err = -EIO;
7596 goto err_eeprom;
7597 }
7598
Don Skidmorec6ecf392010-12-03 03:31:51 +00007599 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7600 if (hw->mac.ops.disable_tx_laser &&
7601 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007602 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007603 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007604 hw->mac.ops.disable_tx_laser(hw);
7605
Alexander Duyck70864002011-04-27 09:13:56 +00007606 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7607 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007608
Alexander Duyck70864002011-04-27 09:13:56 +00007609 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7610 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007611
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007612 err = ixgbe_init_interrupt_scheme(adapter);
7613 if (err)
7614 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007615
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007616 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7617 netdev->features &= ~NETIF_F_RXHASH;
7618
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007619 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007620 case IXGBE_DEV_ID_82599_SFP:
7621 /* Only this subdevice supports WOL */
7622 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
7623 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7624 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7625 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007626 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7627 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007628 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7629 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7630 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7631 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007632 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00007633 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
Joe Perchese8e9f692010-09-07 21:34:53 +00007634 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007635 break;
7636 default:
7637 adapter->wol = 0;
7638 break;
7639 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007640 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7641
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007642 /* pick up the PCI bus settings for reporting later */
7643 hw->mac.ops.get_bus_info(hw);
7644
Auke Kok9a799d72007-09-15 14:07:45 -07007645 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007646 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007647 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7648 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007649 "Unknown"),
7650 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7651 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7652 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7653 "Unknown"),
7654 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007655
7656 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7657 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007658 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007659 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007660 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007661 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007662 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007663 else
Don Skidmore289700db2010-12-03 03:32:58 +00007664 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7665 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007666
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007667 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007668 e_dev_warn("PCI-Express bandwidth available for this card is "
7669 "not sufficient for optimal performance.\n");
7670 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7671 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007672 }
7673
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007674 /* save off EEPROM version number */
7675 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7676
Auke Kok9a799d72007-09-15 14:07:45 -07007677 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007678 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007679
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007680 if (err == IXGBE_ERR_EEPROM_VERSION) {
7681 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007682 e_dev_warn("This device is a pre-production adapter/LOM. "
7683 "Please be aware there may be issues associated "
7684 "with your hardware. If you are experiencing "
7685 "problems please contact your Intel or hardware "
7686 "representative who provided you with this "
7687 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007688 }
Auke Kok9a799d72007-09-15 14:07:45 -07007689 strcpy(netdev->name, "eth%d");
7690 err = register_netdev(netdev);
7691 if (err)
7692 goto err_register;
7693
Jesse Brandeburg54386462009-04-17 20:44:27 +00007694 /* carrier off reporting is important to ethtool even BEFORE open */
7695 netif_carrier_off(netdev);
7696
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007697#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007698 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007699 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007700 ixgbe_setup_dca(adapter);
7701 }
7702#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007703 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007704 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007705 for (i = 0; i < adapter->num_vfs; i++)
7706 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7707 }
7708
Emil Tantilov9612de92011-05-07 07:40:20 +00007709 /* Inform firmware of driver version */
7710 if (hw->mac.ops.set_fw_drv_ver)
Don Skidmorea38a1042011-05-20 03:05:14 +00007711 hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD,
7712 FW_CEM_UNUSED_VER);
Emil Tantilov9612de92011-05-07 07:40:20 +00007713
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007714 /* add san mac addr to netdev */
7715 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007716
Emil Tantilov849c4542010-06-03 16:53:41 +00007717 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007718 cards_found++;
7719 return 0;
7720
7721err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007722 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007723 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007724err_sw_init:
7725err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007726 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7727 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007728 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007729 iounmap(hw->hw_addr);
7730err_ioremap:
7731 free_netdev(netdev);
7732err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007733 pci_release_selected_regions(pdev,
7734 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007735err_pci_reg:
7736err_dma:
7737 pci_disable_device(pdev);
7738 return err;
7739}
7740
7741/**
7742 * ixgbe_remove - Device Removal Routine
7743 * @pdev: PCI device information struct
7744 *
7745 * ixgbe_remove is called by the PCI subsystem to alert the driver
7746 * that it should release a PCI device. The could be caused by a
7747 * Hot-Plug event, or because the driver is going to be removed from
7748 * memory.
7749 **/
7750static void __devexit ixgbe_remove(struct pci_dev *pdev)
7751{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007752 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7753 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007754
7755 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007756 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007757
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007758#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007759 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7760 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7761 dca_remove_requester(&pdev->dev);
7762 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7763 }
7764
7765#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007766#ifdef IXGBE_FCOE
7767 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7768 ixgbe_cleanup_fcoe(adapter);
7769
7770#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007771
7772 /* remove the added san mac */
7773 ixgbe_del_sanmac_netdev(netdev);
7774
Donald Skidmorec4900be2008-11-20 21:11:42 -08007775 if (netdev->reg_state == NETREG_REGISTERED)
7776 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007777
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007778 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7779 ixgbe_disable_sriov(adapter);
7780
Alexander Duyck7a921c92009-05-06 10:43:28 +00007781 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007782
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007783 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007784
7785 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007786 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007787 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007788
Emil Tantilov849c4542010-06-03 16:53:41 +00007789 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007790
Auke Kok9a799d72007-09-15 14:07:45 -07007791 free_netdev(netdev);
7792
Frans Pop19d5afd2009-10-02 10:04:12 -07007793 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007794
Auke Kok9a799d72007-09-15 14:07:45 -07007795 pci_disable_device(pdev);
7796}
7797
7798/**
7799 * ixgbe_io_error_detected - called when PCI error is detected
7800 * @pdev: Pointer to PCI device
7801 * @state: The current pci connection state
7802 *
7803 * This function is called after a PCI bus error affecting
7804 * this device has been detected.
7805 */
7806static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007807 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007808{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007809 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7810 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007811
7812 netif_device_detach(netdev);
7813
Breno Leitao3044b8d2009-05-06 10:44:26 +00007814 if (state == pci_channel_io_perm_failure)
7815 return PCI_ERS_RESULT_DISCONNECT;
7816
Auke Kok9a799d72007-09-15 14:07:45 -07007817 if (netif_running(netdev))
7818 ixgbe_down(adapter);
7819 pci_disable_device(pdev);
7820
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007821 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007822 return PCI_ERS_RESULT_NEED_RESET;
7823}
7824
7825/**
7826 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7827 * @pdev: Pointer to PCI device
7828 *
7829 * Restart the card from scratch, as if from a cold-boot.
7830 */
7831static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7832{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007833 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007834 pci_ers_result_t result;
7835 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007836
gouji-new9ce77662009-05-06 10:44:45 +00007837 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007838 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007839 result = PCI_ERS_RESULT_DISCONNECT;
7840 } else {
7841 pci_set_master(pdev);
7842 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007843 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007844
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007845 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007846
7847 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007848 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007849 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007850 }
Auke Kok9a799d72007-09-15 14:07:45 -07007851
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007852 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7853 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007854 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7855 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007856 /* non-fatal, continue */
7857 }
Auke Kok9a799d72007-09-15 14:07:45 -07007858
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007859 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007860}
7861
7862/**
7863 * ixgbe_io_resume - called when traffic can start flowing again.
7864 * @pdev: Pointer to PCI device
7865 *
7866 * This callback is called when the error recovery driver tells us that
7867 * its OK to resume normal operation.
7868 */
7869static void ixgbe_io_resume(struct pci_dev *pdev)
7870{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007871 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7872 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007873
7874 if (netif_running(netdev)) {
7875 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007876 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007877 return;
7878 }
7879 }
7880
7881 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007882}
7883
7884static struct pci_error_handlers ixgbe_err_handler = {
7885 .error_detected = ixgbe_io_error_detected,
7886 .slot_reset = ixgbe_io_slot_reset,
7887 .resume = ixgbe_io_resume,
7888};
7889
7890static struct pci_driver ixgbe_driver = {
7891 .name = ixgbe_driver_name,
7892 .id_table = ixgbe_pci_tbl,
7893 .probe = ixgbe_probe,
7894 .remove = __devexit_p(ixgbe_remove),
7895#ifdef CONFIG_PM
7896 .suspend = ixgbe_suspend,
7897 .resume = ixgbe_resume,
7898#endif
7899 .shutdown = ixgbe_shutdown,
7900 .err_handler = &ixgbe_err_handler
7901};
7902
7903/**
7904 * ixgbe_init_module - Driver Registration Routine
7905 *
7906 * ixgbe_init_module is the first routine called when the driver is
7907 * loaded. All it does is register with the PCI subsystem.
7908 **/
7909static int __init ixgbe_init_module(void)
7910{
7911 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007912 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007913 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007914
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007915#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007916 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007917#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007918
Auke Kok9a799d72007-09-15 14:07:45 -07007919 ret = pci_register_driver(&ixgbe_driver);
7920 return ret;
7921}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007922
Auke Kok9a799d72007-09-15 14:07:45 -07007923module_init(ixgbe_init_module);
7924
7925/**
7926 * ixgbe_exit_module - Driver Exit Cleanup Routine
7927 *
7928 * ixgbe_exit_module is called just before the driver is removed
7929 * from memory.
7930 **/
7931static void __exit ixgbe_exit_module(void)
7932{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007933#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007934 dca_unregister_notify(&dca_notifier);
7935#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007936 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007937 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007938}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007939
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007940#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007941static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007942 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007943{
7944 int ret_val;
7945
7946 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007947 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007948
7949 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7950}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007951
Alexander Duyckb4533682009-03-31 21:32:42 +00007952#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007953
Auke Kok9a799d72007-09-15 14:07:45 -07007954module_exit(ixgbe_exit_module);
7955
7956/* ixgbe_main.c */