blob: fc8cfad4ac9b9246828526c8f36f5c9ac718e36d [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore94971822012-01-06 03:24:16 +00004 Copyright(c) 1999 - 2012 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>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000045#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/if_vlan.h>
John Fastabend815cccb2012-10-24 08:13:09 +000047#include <linux/if_bridge.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040048#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000049#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070050
51#include "ixgbe.h"
52#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000053#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000054#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070055
56char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070057static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000058 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000059#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000060char ixgbe_default_device_descr[] =
61 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000062#else
63static char ixgbe_default_device_descr[] =
64 "Intel(R) 10 Gigabit Network Connection";
65#endif
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000066#define MAJ 3
Don Skidmoreeef45602012-04-28 03:29:22 +000067#define MIN 9
68#define BUILD 15
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000069#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000070 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070071const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000072static const char ixgbe_copyright[] =
Don Skidmore94971822012-01-06 03:24:16 +000073 "Copyright (c) 1999-2012 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070074
75static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070076 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000077 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080078 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070079};
80
81/* ixgbe_pci_tbl - PCI Device ID Table
82 *
83 * Wildcard entries (PCI_ANY_ID) should come last
84 * Last entry must be all 0s
85 *
86 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
87 * Class, Class Mask, private data (not used) }
88 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000089static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000090 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Auke Kok9a799d72007-09-15 14:07:45 -0700119 /* required last entry */
120 {0, }
121};
122MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
123
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400124#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800125static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000126 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800127static struct notifier_block dca_notifier = {
128 .notifier_call = ixgbe_notify_dca,
129 .next = NULL,
130 .priority = 0
131};
132#endif
133
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000134#ifdef CONFIG_PCI_IOV
135static unsigned int max_vfs;
136module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000137MODULE_PARM_DESC(max_vfs,
Greg Rose6b42a9c2012-04-17 04:29:29 +0000138 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000139#endif /* CONFIG_PCI_IOV */
140
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000141static unsigned int allow_unsupported_sfp;
142module_param(allow_unsupported_sfp, uint, 0);
143MODULE_PARM_DESC(allow_unsupported_sfp,
144 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
145
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000146#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
147static int debug = -1;
148module_param(debug, int, 0);
149MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
150
Auke Kok9a799d72007-09-15 14:07:45 -0700151MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
152MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
153MODULE_LICENSE("GPL");
154MODULE_VERSION(DRV_VERSION);
155
Alexander Duyck70864002011-04-27 09:13:56 +0000156static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
157{
158 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
159 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
160 schedule_work(&adapter->service_task);
161}
162
163static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
164{
165 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
166
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000167 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000168 smp_mb__before_clear_bit();
169 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
170}
171
Taku Izumidcd79ae2010-04-27 14:39:53 +0000172struct ixgbe_reg_info {
173 u32 ofs;
174 char *name;
175};
176
177static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
178
179 /* General Registers */
180 {IXGBE_CTRL, "CTRL"},
181 {IXGBE_STATUS, "STATUS"},
182 {IXGBE_CTRL_EXT, "CTRL_EXT"},
183
184 /* Interrupt Registers */
185 {IXGBE_EICR, "EICR"},
186
187 /* RX Registers */
188 {IXGBE_SRRCTL(0), "SRRCTL"},
189 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
190 {IXGBE_RDLEN(0), "RDLEN"},
191 {IXGBE_RDH(0), "RDH"},
192 {IXGBE_RDT(0), "RDT"},
193 {IXGBE_RXDCTL(0), "RXDCTL"},
194 {IXGBE_RDBAL(0), "RDBAL"},
195 {IXGBE_RDBAH(0), "RDBAH"},
196
197 /* TX Registers */
198 {IXGBE_TDBAL(0), "TDBAL"},
199 {IXGBE_TDBAH(0), "TDBAH"},
200 {IXGBE_TDLEN(0), "TDLEN"},
201 {IXGBE_TDH(0), "TDH"},
202 {IXGBE_TDT(0), "TDT"},
203 {IXGBE_TXDCTL(0), "TXDCTL"},
204
205 /* List Terminator */
206 {}
207};
208
209
210/*
211 * ixgbe_regdump - register printout routine
212 */
213static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
214{
215 int i = 0, j = 0;
216 char rname[16];
217 u32 regs[64];
218
219 switch (reginfo->ofs) {
220 case IXGBE_SRRCTL(0):
221 for (i = 0; i < 64; i++)
222 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
223 break;
224 case IXGBE_DCA_RXCTRL(0):
225 for (i = 0; i < 64; i++)
226 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
227 break;
228 case IXGBE_RDLEN(0):
229 for (i = 0; i < 64; i++)
230 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
231 break;
232 case IXGBE_RDH(0):
233 for (i = 0; i < 64; i++)
234 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
235 break;
236 case IXGBE_RDT(0):
237 for (i = 0; i < 64; i++)
238 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
239 break;
240 case IXGBE_RXDCTL(0):
241 for (i = 0; i < 64; i++)
242 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
243 break;
244 case IXGBE_RDBAL(0):
245 for (i = 0; i < 64; i++)
246 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
247 break;
248 case IXGBE_RDBAH(0):
249 for (i = 0; i < 64; i++)
250 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
251 break;
252 case IXGBE_TDBAL(0):
253 for (i = 0; i < 64; i++)
254 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
255 break;
256 case IXGBE_TDBAH(0):
257 for (i = 0; i < 64; i++)
258 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
259 break;
260 case IXGBE_TDLEN(0):
261 for (i = 0; i < 64; i++)
262 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
263 break;
264 case IXGBE_TDH(0):
265 for (i = 0; i < 64; i++)
266 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
267 break;
268 case IXGBE_TDT(0):
269 for (i = 0; i < 64; i++)
270 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
271 break;
272 case IXGBE_TXDCTL(0):
273 for (i = 0; i < 64; i++)
274 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
275 break;
276 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000277 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000278 IXGBE_READ_REG(hw, reginfo->ofs));
279 return;
280 }
281
282 for (i = 0; i < 8; i++) {
283 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000284 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000285 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000286 pr_cont(" %08x", regs[i*8+j]);
287 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000288 }
289
290}
291
292/*
293 * ixgbe_dump - Print registers, tx-rings and rx-rings
294 */
295static void ixgbe_dump(struct ixgbe_adapter *adapter)
296{
297 struct net_device *netdev = adapter->netdev;
298 struct ixgbe_hw *hw = &adapter->hw;
299 struct ixgbe_reg_info *reginfo;
300 int n = 0;
301 struct ixgbe_ring *tx_ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000302 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000303 union ixgbe_adv_tx_desc *tx_desc;
304 struct my_u0 { u64 a; u64 b; } *u0;
305 struct ixgbe_ring *rx_ring;
306 union ixgbe_adv_rx_desc *rx_desc;
307 struct ixgbe_rx_buffer *rx_buffer_info;
308 u32 staterr;
309 int i = 0;
310
311 if (!netif_msg_hw(adapter))
312 return;
313
314 /* Print netdevice Info */
315 if (netdev) {
316 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000317 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000318 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000319 pr_info("%-15s %016lX %016lX %016lX\n",
320 netdev->name,
321 netdev->state,
322 netdev->trans_start,
323 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000324 }
325
326 /* Print Registers */
327 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000328 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000329 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
330 reginfo->name; reginfo++) {
331 ixgbe_regdump(hw, reginfo);
332 }
333
334 /* Print TX Ring Summary */
335 if (!netdev || !netif_running(netdev))
336 goto exit;
337
338 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000339 pr_info(" %s %s %s %s\n",
340 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
341 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000342 for (n = 0; n < adapter->num_tx_queues; n++) {
343 tx_ring = adapter->tx_ring[n];
Alexander Duyck729739b2012-02-08 07:51:06 +0000344 tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Josh Hay8ad88e32012-09-26 05:59:41 +0000345 pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000346 n, tx_ring->next_to_use, tx_ring->next_to_clean,
Alexander Duyck729739b2012-02-08 07:51:06 +0000347 (u64)dma_unmap_addr(tx_buffer, dma),
348 dma_unmap_len(tx_buffer, len),
349 tx_buffer->next_to_watch,
350 (u64)tx_buffer->time_stamp);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000351 }
352
353 /* Print TX Rings */
354 if (!netif_msg_tx_done(adapter))
355 goto rx_ring_summary;
356
357 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
358
359 /* Transmit Descriptor Formats
360 *
Josh Hay39ac8682012-09-26 05:59:36 +0000361 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000362 * +--------------------------------------------------------------+
363 * 0 | Buffer Address [63:0] |
364 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000365 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000366 * +--------------------------------------------------------------+
367 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000368 *
369 * 82598 Advanced Transmit Descriptor (Write-Back Format)
370 * +--------------------------------------------------------------+
371 * 0 | RSV [63:0] |
372 * +--------------------------------------------------------------+
373 * 8 | RSV | STA | NXTSEQ |
374 * +--------------------------------------------------------------+
375 * 63 36 35 32 31 0
376 *
377 * 82599+ Advanced Transmit Descriptor
378 * +--------------------------------------------------------------+
379 * 0 | Buffer Address [63:0] |
380 * +--------------------------------------------------------------+
381 * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
382 * +--------------------------------------------------------------+
383 * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
384 *
385 * 82599+ Advanced Transmit Descriptor (Write-Back Format)
386 * +--------------------------------------------------------------+
387 * 0 | RSV [63:0] |
388 * +--------------------------------------------------------------+
389 * 8 | RSV | STA | RSV |
390 * +--------------------------------------------------------------+
391 * 63 36 35 32 31 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000392 */
393
394 for (n = 0; n < adapter->num_tx_queues; n++) {
395 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000396 pr_info("------------------------------------\n");
397 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
398 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000399 pr_info("%s%s %s %s %s %s\n",
400 "T [desc] [address 63:0 ] ",
401 "[PlPOIdStDDt Ln] [bi->dma ] ",
402 "leng", "ntw", "timestamp", "bi->skb");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000403
404 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000405 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000406 tx_buffer = &tx_ring->tx_buffer_info[i];
Taku Izumidcd79ae2010-04-27 14:39:53 +0000407 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000408 if (dma_unmap_len(tx_buffer, len) > 0) {
409 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
410 i,
411 le64_to_cpu(u0->a),
412 le64_to_cpu(u0->b),
413 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000414 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000415 tx_buffer->next_to_watch,
416 (u64)tx_buffer->time_stamp,
417 tx_buffer->skb);
418 if (i == tx_ring->next_to_use &&
419 i == tx_ring->next_to_clean)
420 pr_cont(" NTC/U\n");
421 else if (i == tx_ring->next_to_use)
422 pr_cont(" NTU\n");
423 else if (i == tx_ring->next_to_clean)
424 pr_cont(" NTC\n");
425 else
426 pr_cont("\n");
427
428 if (netif_msg_pktdata(adapter) &&
429 tx_buffer->skb)
430 print_hex_dump(KERN_INFO, "",
431 DUMP_PREFIX_ADDRESS, 16, 1,
432 tx_buffer->skb->data,
433 dma_unmap_len(tx_buffer, len),
434 true);
435 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000436 }
437 }
438
439 /* Print RX Rings Summary */
440rx_ring_summary:
441 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000442 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000443 for (n = 0; n < adapter->num_rx_queues; n++) {
444 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000445 pr_info("%5d %5X %5X\n",
446 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000447 }
448
449 /* Print RX Rings */
450 if (!netif_msg_rx_status(adapter))
451 goto exit;
452
453 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
454
Josh Hay39ac8682012-09-26 05:59:36 +0000455 /* Receive Descriptor Formats
456 *
457 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000458 * 63 1 0
459 * +-----------------------------------------------------+
460 * 0 | Packet Buffer Address [63:1] |A0/NSE|
461 * +----------------------------------------------+------+
462 * 8 | Header Buffer Address [63:1] | DD |
463 * +-----------------------------------------------------+
464 *
465 *
Josh Hay39ac8682012-09-26 05:59:36 +0000466 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000467 *
468 * 63 48 47 32 31 30 21 20 16 15 4 3 0
469 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000470 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
471 * | Packet | IP | | | | Type | Type |
472 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000473 * +------------------------------------------------------+
474 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
475 * +------------------------------------------------------+
476 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000477 *
478 * 82599+ Advanced Receive Descriptor (Read) Format
479 * 63 1 0
480 * +-----------------------------------------------------+
481 * 0 | Packet Buffer Address [63:1] |A0/NSE|
482 * +----------------------------------------------+------+
483 * 8 | Header Buffer Address [63:1] | DD |
484 * +-----------------------------------------------------+
485 *
486 *
487 * 82599+ Advanced Receive Descriptor (Write-Back) Format
488 *
489 * 63 48 47 32 31 30 21 20 17 16 4 3 0
490 * +------------------------------------------------------+
491 * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
492 * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
493 * |/ Flow Dir Flt ID | | | | | |
494 * +------------------------------------------------------+
495 * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
496 * +------------------------------------------------------+
497 * 63 48 47 32 31 20 19 0
Taku Izumidcd79ae2010-04-27 14:39:53 +0000498 */
Josh Hay39ac8682012-09-26 05:59:36 +0000499
Taku Izumidcd79ae2010-04-27 14:39:53 +0000500 for (n = 0; n < adapter->num_rx_queues; n++) {
501 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000502 pr_info("------------------------------------\n");
503 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
504 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000505 pr_info("%s%s%s",
506 "R [desc] [ PktBuf A0] ",
507 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000508 "<-- Adv Rx Read format\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000509 pr_info("%s%s%s",
510 "RWB[desc] [PcsmIpSHl PtRs] ",
511 "[vl er S cks ln] ---------------- [bi->skb ] ",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000512 "<-- Adv Rx Write-Back format\n");
513
514 for (i = 0; i < rx_ring->count; i++) {
515 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000516 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000517 u0 = (struct my_u0 *)rx_desc;
518 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
519 if (staterr & IXGBE_RXD_STAT_DD) {
520 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000521 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000522 "%016llX ---------------- %p", i,
523 le64_to_cpu(u0->a),
524 le64_to_cpu(u0->b),
525 rx_buffer_info->skb);
526 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000527 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000528 "%016llX %016llX %p", i,
529 le64_to_cpu(u0->a),
530 le64_to_cpu(u0->b),
531 (u64)rx_buffer_info->dma,
532 rx_buffer_info->skb);
533
Emil Tantilov9c50c032012-07-26 01:21:24 +0000534 if (netif_msg_pktdata(adapter) &&
535 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000536 print_hex_dump(KERN_INFO, "",
537 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000538 page_address(rx_buffer_info->page) +
539 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000540 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000541 }
542 }
543
544 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000545 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000546 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000547 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000548 else
Joe Perchesc7689572010-09-07 21:35:17 +0000549 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000550
551 }
552 }
553
554exit:
555 return;
556}
557
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800558static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
559{
560 u32 ctrl_ext;
561
562 /* Let firmware take over control of h/w */
563 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
564 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000565 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800566}
567
568static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
569{
570 u32 ctrl_ext;
571
572 /* Let firmware know the driver has taken over */
573 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
574 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000575 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800576}
Auke Kok9a799d72007-09-15 14:07:45 -0700577
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000578/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000579 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
580 * @adapter: pointer to adapter struct
581 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
582 * @queue: queue to map the corresponding interrupt to
583 * @msix_vector: the vector to map to the corresponding queue
584 *
585 */
586static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000587 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700588{
589 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000590 struct ixgbe_hw *hw = &adapter->hw;
591 switch (hw->mac.type) {
592 case ixgbe_mac_82598EB:
593 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
594 if (direction == -1)
595 direction = 0;
596 index = (((direction * 64) + queue) >> 2) & 0x1F;
597 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
598 ivar &= ~(0xFF << (8 * (queue & 0x3)));
599 ivar |= (msix_vector << (8 * (queue & 0x3)));
600 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
601 break;
602 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800603 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000604 if (direction == -1) {
605 /* other causes */
606 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
607 index = ((queue & 1) * 8);
608 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
609 ivar &= ~(0xFF << index);
610 ivar |= (msix_vector << index);
611 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
612 break;
613 } else {
614 /* tx or rx causes */
615 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
616 index = ((16 * (queue & 1)) + (8 * direction));
617 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
618 ivar &= ~(0xFF << index);
619 ivar |= (msix_vector << index);
620 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
621 break;
622 }
623 default:
624 break;
625 }
Auke Kok9a799d72007-09-15 14:07:45 -0700626}
627
Alexander Duyckfe49f042009-06-04 16:00:09 +0000628static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000629 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000630{
631 u32 mask;
632
Alexander Duyckbd508172010-11-16 19:27:03 -0800633 switch (adapter->hw.mac.type) {
634 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000635 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
636 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800637 break;
638 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800639 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000640 mask = (qmask & 0xFFFFFFFF);
641 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
642 mask = (qmask >> 32);
643 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800644 break;
645 default:
646 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000647 }
648}
649
Alexander Duyck729739b2012-02-08 07:51:06 +0000650void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
651 struct ixgbe_tx_buffer *tx_buffer)
Alexander Duyckd3d00232011-07-15 02:31:25 +0000652{
Alexander Duyck729739b2012-02-08 07:51:06 +0000653 if (tx_buffer->skb) {
654 dev_kfree_skb_any(tx_buffer->skb);
655 if (dma_unmap_len(tx_buffer, len))
Alexander Duyckd3d00232011-07-15 02:31:25 +0000656 dma_unmap_single(ring->dev,
Alexander Duyck729739b2012-02-08 07:51:06 +0000657 dma_unmap_addr(tx_buffer, dma),
658 dma_unmap_len(tx_buffer, len),
659 DMA_TO_DEVICE);
660 } else if (dma_unmap_len(tx_buffer, len)) {
661 dma_unmap_page(ring->dev,
662 dma_unmap_addr(tx_buffer, dma),
663 dma_unmap_len(tx_buffer, len),
664 DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000665 }
Alexander Duyck729739b2012-02-08 07:51:06 +0000666 tx_buffer->next_to_watch = NULL;
667 tx_buffer->skb = NULL;
668 dma_unmap_len_set(tx_buffer, len, 0);
669 /* tx_buffer must be completely set up in the transmit path */
Auke Kok9a799d72007-09-15 14:07:45 -0700670}
671
Alexander Duyck943561d2012-05-09 22:14:44 -0700672static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
673{
674 struct ixgbe_hw *hw = &adapter->hw;
675 struct ixgbe_hw_stats *hwstats = &adapter->stats;
676 int i;
677 u32 data;
678
679 if ((hw->fc.current_mode != ixgbe_fc_full) &&
680 (hw->fc.current_mode != ixgbe_fc_rx_pause))
681 return;
682
683 switch (hw->mac.type) {
684 case ixgbe_mac_82598EB:
685 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
686 break;
687 default:
688 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
689 }
690 hwstats->lxoffrxc += data;
691
692 /* refill credits (no tx hang) if we received xoff */
693 if (!data)
694 return;
695
696 for (i = 0; i < adapter->num_tx_queues; i++)
697 clear_bit(__IXGBE_HANG_CHECK_ARMED,
698 &adapter->tx_ring[i]->state);
699}
700
John Fastabendc84d3242010-11-16 19:27:12 -0800701static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700702{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700703 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800704 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800705 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000706 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800707 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700708 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700709
Alexander Duyck943561d2012-05-09 22:14:44 -0700710 if (adapter->ixgbe_ieee_pfc)
711 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800712
Alexander Duyck943561d2012-05-09 22:14:44 -0700713 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
714 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800715 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700716 }
John Fastabendc84d3242010-11-16 19:27:12 -0800717
718 /* update stats for each tc, only valid with PFC enabled */
719 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000720 u32 pxoffrxc;
721
John Fastabendc84d3242010-11-16 19:27:12 -0800722 switch (hw->mac.type) {
723 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000724 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800725 break;
726 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000727 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800728 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000729 hwstats->pxoffrxc[i] += pxoffrxc;
730 /* Get the TC for given UP */
731 tc = netdev_get_prio_tc_map(adapter->netdev, i);
732 xoff[tc] += pxoffrxc;
Auke Kok9a799d72007-09-15 14:07:45 -0700733 }
734
John Fastabendc84d3242010-11-16 19:27:12 -0800735 /* disarm tx queues that have received xoff frames */
736 for (i = 0; i < adapter->num_tx_queues; i++) {
737 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendc84d3242010-11-16 19:27:12 -0800738
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000739 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800740 if (xoff[tc])
741 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
742 }
743}
744
745static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
746{
Alexander Duyck7d7ce682012-02-08 07:50:51 +0000747 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -0800748}
749
750static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
751{
752 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
753 struct ixgbe_hw *hw = &adapter->hw;
754
755 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
756 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
757
758 if (head != tail)
759 return (head < tail) ?
760 tail - head : (tail + ring->count - head);
761
762 return 0;
763}
764
765static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
766{
767 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
768 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
769 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
770 bool ret = false;
771
772 clear_check_for_tx_hang(tx_ring);
773
774 /*
775 * Check for a hung queue, but be thorough. This verifies
776 * that a transmit has been completed since the previous
777 * check AND there is at least one packet pending. The
778 * ARMED bit is set to indicate a potential hang. The
779 * bit is cleared if a pause frame is received to remove
780 * false hang detection due to PFC or 802.3x frames. By
781 * requiring this to fail twice we avoid races with
782 * pfc clearing the ARMED bit and conditions where we
783 * run the check_tx_hang logic with a transmit completion
784 * pending but without time to complete it yet.
785 */
786 if ((tx_done_old == tx_done) && tx_pending) {
787 /* make sure it is true for two checks in a row */
788 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
789 &tx_ring->state);
790 } else {
791 /* update completed stats and continue */
792 tx_ring->tx_stats.tx_done_old = tx_done;
793 /* reset the countdown */
794 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
795 }
796
797 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700798}
799
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000800/**
801 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
802 * @adapter: driver private struct
803 **/
804static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
805{
806
807 /* Do the reset outside of interrupt context */
808 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
809 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
810 ixgbe_service_event_schedule(adapter);
811 }
812}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700813
Auke Kok9a799d72007-09-15 14:07:45 -0700814/**
815 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000816 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700817 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700818 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000819static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000820 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700821{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000822 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000823 struct ixgbe_tx_buffer *tx_buffer;
824 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700825 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000826 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +0000827 unsigned int i = tx_ring->next_to_clean;
828
829 if (test_bit(__IXGBE_DOWN, &adapter->state))
830 return true;
Auke Kok9a799d72007-09-15 14:07:45 -0700831
Alexander Duyckd3d00232011-07-15 02:31:25 +0000832 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000833 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +0000834 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800835
Alexander Duyck729739b2012-02-08 07:51:06 +0000836 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000837 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700838
Alexander Duyckd3d00232011-07-15 02:31:25 +0000839 /* if next_to_watch is not set then there is no work pending */
840 if (!eop_desc)
841 break;
842
Alexander Duyck7f83a9e2012-02-08 07:49:23 +0000843 /* prevent any other reads prior to eop_desc */
844 rmb();
845
Alexander Duyckd3d00232011-07-15 02:31:25 +0000846 /* if DD is not set pending work has not been completed */
847 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
848 break;
849
Alexander Duyckd3d00232011-07-15 02:31:25 +0000850 /* clear next_to_watch to prevent false hangs */
851 tx_buffer->next_to_watch = NULL;
852
Alexander Duyck091a6242012-02-08 07:51:01 +0000853 /* update the statistics for this packet */
854 total_bytes += tx_buffer->bytecount;
855 total_packets += tx_buffer->gso_segs;
856
Jacob Keller0ede4a62012-05-22 06:08:32 +0000857 if (unlikely(tx_buffer->tx_flags & IXGBE_TX_FLAGS_TSTAMP))
858 ixgbe_ptp_tx_hwtstamp(q_vector, tx_buffer->skb);
Jacob Keller0ede4a62012-05-22 06:08:32 +0000859
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000860 /* free the skb */
861 dev_kfree_skb_any(tx_buffer->skb);
862
Alexander Duyck729739b2012-02-08 07:51:06 +0000863 /* unmap skb header data */
864 dma_unmap_single(tx_ring->dev,
865 dma_unmap_addr(tx_buffer, dma),
866 dma_unmap_len(tx_buffer, len),
867 DMA_TO_DEVICE);
868
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000869 /* clear tx_buffer data */
870 tx_buffer->skb = NULL;
Alexander Duyck729739b2012-02-08 07:51:06 +0000871 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +0000872
Alexander Duyck729739b2012-02-08 07:51:06 +0000873 /* unmap remaining buffers */
874 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000875 tx_buffer++;
876 tx_desc++;
877 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +0000878 if (unlikely(!i)) {
879 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000880 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +0000881 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000882 }
883
Alexander Duyck729739b2012-02-08 07:51:06 +0000884 /* unmap any remaining paged data */
885 if (dma_unmap_len(tx_buffer, len)) {
886 dma_unmap_page(tx_ring->dev,
887 dma_unmap_addr(tx_buffer, dma),
888 dma_unmap_len(tx_buffer, len),
889 DMA_TO_DEVICE);
890 dma_unmap_len_set(tx_buffer, len, 0);
891 }
892 }
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800893
Alexander Duyck729739b2012-02-08 07:51:06 +0000894 /* move us one more past the eop_desc for start of next pkt */
895 tx_buffer++;
896 tx_desc++;
897 i++;
898 if (unlikely(!i)) {
899 i -= tx_ring->count;
900 tx_buffer = tx_ring->tx_buffer_info;
901 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
902 }
903
904 /* issue prefetch for next Tx descriptor */
905 prefetch(tx_desc);
906
907 /* update budget accounting */
908 budget--;
909 } while (likely(budget));
910
911 i += tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -0700912 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000913 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800914 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000915 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000916 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000917 q_vector->tx.total_bytes += total_bytes;
918 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800919
John Fastabendc84d3242010-11-16 19:27:12 -0800920 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800921 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800922 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800923 e_err(drv, "Detected Tx Unit Hang\n"
924 " Tx Queue <%d>\n"
925 " TDH, TDT <%x>, <%x>\n"
926 " next_to_use <%x>\n"
927 " next_to_clean <%x>\n"
928 "tx_buffer_info[next_to_clean]\n"
929 " time_stamp <%lx>\n"
930 " jiffies <%lx>\n",
931 tx_ring->queue_index,
932 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
933 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000934 tx_ring->next_to_use, i,
935 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800936
937 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
938
939 e_info(probe,
940 "tx hang %d detected on queue %d, resetting adapter\n",
941 adapter->tx_timeout_count + 1, tx_ring->queue_index);
942
943 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000944 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800945
946 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000947 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800948 }
Auke Kok9a799d72007-09-15 14:07:45 -0700949
Alexander Duyckb2d96e02012-02-07 08:14:33 +0000950 netdev_tx_completed_queue(txring_txq(tx_ring),
951 total_packets, total_bytes);
952
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800953#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000954 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000955 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800956 /* Make sure that anybody stopping the queue after this
957 * sees the new next_to_clean.
958 */
959 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +0000960 if (__netif_subqueue_stopped(tx_ring->netdev,
961 tx_ring->queue_index)
962 && !test_bit(__IXGBE_DOWN, &adapter->state)) {
963 netif_wake_subqueue(tx_ring->netdev,
964 tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800965 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800966 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800967 }
Auke Kok9a799d72007-09-15 14:07:45 -0700968
Alexander Duyck59224552011-08-31 00:01:06 +0000969 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700970}
971
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400972#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800973static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800974 struct ixgbe_ring *tx_ring,
975 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800976{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000977 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000978 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
979 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800980
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800981 switch (hw->mac.type) {
982 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000983 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800984 break;
985 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800986 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000987 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
988 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
989 break;
990 default:
991 /* for unknown hardware do not write register */
992 return;
993 }
994
995 /*
996 * We can enable relaxed ordering for reads, but not writes when
997 * DCA is enabled. This is due to a known issue in some chipsets
998 * which will cause the DCA tag to be cleared.
999 */
1000 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
1001 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
1002 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
1003
1004 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
1005}
1006
1007static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
1008 struct ixgbe_ring *rx_ring,
1009 int cpu)
1010{
1011 struct ixgbe_hw *hw = &adapter->hw;
1012 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
1013 u8 reg_idx = rx_ring->reg_idx;
1014
1015
1016 switch (hw->mac.type) {
1017 case ixgbe_mac_82599EB:
1018 case ixgbe_mac_X540:
1019 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001020 break;
1021 default:
1022 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001023 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001024
1025 /*
1026 * We can enable relaxed ordering for reads, but not writes when
1027 * DCA is enabled. This is due to a known issue in some chipsets
1028 * which will cause the DCA tag to be cleared.
1029 */
1030 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001031 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1032
1033 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001034}
1035
1036static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1037{
1038 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001039 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001040 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001041
1042 if (q_vector->cpu == cpu)
1043 goto out_no_update;
1044
Alexander Duycka5579282012-02-08 07:50:04 +00001045 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001046 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001047
Alexander Duycka5579282012-02-08 07:50:04 +00001048 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001049 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001050
1051 q_vector->cpu = cpu;
1052out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001053 put_cpu();
1054}
1055
1056static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1057{
1058 int i;
1059
1060 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1061 return;
1062
Alexander Duycke35ec122009-05-21 13:07:12 +00001063 /* always use CB2 mode, difference is masked in the CB driver */
1064 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1065
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001066 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001067 adapter->q_vector[i]->cpu = -1;
1068 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001069 }
1070}
1071
1072static int __ixgbe_notify_dca(struct device *dev, void *data)
1073{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001074 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001075 unsigned long event = *(unsigned long *)data;
1076
Don Skidmore2a72c312011-07-20 02:27:05 +00001077 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001078 return 0;
1079
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001080 switch (event) {
1081 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001082 /* if we're already enabled, don't do it again */
1083 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1084 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001085 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001086 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001087 ixgbe_setup_dca(adapter);
1088 break;
1089 }
1090 /* Fall Through since DCA is disabled. */
1091 case DCA_PROVIDER_REMOVE:
1092 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1093 dca_remove_requester(dev);
1094 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1095 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1096 }
1097 break;
1098 }
1099
Denis V. Lunev652f0932008-03-27 14:39:17 +03001100 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001101}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001102
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001103#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001104static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1105 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001106 struct sk_buff *skb)
1107{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001108 if (ring->netdev->features & NETIF_F_RXHASH)
1109 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001110}
1111
Alexander Duyckf8003262012-03-03 02:35:52 +00001112#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001113/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001114 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001115 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001116 * @rx_desc: advanced rx descriptor
1117 *
1118 * Returns : true if it is FCoE pkt
1119 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001120static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001121 union ixgbe_adv_rx_desc *rx_desc)
1122{
1123 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1124
Alexander Duyck57efd442012-06-25 21:54:46 +00001125 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001126 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1127 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1128 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1129}
1130
Alexander Duyckf8003262012-03-03 02:35:52 +00001131#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001132/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001133 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001134 * @ring: structure containing ring specific data
1135 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001136 * @skb: skb currently being received and modified
1137 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001138static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001139 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001140 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001141{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001142 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001143
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001144 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001145 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001146 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001147
1148 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001149 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1150 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001151 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001152 return;
1153 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001154
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001155 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001156 return;
1157
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001158 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00001159 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore8bae1b22009-07-23 18:00:39 +00001160
1161 /*
1162 * 82599 errata, UDP frames with a 0 checksum can be marked as
1163 * checksum errors.
1164 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001165 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1166 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001167 return;
1168
Alexander Duyck8a0da212012-01-31 02:59:49 +00001169 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001170 return;
1171 }
1172
Auke Kok9a799d72007-09-15 14:07:45 -07001173 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001174 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001175}
1176
Alexander Duyck84ea2592010-11-16 19:26:49 -08001177static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001178{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001179 rx_ring->next_to_use = val;
Alexander Duyckf8003262012-03-03 02:35:52 +00001180
1181 /* update next to alloc since we have filled the ring */
1182 rx_ring->next_to_alloc = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001183 /*
1184 * Force memory writes to complete before letting h/w
1185 * know there are new descriptors to fetch. (Only
1186 * applicable for weak-ordered memory model archs,
1187 * such as IA-64).
1188 */
1189 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001190 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001191}
1192
Alexander Duyckf990b792012-01-31 02:59:34 +00001193static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1194 struct ixgbe_rx_buffer *bi)
1195{
1196 struct page *page = bi->page;
Alexander Duyckf8003262012-03-03 02:35:52 +00001197 dma_addr_t dma = bi->dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001198
Alexander Duyckf8003262012-03-03 02:35:52 +00001199 /* since we are recycling buffers we should seldom need to alloc */
1200 if (likely(dma))
Alexander Duyckf990b792012-01-31 02:59:34 +00001201 return true;
1202
Alexander Duyckf8003262012-03-03 02:35:52 +00001203 /* alloc new page for storage */
1204 if (likely(!page)) {
Mel Gorman06140022012-07-31 16:44:24 -07001205 page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
1206 bi->skb, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf990b792012-01-31 02:59:34 +00001207 if (unlikely(!page)) {
1208 rx_ring->rx_stats.alloc_rx_page_failed++;
1209 return false;
1210 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001211 bi->page = page;
Alexander Duyckf990b792012-01-31 02:59:34 +00001212 }
1213
Alexander Duyckf8003262012-03-03 02:35:52 +00001214 /* map page for use */
1215 dma = dma_map_page(rx_ring->dev, page, 0,
1216 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
Alexander Duyckf990b792012-01-31 02:59:34 +00001217
Alexander Duyckf8003262012-03-03 02:35:52 +00001218 /*
1219 * if mapping failed free memory back to system since
1220 * there isn't much point in holding memory we can't use
1221 */
1222 if (dma_mapping_error(rx_ring->dev, dma)) {
Alexander Duyckdd411ec2012-04-06 04:24:50 +00001223 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001224 bi->page = NULL;
1225
Alexander Duyckf990b792012-01-31 02:59:34 +00001226 rx_ring->rx_stats.alloc_rx_page_failed++;
1227 return false;
1228 }
1229
Alexander Duyckf8003262012-03-03 02:35:52 +00001230 bi->dma = dma;
Alexander Duyckafaa9452012-07-20 08:08:12 +00001231 bi->page_offset = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001232
Alexander Duyckf990b792012-01-31 02:59:34 +00001233 return true;
1234}
1235
Auke Kok9a799d72007-09-15 14:07:45 -07001236/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001237 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001238 * @rx_ring: ring to place buffers on
1239 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001240 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001241void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001242{
Auke Kok9a799d72007-09-15 14:07:45 -07001243 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001244 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001245 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001246
Alexander Duyckf8003262012-03-03 02:35:52 +00001247 /* nothing to do */
1248 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001249 return;
1250
Alexander Duycke4f74022012-01-31 02:59:44 +00001251 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001252 bi = &rx_ring->rx_buffer_info[i];
1253 i -= rx_ring->count;
1254
Alexander Duyckf8003262012-03-03 02:35:52 +00001255 do {
1256 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001257 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001258
Alexander Duyckf8003262012-03-03 02:35:52 +00001259 /*
1260 * Refresh the desc even if buffer_addrs didn't change
1261 * because each write-back erases this info.
1262 */
1263 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
Auke Kok9a799d72007-09-15 14:07:45 -07001264
Alexander Duyckf990b792012-01-31 02:59:34 +00001265 rx_desc++;
1266 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001267 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001268 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001269 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001270 bi = rx_ring->rx_buffer_info;
1271 i -= rx_ring->count;
1272 }
1273
1274 /* clear the hdr_addr for the next_to_use descriptor */
1275 rx_desc->read.hdr_addr = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001276
1277 cleaned_count--;
1278 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001279
Alexander Duyckf990b792012-01-31 02:59:34 +00001280 i += rx_ring->count;
1281
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001282 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001283 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001284}
1285
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001286/**
1287 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1288 * @data: pointer to the start of the headers
1289 * @max_len: total length of section to find headers in
1290 *
1291 * This function is meant to determine the length of headers that will
1292 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1293 * motivation of doing this is to only perform one pull for IPv4 TCP
1294 * packets so that we can do basic things like calculating the gso_size
1295 * based on the average data per packet.
1296 **/
1297static unsigned int ixgbe_get_headlen(unsigned char *data,
1298 unsigned int max_len)
1299{
1300 union {
1301 unsigned char *network;
1302 /* l2 headers */
1303 struct ethhdr *eth;
1304 struct vlan_hdr *vlan;
1305 /* l3 headers */
1306 struct iphdr *ipv4;
Alexander Duycka048b402012-05-24 08:26:29 +00001307 struct ipv6hdr *ipv6;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001308 } hdr;
1309 __be16 protocol;
1310 u8 nexthdr = 0; /* default to not TCP */
1311 u8 hlen;
1312
1313 /* this should never happen, but better safe than sorry */
1314 if (max_len < ETH_HLEN)
1315 return max_len;
1316
1317 /* initialize network frame pointer */
1318 hdr.network = data;
1319
1320 /* set first protocol and move network header forward */
1321 protocol = hdr.eth->h_proto;
1322 hdr.network += ETH_HLEN;
1323
1324 /* handle any vlan tag if present */
1325 if (protocol == __constant_htons(ETH_P_8021Q)) {
1326 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1327 return max_len;
1328
1329 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1330 hdr.network += VLAN_HLEN;
1331 }
1332
1333 /* handle L3 protocols */
1334 if (protocol == __constant_htons(ETH_P_IP)) {
1335 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1336 return max_len;
1337
1338 /* access ihl as a u8 to avoid unaligned access on ia64 */
1339 hlen = (hdr.network[0] & 0x0F) << 2;
1340
1341 /* verify hlen meets minimum size requirements */
1342 if (hlen < sizeof(struct iphdr))
1343 return hdr.network - data;
1344
1345 /* record next protocol */
1346 nexthdr = hdr.ipv4->protocol;
1347 hdr.network += hlen;
Alexander Duycka048b402012-05-24 08:26:29 +00001348 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
1349 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
1350 return max_len;
1351
1352 /* record next protocol */
1353 nexthdr = hdr.ipv6->nexthdr;
1354 hdr.network += sizeof(struct ipv6hdr);
Alexander Duyckf8003262012-03-03 02:35:52 +00001355#ifdef IXGBE_FCOE
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001356 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1357 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1358 return max_len;
1359 hdr.network += FCOE_HEADER_LEN;
1360#endif
1361 } else {
1362 return hdr.network - data;
1363 }
1364
Alexander Duycka048b402012-05-24 08:26:29 +00001365 /* finally sort out TCP/UDP */
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001366 if (nexthdr == IPPROTO_TCP) {
1367 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1368 return max_len;
1369
1370 /* access doff as a u8 to avoid unaligned access on ia64 */
1371 hlen = (hdr.network[12] & 0xF0) >> 2;
1372
1373 /* verify hlen meets minimum size requirements */
1374 if (hlen < sizeof(struct tcphdr))
1375 return hdr.network - data;
1376
1377 hdr.network += hlen;
Alexander Duycka048b402012-05-24 08:26:29 +00001378 } else if (nexthdr == IPPROTO_UDP) {
1379 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
1380 return max_len;
1381
1382 hdr.network += sizeof(struct udphdr);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001383 }
1384
1385 /*
1386 * If everything has gone correctly hdr.network should be the
1387 * data section of the packet and will be the end of the header.
1388 * If not then it probably represents the end of the last recognized
1389 * header.
1390 */
1391 if ((hdr.network - data) < max_len)
1392 return hdr.network - data;
1393 else
1394 return max_len;
1395}
1396
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001397static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1398 struct sk_buff *skb)
1399{
Alexander Duyckf8003262012-03-03 02:35:52 +00001400 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001401
1402 /* set gso_size to avoid messing up TCP MSS */
1403 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1404 IXGBE_CB(skb)->append_cnt);
1405}
1406
1407static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1408 struct sk_buff *skb)
1409{
1410 /* if append_cnt is 0 then frame is not RSC */
1411 if (!IXGBE_CB(skb)->append_cnt)
1412 return;
1413
1414 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1415 rx_ring->rx_stats.rsc_flush++;
1416
1417 ixgbe_set_rsc_gso_size(rx_ring, skb);
1418
1419 /* gso_size is computed using append_cnt so always clear it last */
1420 IXGBE_CB(skb)->append_cnt = 0;
1421}
1422
Alexander Duyck8a0da212012-01-31 02:59:49 +00001423/**
1424 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1425 * @rx_ring: rx descriptor ring packet is being transacted on
1426 * @rx_desc: pointer to the EOP Rx descriptor
1427 * @skb: pointer to current skb being populated
1428 *
1429 * This function checks the ring, descriptor, and packet information in
1430 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1431 * other fields within the skb.
1432 **/
1433static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1434 union ixgbe_adv_rx_desc *rx_desc,
1435 struct sk_buff *skb)
1436{
John Fastabend43e95f12012-05-15 06:12:17 +00001437 struct net_device *dev = rx_ring->netdev;
1438
Alexander Duyck8a0da212012-01-31 02:59:49 +00001439 ixgbe_update_rsc_stats(rx_ring, skb);
1440
1441 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1442
1443 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1444
Jacob Keller1d1a79b2012-05-22 06:18:08 +00001445 ixgbe_ptp_rx_hwtstamp(rx_ring->q_vector, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001446
John Fastabend43e95f12012-05-15 06:12:17 +00001447 if ((dev->features & NETIF_F_HW_VLAN_RX) &&
1448 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001449 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1450 __vlan_hwaccel_put_tag(skb, vid);
1451 }
1452
1453 skb_record_rx_queue(skb, rx_ring->queue_index);
1454
John Fastabend43e95f12012-05-15 06:12:17 +00001455 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001456}
1457
1458static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1459 struct sk_buff *skb)
1460{
1461 struct ixgbe_adapter *adapter = q_vector->adapter;
1462
1463 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1464 napi_gro_receive(&q_vector->napi, skb);
1465 else
1466 netif_rx(skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001467}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001468
Alexander Duyckf8003262012-03-03 02:35:52 +00001469/**
1470 * ixgbe_is_non_eop - process handling of non-EOP buffers
1471 * @rx_ring: Rx ring being processed
1472 * @rx_desc: Rx descriptor for current buffer
1473 * @skb: Current socket buffer containing buffer in progress
1474 *
1475 * This function updates next to clean. If the buffer is an EOP buffer
1476 * this function exits returning false, otherwise it will place the
1477 * sk_buff in the next buffer to be chained and return true indicating
1478 * that this is in fact a non-EOP buffer.
1479 **/
1480static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
1481 union ixgbe_adv_rx_desc *rx_desc,
1482 struct sk_buff *skb)
1483{
1484 u32 ntc = rx_ring->next_to_clean + 1;
1485
1486 /* fetch, update, and store next to clean */
1487 ntc = (ntc < rx_ring->count) ? ntc : 0;
1488 rx_ring->next_to_clean = ntc;
1489
1490 prefetch(IXGBE_RX_DESC(rx_ring, ntc));
1491
Alexander Duyck5a02cbd2012-07-20 08:08:51 +00001492 /* update RSC append count if present */
1493 if (ring_is_rsc_enabled(rx_ring)) {
1494 __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1495 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1496
1497 if (unlikely(rsc_enabled)) {
1498 u32 rsc_cnt = le32_to_cpu(rsc_enabled);
1499
1500 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1501 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
1502
1503 /* update ntc based on RSC value */
1504 ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
1505 ntc &= IXGBE_RXDADV_NEXTP_MASK;
1506 ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
1507 }
1508 }
1509
1510 /* if we are the last buffer then there is nothing else to do */
Alexander Duyckf8003262012-03-03 02:35:52 +00001511 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1512 return false;
1513
Alexander Duyckf8003262012-03-03 02:35:52 +00001514 /* place skb in next buffer to be received */
1515 rx_ring->rx_buffer_info[ntc].skb = skb;
1516 rx_ring->rx_stats.non_eop_descs++;
1517
1518 return true;
1519}
1520
1521/**
Alexander Duyck19861ce2012-07-20 08:08:33 +00001522 * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
1523 * @rx_ring: rx descriptor ring packet is being transacted on
1524 * @skb: pointer to current skb being adjusted
1525 *
1526 * This function is an ixgbe specific version of __pskb_pull_tail. The
1527 * main difference between this version and the original function is that
1528 * this function can make several assumptions about the state of things
1529 * that allow for significant optimizations versus the standard function.
1530 * As a result we can do things like drop a frag and maintain an accurate
1531 * truesize for the skb.
1532 */
1533static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
1534 struct sk_buff *skb)
1535{
1536 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1537 unsigned char *va;
1538 unsigned int pull_len;
1539
1540 /*
1541 * it is valid to use page_address instead of kmap since we are
1542 * working with pages allocated out of the lomem pool per
1543 * alloc_page(GFP_ATOMIC)
1544 */
1545 va = skb_frag_address(frag);
1546
1547 /*
1548 * we need the header to contain the greater of either ETH_HLEN or
1549 * 60 bytes if the skb->len is less than 60 for skb_pad.
1550 */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001551 pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001552
1553 /* align pull length to size of long to optimize memcpy performance */
1554 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
1555
1556 /* update all of the pointers */
1557 skb_frag_size_sub(frag, pull_len);
1558 frag->page_offset += pull_len;
1559 skb->data_len -= pull_len;
1560 skb->tail += pull_len;
Alexander Duyck19861ce2012-07-20 08:08:33 +00001561}
1562
1563/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001564 * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
1565 * @rx_ring: rx descriptor ring packet is being transacted on
1566 * @skb: pointer to current skb being updated
1567 *
1568 * This function provides a basic DMA sync up for the first fragment of an
1569 * skb. The reason for doing this is that the first fragment cannot be
1570 * unmapped until we have reached the end of packet descriptor for a buffer
1571 * chain.
1572 */
1573static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
1574 struct sk_buff *skb)
1575{
1576 /* if the page was released unmap it, else just sync our portion */
1577 if (unlikely(IXGBE_CB(skb)->page_released)) {
1578 dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
1579 ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
1580 IXGBE_CB(skb)->page_released = false;
1581 } else {
1582 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
1583
1584 dma_sync_single_range_for_cpu(rx_ring->dev,
1585 IXGBE_CB(skb)->dma,
1586 frag->page_offset,
1587 ixgbe_rx_bufsz(rx_ring),
1588 DMA_FROM_DEVICE);
1589 }
1590 IXGBE_CB(skb)->dma = 0;
1591}
1592
1593/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001594 * ixgbe_cleanup_headers - Correct corrupted or empty headers
1595 * @rx_ring: rx descriptor ring packet is being transacted on
1596 * @rx_desc: pointer to the EOP Rx descriptor
1597 * @skb: pointer to current skb being fixed
1598 *
1599 * Check for corrupted packet headers caused by senders on the local L2
1600 * embedded NIC switch not setting up their Tx Descriptors right. These
1601 * should be very rare.
1602 *
1603 * Also address the case where we are pulling data in on pages only
1604 * and as such no data is present in the skb header.
1605 *
1606 * In addition if skb is not at least 60 bytes we need to pad it so that
1607 * it is large enough to qualify as a valid Ethernet frame.
1608 *
1609 * Returns true if an error was encountered and skb was freed.
1610 **/
1611static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1612 union ixgbe_adv_rx_desc *rx_desc,
1613 struct sk_buff *skb)
1614{
Alexander Duyckf8003262012-03-03 02:35:52 +00001615 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001616
1617 /* verify that the packet does not have any known errors */
1618 if (unlikely(ixgbe_test_staterr(rx_desc,
1619 IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
1620 !(netdev->features & NETIF_F_RXALL))) {
1621 dev_kfree_skb_any(skb);
1622 return true;
1623 }
1624
Alexander Duyck19861ce2012-07-20 08:08:33 +00001625 /* place header in linear portion of buffer */
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001626 if (skb_is_nonlinear(skb))
1627 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001628
Alexander Duyck57efd442012-06-25 21:54:46 +00001629#ifdef IXGBE_FCOE
1630 /* do not attempt to pad FCoE Frames as this will disrupt DDP */
1631 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
1632 return false;
1633
1634#endif
Alexander Duyckf8003262012-03-03 02:35:52 +00001635 /* if skb_pad returns an error the skb was freed */
1636 if (unlikely(skb->len < 60)) {
1637 int pad_len = 60 - skb->len;
1638
1639 if (skb_pad(skb, pad_len))
1640 return true;
1641 __skb_put(skb, pad_len);
1642 }
1643
1644 return false;
1645}
1646
1647/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001648 * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
1649 * @rx_ring: rx descriptor ring to store buffers on
1650 * @old_buff: donor buffer to have page reused
1651 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001652 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001653 **/
1654static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
1655 struct ixgbe_rx_buffer *old_buff)
1656{
1657 struct ixgbe_rx_buffer *new_buff;
1658 u16 nta = rx_ring->next_to_alloc;
Alexander Duyckf8003262012-03-03 02:35:52 +00001659
1660 new_buff = &rx_ring->rx_buffer_info[nta];
1661
1662 /* update, and store next to alloc */
1663 nta++;
1664 rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
1665
1666 /* transfer page from old buffer to new buffer */
1667 new_buff->page = old_buff->page;
1668 new_buff->dma = old_buff->dma;
Alexander Duyck0549ae22012-07-20 08:08:18 +00001669 new_buff->page_offset = old_buff->page_offset;
Alexander Duyckf8003262012-03-03 02:35:52 +00001670
1671 /* sync the buffer for use by the device */
1672 dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001673 new_buff->page_offset,
1674 ixgbe_rx_bufsz(rx_ring),
Alexander Duyckf8003262012-03-03 02:35:52 +00001675 DMA_FROM_DEVICE);
Alexander Duyckf8003262012-03-03 02:35:52 +00001676}
1677
1678/**
1679 * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
1680 * @rx_ring: rx descriptor ring to transact packets on
1681 * @rx_buffer: buffer containing page to add
1682 * @rx_desc: descriptor containing length of buffer written by hardware
1683 * @skb: sk_buff to place the data into
1684 *
Alexander Duyck0549ae22012-07-20 08:08:18 +00001685 * This function will add the data contained in rx_buffer->page to the skb.
1686 * This is done either through a direct copy if the data in the buffer is
1687 * less than the skb header size, otherwise it will just attach the page as
1688 * a frag to the skb.
1689 *
1690 * The function will then update the page offset if necessary and return
1691 * true if the buffer can be reused by the adapter.
Alexander Duyckf8003262012-03-03 02:35:52 +00001692 **/
Alexander Duyck0549ae22012-07-20 08:08:18 +00001693static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckf8003262012-03-03 02:35:52 +00001694 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck0549ae22012-07-20 08:08:18 +00001695 union ixgbe_adv_rx_desc *rx_desc,
1696 struct sk_buff *skb)
Alexander Duyckf8003262012-03-03 02:35:52 +00001697{
Alexander Duyck0549ae22012-07-20 08:08:18 +00001698 struct page *page = rx_buffer->page;
1699 unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001700#if (PAGE_SIZE < 8192)
Alexander Duyck0549ae22012-07-20 08:08:18 +00001701 unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001702#else
1703 unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
1704 unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
1705 ixgbe_rx_bufsz(rx_ring);
1706#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001707
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001708 if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
1709 unsigned char *va = page_address(page) + rx_buffer->page_offset;
1710
1711 memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
1712
1713 /* we can reuse buffer as-is, just make sure it is local */
1714 if (likely(page_to_nid(page) == numa_node_id()))
1715 return true;
1716
1717 /* this page cannot be reused so discard it */
1718 put_page(page);
1719 return false;
1720 }
1721
Alexander Duyck0549ae22012-07-20 08:08:18 +00001722 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
1723 rx_buffer->page_offset, size, truesize);
1724
Alexander Duyck09816fb2012-07-20 08:08:23 +00001725 /* avoid re-using remote pages */
1726 if (unlikely(page_to_nid(page) != numa_node_id()))
1727 return false;
1728
1729#if (PAGE_SIZE < 8192)
1730 /* if we are only owner of page we can reuse it */
1731 if (unlikely(page_count(page) != 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001732 return false;
1733
1734 /* flip page offset to other buffer */
1735 rx_buffer->page_offset ^= truesize;
1736
Alexander Duyck09816fb2012-07-20 08:08:23 +00001737 /*
1738 * since we are the only owner of the page and we need to
1739 * increment it, just set the value to 2 in order to avoid
1740 * an unecessary locked operation
1741 */
1742 atomic_set(&page->_count, 2);
1743#else
1744 /* move offset up to the next cache line */
1745 rx_buffer->page_offset += truesize;
1746
1747 if (rx_buffer->page_offset > last_offset)
1748 return false;
1749
Alexander Duyck0549ae22012-07-20 08:08:18 +00001750 /* bump ref count on page before it is given to the stack */
1751 get_page(page);
Alexander Duyck09816fb2012-07-20 08:08:23 +00001752#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001753
1754 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001755}
1756
Alexander Duyck18806c92012-07-20 08:08:44 +00001757static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
1758 union ixgbe_adv_rx_desc *rx_desc)
1759{
1760 struct ixgbe_rx_buffer *rx_buffer;
1761 struct sk_buff *skb;
1762 struct page *page;
1763
1764 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
1765 page = rx_buffer->page;
1766 prefetchw(page);
1767
1768 skb = rx_buffer->skb;
1769
1770 if (likely(!skb)) {
1771 void *page_addr = page_address(page) +
1772 rx_buffer->page_offset;
1773
1774 /* prefetch first cache line of first page */
1775 prefetch(page_addr);
1776#if L1_CACHE_BYTES < 128
1777 prefetch(page_addr + L1_CACHE_BYTES);
1778#endif
1779
1780 /* allocate a skb to store the frags */
1781 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1782 IXGBE_RX_HDR_SIZE);
1783 if (unlikely(!skb)) {
1784 rx_ring->rx_stats.alloc_rx_buff_failed++;
1785 return NULL;
1786 }
1787
1788 /*
1789 * we will be copying header into skb->data in
1790 * pskb_may_pull so it is in our interest to prefetch
1791 * it now to avoid a possible cache miss
1792 */
1793 prefetchw(skb->data);
1794
1795 /*
1796 * Delay unmapping of the first packet. It carries the
1797 * header information, HW may still access the header
1798 * after the writeback. Only unmap it when EOP is
1799 * reached
1800 */
1801 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1802 goto dma_sync;
1803
1804 IXGBE_CB(skb)->dma = rx_buffer->dma;
1805 } else {
1806 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
1807 ixgbe_dma_sync_frag(rx_ring, skb);
1808
1809dma_sync:
1810 /* we are reusing so sync this buffer for CPU use */
1811 dma_sync_single_range_for_cpu(rx_ring->dev,
1812 rx_buffer->dma,
1813 rx_buffer->page_offset,
1814 ixgbe_rx_bufsz(rx_ring),
1815 DMA_FROM_DEVICE);
1816 }
1817
1818 /* pull page into skb */
1819 if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
1820 /* hand second half of page back to the ring */
1821 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
1822 } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
1823 /* the page has been released from the ring */
1824 IXGBE_CB(skb)->page_released = true;
1825 } else {
1826 /* we are not reusing the buffer so unmap it */
1827 dma_unmap_page(rx_ring->dev, rx_buffer->dma,
1828 ixgbe_rx_pg_size(rx_ring),
1829 DMA_FROM_DEVICE);
1830 }
1831
1832 /* clear contents of buffer_info */
1833 rx_buffer->skb = NULL;
1834 rx_buffer->dma = 0;
1835 rx_buffer->page = NULL;
1836
1837 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00001838}
1839
1840/**
1841 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
1842 * @q_vector: structure containing interrupt and ring information
1843 * @rx_ring: rx descriptor ring to transact packets on
1844 * @budget: Total limit on number of packets to process
1845 *
1846 * This function provides a "bounce buffer" approach to Rx interrupt
1847 * processing. The advantage to this is that on systems that have
1848 * expensive overhead for IOMMU access this provides a means of avoiding
1849 * it by maintaining the mapping of the page to the syste.
1850 *
1851 * Returns true if all work is completed without reaching budget
1852 **/
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001853static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001854 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001855 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001856{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001857 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Ben Greear3f2d1c02012-03-08 08:28:41 +00001858#ifdef IXGBE_FCOE
Alexander Duyckf8003262012-03-03 02:35:52 +00001859 struct ixgbe_adapter *adapter = q_vector->adapter;
Mark Rustad4ffdf912012-07-18 06:05:50 +00001860 int ddp_bytes;
1861 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00001862#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00001863 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001864
Alexander Duyckf8003262012-03-03 02:35:52 +00001865 do {
Alexander Duyckf8003262012-03-03 02:35:52 +00001866 union ixgbe_adv_rx_desc *rx_desc;
1867 struct sk_buff *skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001868
Alexander Duyckf8003262012-03-03 02:35:52 +00001869 /* return some buffers to hardware, one at a time is too slow */
1870 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
1871 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1872 cleaned_count = 0;
1873 }
Auke Kok9a799d72007-09-15 14:07:45 -07001874
Alexander Duyck18806c92012-07-20 08:08:44 +00001875 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Auke Kok9a799d72007-09-15 14:07:45 -07001876
Alexander Duyckf8003262012-03-03 02:35:52 +00001877 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
1878 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001879
Alexander Duyckf8003262012-03-03 02:35:52 +00001880 /*
1881 * This memory barrier is needed to keep us from reading
1882 * any other fields out of the rx_desc until we know the
1883 * RXD_STAT_DD bit is set
1884 */
1885 rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07001886
Alexander Duyck18806c92012-07-20 08:08:44 +00001887 /* retrieve a buffer from the ring */
1888 skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
Alexander Duyckf8003262012-03-03 02:35:52 +00001889
Alexander Duyck18806c92012-07-20 08:08:44 +00001890 /* exit if we failed to retrieve a buffer */
1891 if (!skb)
1892 break;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001893
Auke Kok9a799d72007-09-15 14:07:45 -07001894 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001895
Alexander Duyckf8003262012-03-03 02:35:52 +00001896 /* place incomplete frames back on ring for completion */
1897 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
1898 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001899
Alexander Duyckf8003262012-03-03 02:35:52 +00001900 /* verify the packet layout is correct */
1901 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
1902 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001903
1904 /* probably a little skewed due to removing CRC */
1905 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001906
Alexander Duyck8a0da212012-01-31 02:59:49 +00001907 /* populate checksum, timestamp, VLAN, and protocol */
1908 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1909
Yi Zou332d4a72009-05-13 13:11:53 +00001910#ifdef IXGBE_FCOE
1911 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00001912 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001913 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00001914 /* include DDPed FCoE data */
1915 if (ddp_bytes > 0) {
1916 if (!mss) {
1917 mss = rx_ring->netdev->mtu -
1918 sizeof(struct fcoe_hdr) -
1919 sizeof(struct fc_frame_header) -
1920 sizeof(struct fcoe_crc_eof);
1921 if (mss > 512)
1922 mss &= ~511;
1923 }
1924 total_rx_bytes += ddp_bytes;
1925 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
1926 mss);
1927 }
David S. Miller823dcd22011-08-20 10:39:12 -07001928 if (!ddp_bytes) {
1929 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001930 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07001931 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001932 }
Alexander Duyckf8003262012-03-03 02:35:52 +00001933
Yi Zou332d4a72009-05-13 13:11:53 +00001934#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001935 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001936
Alexander Duyckf8003262012-03-03 02:35:52 +00001937 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001938 total_rx_packets++;
1939 } while (likely(total_rx_packets < budget));
Auke Kok9a799d72007-09-15 14:07:45 -07001940
Alexander Duyckc267fc12010-11-16 19:27:00 -08001941 u64_stats_update_begin(&rx_ring->syncp);
1942 rx_ring->stats.packets += total_rx_packets;
1943 rx_ring->stats.bytes += total_rx_bytes;
1944 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001945 q_vector->rx.total_packets += total_rx_packets;
1946 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001947
Alexander Duyckf8003262012-03-03 02:35:52 +00001948 if (cleaned_count)
1949 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
1950
Alexander Duyckf4de00e2012-09-25 00:29:37 +00001951 return (total_rx_packets < budget);
Auke Kok9a799d72007-09-15 14:07:45 -07001952}
1953
Auke Kok9a799d72007-09-15 14:07:45 -07001954/**
1955 * ixgbe_configure_msix - Configure MSI-X hardware
1956 * @adapter: board private structure
1957 *
1958 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1959 * interrupts.
1960 **/
1961static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1962{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001963 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001964 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001965 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001966
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001967 /* Populate MSIX to EITR Select */
1968 if (adapter->num_vfs > 32) {
1969 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1970 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1971 }
1972
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001973 /*
1974 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001975 * corresponding register.
1976 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001977 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001978 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001979 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001980
Alexander Duycka5579282012-02-08 07:50:04 +00001981 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001982 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001983
Alexander Duycka5579282012-02-08 07:50:04 +00001984 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001985 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001986
Alexander Duyckfe49f042009-06-04 16:00:09 +00001987 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001988 }
1989
Alexander Duyckbd508172010-11-16 19:27:03 -08001990 switch (adapter->hw.mac.type) {
1991 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001992 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001993 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001994 break;
1995 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001996 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001997 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001998 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001999 default:
2000 break;
2001 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002002 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002003
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002004 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002005 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002006 mask &= ~(IXGBE_EIMS_OTHER |
2007 IXGBE_EIMS_MAILBOX |
2008 IXGBE_EIMS_LSC);
2009
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002010 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002011}
2012
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002013enum latency_range {
2014 lowest_latency = 0,
2015 low_latency = 1,
2016 bulk_latency = 2,
2017 latency_invalid = 255
2018};
2019
2020/**
2021 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002022 * @q_vector: structure containing interrupt and ring information
2023 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002024 *
2025 * Stores a new ITR value based on packets and byte
2026 * counts during the last interrupt. The advantage of per interrupt
2027 * computation is faster updates and more accurate ITR for the current
2028 * traffic pattern. Constants in this function were computed
2029 * based on theoretical maximum wire speed and thresholds were set based
2030 * on testing data as well as attempting to minimize response time
2031 * while increasing bulk throughput.
2032 * this functionality is controlled by the InterruptThrottleRate module
2033 * parameter (see ixgbe_param.c)
2034 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002035static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2036 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002037{
Alexander Duyckbd198052011-06-11 01:45:08 +00002038 int bytes = ring_container->total_bytes;
2039 int packets = ring_container->total_packets;
2040 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00002041 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00002042 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002043
2044 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00002045 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002046
2047 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00002048 * 0-10MB/s lowest (100000 ints/s)
2049 * 10-20MB/s low (20000 ints/s)
2050 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002051 */
2052 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002053 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002054 bytes_perint = bytes / timepassed_us; /* bytes/usec */
2055
2056 switch (itr_setting) {
2057 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002058 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002059 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002060 break;
2061 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002062 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002063 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00002064 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00002065 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002066 break;
2067 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00002068 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00002069 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002070 break;
2071 }
2072
Alexander Duyckbd198052011-06-11 01:45:08 +00002073 /* clear work counters since we have the values we need */
2074 ring_container->total_bytes = 0;
2075 ring_container->total_packets = 0;
2076
2077 /* write updated itr to ring container */
2078 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002079}
2080
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002081/**
2082 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002083 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002084 *
2085 * This function is made to be called by ethtool and by the driver
2086 * when it needs to update EITR registers at runtime. Hardware
2087 * specific quirks/differences are taken care of here.
2088 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002089void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002090{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002091 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002092 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002093 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002094 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002095
Alexander Duyckbd508172010-11-16 19:27:03 -08002096 switch (adapter->hw.mac.type) {
2097 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002098 /* must write high and low 16 bits to reset counter */
2099 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002100 break;
2101 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002102 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002103 /*
2104 * set the WDIS bit to not clear the timer bits and cause an
2105 * immediate assertion of the interrupt
2106 */
2107 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002108 break;
2109 default:
2110 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002111 }
2112 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2113}
2114
Alexander Duyckbd198052011-06-11 01:45:08 +00002115static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002116{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002117 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00002118 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002119
Alexander Duyckbd198052011-06-11 01:45:08 +00002120 ixgbe_update_itr(q_vector, &q_vector->tx);
2121 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002122
Alexander Duyck08c88332011-06-11 01:45:03 +00002123 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002124
2125 switch (current_itr) {
2126 /* counts and packets in update_itr are dependent on these numbers */
2127 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002128 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002129 break;
2130 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002131 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002132 break;
2133 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002134 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002135 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00002136 default:
2137 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002138 }
2139
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002140 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002141 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002142 new_itr = (10 * new_itr * q_vector->itr) /
2143 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002144
Alexander Duyckbd198052011-06-11 01:45:08 +00002145 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002146 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002147
2148 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002149 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002150}
2151
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002152/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002153 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002154 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002155 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002156static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002157{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002158 struct ixgbe_hw *hw = &adapter->hw;
2159 u32 eicr = adapter->interrupt_event;
2160
Alexander Duyckf0f97782011-04-22 04:08:09 +00002161 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002162 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002163
Alexander Duyckf0f97782011-04-22 04:08:09 +00002164 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2165 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
2166 return;
2167
2168 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2169
Joe Perches7ca647b2010-09-07 21:35:40 +00002170 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002171 case IXGBE_DEV_ID_82599_T3_LOM:
2172 /*
2173 * Since the warning interrupt is for both ports
2174 * we don't have to check if:
2175 * - This interrupt wasn't for our port.
2176 * - We may have missed the interrupt so always have to
2177 * check if we got a LSC
2178 */
2179 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
2180 !(eicr & IXGBE_EICR_LSC))
2181 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002182
Alexander Duyckf0f97782011-04-22 04:08:09 +00002183 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
2184 u32 autoneg;
2185 bool link_up = false;
2186
Joe Perches7ca647b2010-09-07 21:35:40 +00002187 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
2188
Alexander Duyckf0f97782011-04-22 04:08:09 +00002189 if (link_up)
2190 return;
2191 }
2192
2193 /* Check if this is not due to overtemp */
2194 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2195 return;
2196
2197 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002198 default:
2199 if (!(eicr & IXGBE_EICR_GPI_SDP0))
2200 return;
2201 break;
2202 }
2203 e_crit(drv,
2204 "Network adapter has been stopped because it has over heated. "
2205 "Restart the computer. If the problem persists, "
2206 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00002207
2208 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002209}
2210
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002211static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2212{
2213 struct ixgbe_hw *hw = &adapter->hw;
2214
2215 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
2216 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002217 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002218 /* write to clear the interrupt */
2219 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
2220 }
2221}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002222
Jacob Keller4f51bf72011-08-20 04:49:45 +00002223static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2224{
2225 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2226 return;
2227
2228 switch (adapter->hw.mac.type) {
2229 case ixgbe_mac_82599EB:
2230 /*
2231 * Need to check link state so complete overtemp check
2232 * on service task
2233 */
2234 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
2235 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2236 adapter->interrupt_event = eicr;
2237 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2238 ixgbe_service_event_schedule(adapter);
2239 return;
2240 }
2241 return;
2242 case ixgbe_mac_X540:
2243 if (!(eicr & IXGBE_EICR_TS))
2244 return;
2245 break;
2246 default:
2247 return;
2248 }
2249
2250 e_crit(drv,
2251 "Network adapter has been stopped because it has over heated. "
2252 "Restart the computer. If the problem persists, "
2253 "power off the system and replace the adapter\n");
2254}
2255
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002256static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2257{
2258 struct ixgbe_hw *hw = &adapter->hw;
2259
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002260 if (eicr & IXGBE_EICR_GPI_SDP2) {
2261 /* Clear the interrupt */
2262 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002263 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2264 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2265 ixgbe_service_event_schedule(adapter);
2266 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002267 }
2268
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002269 if (eicr & IXGBE_EICR_GPI_SDP1) {
2270 /* Clear the interrupt */
2271 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002272 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2273 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2274 ixgbe_service_event_schedule(adapter);
2275 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002276 }
2277}
2278
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002279static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2280{
2281 struct ixgbe_hw *hw = &adapter->hw;
2282
2283 adapter->lsc_int++;
2284 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2285 adapter->link_check_timeout = jiffies;
2286 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2287 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002288 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002289 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002290 }
2291}
2292
Alexander Duyckfe49f042009-06-04 16:00:09 +00002293static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2294 u64 qmask)
2295{
2296 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002297 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002298
Alexander Duyckbd508172010-11-16 19:27:03 -08002299 switch (hw->mac.type) {
2300 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002301 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002302 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2303 break;
2304 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002305 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002306 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002307 if (mask)
2308 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002309 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002310 if (mask)
2311 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2312 break;
2313 default:
2314 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002315 }
2316 /* skip the flush */
2317}
2318
2319static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002320 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002321{
2322 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002323 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002324
Alexander Duyckbd508172010-11-16 19:27:03 -08002325 switch (hw->mac.type) {
2326 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002327 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002328 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2329 break;
2330 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002331 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002332 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002333 if (mask)
2334 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002335 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002336 if (mask)
2337 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2338 break;
2339 default:
2340 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002341 }
2342 /* skip the flush */
2343}
2344
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002345/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002346 * ixgbe_irq_enable - Enable default interrupt generation settings
2347 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002348 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002349static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2350 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002351{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002352 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002353
Alexander Duyck2c4af692011-07-15 07:29:55 +00002354 /* don't reenable LSC while waiting for link */
2355 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2356 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002357
Alexander Duyck2c4af692011-07-15 07:29:55 +00002358 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002359 switch (adapter->hw.mac.type) {
2360 case ixgbe_mac_82599EB:
2361 mask |= IXGBE_EIMS_GPI_SDP0;
2362 break;
2363 case ixgbe_mac_X540:
2364 mask |= IXGBE_EIMS_TS;
2365 break;
2366 default:
2367 break;
2368 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002369 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2370 mask |= IXGBE_EIMS_GPI_SDP1;
2371 switch (adapter->hw.mac.type) {
2372 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002373 mask |= IXGBE_EIMS_GPI_SDP1;
2374 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002375 case ixgbe_mac_X540:
2376 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002377 mask |= IXGBE_EIMS_MAILBOX;
2378 break;
2379 default:
2380 break;
2381 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002382
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002383 if (adapter->hw.mac.type == ixgbe_mac_X540)
2384 mask |= IXGBE_EIMS_TIMESYNC;
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002385
Alexander Duyck2c4af692011-07-15 07:29:55 +00002386 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2387 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2388 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002389
Alexander Duyck2c4af692011-07-15 07:29:55 +00002390 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2391 if (queues)
2392 ixgbe_irq_enable_queues(adapter, ~0);
2393 if (flush)
2394 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002395}
2396
Alexander Duyck2c4af692011-07-15 07:29:55 +00002397static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002398{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002399 struct ixgbe_adapter *adapter = data;
2400 struct ixgbe_hw *hw = &adapter->hw;
2401 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002402
Alexander Duyck2c4af692011-07-15 07:29:55 +00002403 /*
2404 * Workaround for Silicon errata. Use clear-by-write instead
2405 * of clear-by-read. Reading with EICS will return the
2406 * interrupt causes without clearing, which later be done
2407 * with the write to EICR.
2408 */
2409 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2410 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002411
Alexander Duyck2c4af692011-07-15 07:29:55 +00002412 if (eicr & IXGBE_EICR_LSC)
2413 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002414
Alexander Duyck2c4af692011-07-15 07:29:55 +00002415 if (eicr & IXGBE_EICR_MAILBOX)
2416 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002417
Alexander Duyck2c4af692011-07-15 07:29:55 +00002418 switch (hw->mac.type) {
2419 case ixgbe_mac_82599EB:
2420 case ixgbe_mac_X540:
2421 if (eicr & IXGBE_EICR_ECC)
2422 e_info(link, "Received unrecoverable ECC Err, please "
2423 "reboot\n");
2424 /* Handle Flow Director Full threshold interrupt */
2425 if (eicr & IXGBE_EICR_FLOW_DIR) {
2426 int reinit_count = 0;
2427 int i;
2428 for (i = 0; i < adapter->num_tx_queues; i++) {
2429 struct ixgbe_ring *ring = adapter->tx_ring[i];
2430 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2431 &ring->state))
2432 reinit_count++;
2433 }
2434 if (reinit_count) {
2435 /* no more flow director interrupts until after init */
2436 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2437 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2438 ixgbe_service_event_schedule(adapter);
2439 }
2440 }
2441 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002442 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002443 break;
2444 default:
2445 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002446 }
2447
Alexander Duyck2c4af692011-07-15 07:29:55 +00002448 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002449
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002450 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2451 ixgbe_ptp_check_pps_event(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002452
Alexander Duyck2c4af692011-07-15 07:29:55 +00002453 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002454 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002455 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002456
Alexander Duyck2c4af692011-07-15 07:29:55 +00002457 return IRQ_HANDLED;
2458}
2459
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002460static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002461{
2462 struct ixgbe_q_vector *q_vector = data;
2463
Auke Kok9a799d72007-09-15 14:07:45 -07002464 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002465
2466 if (q_vector->rx.ring || q_vector->tx.ring)
2467 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002468
2469 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002470}
2471
Auke Kok9a799d72007-09-15 14:07:45 -07002472/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00002473 * ixgbe_poll - NAPI Rx polling callback
2474 * @napi: structure for representing this polling device
2475 * @budget: how many packets driver is allowed to clean
2476 *
2477 * This function is used for legacy and MSI, NAPI mode
2478 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00002479int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00002480{
2481 struct ixgbe_q_vector *q_vector =
2482 container_of(napi, struct ixgbe_q_vector, napi);
2483 struct ixgbe_adapter *adapter = q_vector->adapter;
2484 struct ixgbe_ring *ring;
2485 int per_ring_budget;
2486 bool clean_complete = true;
2487
2488#ifdef CONFIG_IXGBE_DCA
2489 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2490 ixgbe_update_dca(q_vector);
2491#endif
2492
2493 ixgbe_for_each_ring(ring, q_vector->tx)
2494 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
2495
2496 /* attempt to distribute budget to each queue fairly, but don't allow
2497 * the budget to go below 1 because we'll exit polling */
2498 if (q_vector->rx.count > 1)
2499 per_ring_budget = max(budget/q_vector->rx.count, 1);
2500 else
2501 per_ring_budget = budget;
2502
2503 ixgbe_for_each_ring(ring, q_vector->rx)
2504 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
2505 per_ring_budget);
2506
2507 /* If all work not completed, return budget and keep polling */
2508 if (!clean_complete)
2509 return budget;
2510
2511 /* all work done, exit the polling mode */
2512 napi_complete(napi);
2513 if (adapter->rx_itr_setting & 1)
2514 ixgbe_set_itr(q_vector);
2515 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2516 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
2517
2518 return 0;
2519}
2520
2521/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002522 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2523 * @adapter: board private structure
2524 *
2525 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2526 * interrupts from the kernel.
2527 **/
2528static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2529{
2530 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002531 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002532 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002533
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002534 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002535 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002536 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002537
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002538 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002539 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002540 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002541 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002542 } else if (q_vector->rx.ring) {
2543 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2544 "%s-%s-%d", netdev->name, "rx", ri++);
2545 } else if (q_vector->tx.ring) {
2546 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2547 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002548 } else {
2549 /* skip this unused q_vector */
2550 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002551 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002552 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2553 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002554 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002555 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002556 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002557 goto free_queue_irqs;
2558 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002559 /* If Flow Director is enabled, set interrupt affinity */
2560 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2561 /* assign the mask for this irq */
2562 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002563 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002564 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002565 }
2566
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002567 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002568 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002569 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002570 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002571 goto free_queue_irqs;
2572 }
2573
2574 return 0;
2575
2576free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002577 while (vector) {
2578 vector--;
2579 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2580 NULL);
2581 free_irq(adapter->msix_entries[vector].vector,
2582 adapter->q_vector[vector]);
2583 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002584 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2585 pci_disable_msix(adapter->pdev);
2586 kfree(adapter->msix_entries);
2587 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002588 return err;
2589}
2590
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002591/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002592 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002593 * @irq: interrupt number
2594 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002595 **/
2596static irqreturn_t ixgbe_intr(int irq, void *data)
2597{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002598 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002599 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002600 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002601 u32 eicr;
2602
Don Skidmore54037502009-02-21 15:42:56 -08002603 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002604 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002605 * before the read of EICR.
2606 */
2607 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2608
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002609 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002610 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002611 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002612 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002613 /*
2614 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002615 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002616 * have disabled interrupts due to EIAM
2617 * finish the workaround of silicon errata on 82598. Unmask
2618 * the interrupt that we masked before the EICR read.
2619 */
2620 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2621 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002622 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002623 }
Auke Kok9a799d72007-09-15 14:07:45 -07002624
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002625 if (eicr & IXGBE_EICR_LSC)
2626 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002627
Alexander Duyckbd508172010-11-16 19:27:03 -08002628 switch (hw->mac.type) {
2629 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002630 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002631 /* Fall through */
2632 case ixgbe_mac_X540:
2633 if (eicr & IXGBE_EICR_ECC)
2634 e_info(link, "Received unrecoverable ECC err, please "
2635 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002636 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002637 break;
2638 default:
2639 break;
2640 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002641
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002642 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00002643 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
2644 ixgbe_ptp_check_pps_event(adapter, eicr);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002645
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002646 /* would disable interrupts here but EIAM disabled it */
2647 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002648
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002649 /*
2650 * re-enable link(maybe) and non-queue interrupts, no flush.
2651 * ixgbe_poll will re-enable the queue interrupts
2652 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002653 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2654 ixgbe_irq_enable(adapter, false, false);
2655
Auke Kok9a799d72007-09-15 14:07:45 -07002656 return IRQ_HANDLED;
2657}
2658
2659/**
2660 * ixgbe_request_irq - initialize interrupts
2661 * @adapter: board private structure
2662 *
2663 * Attempts to configure interrupts using the best available
2664 * capabilities of the hardware and kernel.
2665 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002666static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002667{
2668 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002669 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002670
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002671 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002672 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002673 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002674 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002675 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002676 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002677 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002678 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002679
Alexander Duyckde88eee2012-02-08 07:49:59 +00002680 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002681 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002682
Auke Kok9a799d72007-09-15 14:07:45 -07002683 return err;
2684}
2685
2686static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2687{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002688 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07002689
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002690 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002691 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002692 return;
Auke Kok9a799d72007-09-15 14:07:45 -07002693 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002694
2695 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
2696 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2697 struct msix_entry *entry = &adapter->msix_entries[vector];
2698
2699 /* free only the irqs that were actually requested */
2700 if (!q_vector->rx.ring && !q_vector->tx.ring)
2701 continue;
2702
2703 /* clear the affinity_mask in the IRQ descriptor */
2704 irq_set_affinity_hint(entry->vector, NULL);
2705
2706 free_irq(entry->vector, q_vector);
2707 }
2708
2709 free_irq(adapter->msix_entries[vector++].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002710}
2711
2712/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002713 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2714 * @adapter: board private structure
2715 **/
2716static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2717{
Alexander Duyckbd508172010-11-16 19:27:03 -08002718 switch (adapter->hw.mac.type) {
2719 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002720 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002721 break;
2722 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002723 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002724 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2725 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002726 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002727 break;
2728 default:
2729 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002730 }
2731 IXGBE_WRITE_FLUSH(&adapter->hw);
2732 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002733 int vector;
2734
2735 for (vector = 0; vector < adapter->num_q_vectors; vector++)
2736 synchronize_irq(adapter->msix_entries[vector].vector);
2737
2738 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002739 } else {
2740 synchronize_irq(adapter->pdev->irq);
2741 }
2742}
2743
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002744/**
Auke Kok9a799d72007-09-15 14:07:45 -07002745 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2746 *
2747 **/
2748static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2749{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002750 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002751
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002752 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002753
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002754 ixgbe_set_ivar(adapter, 0, 0, 0);
2755 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002756
Emil Tantilov396e7992010-07-01 20:05:12 +00002757 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002758}
2759
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002760/**
2761 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2762 * @adapter: board private structure
2763 * @ring: structure containing ring specific data
2764 *
2765 * Configure the Tx descriptor ring after a reset.
2766 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002767void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2768 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002769{
2770 struct ixgbe_hw *hw = &adapter->hw;
2771 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002772 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002773 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002774 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002775
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002776 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002777 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002778 IXGBE_WRITE_FLUSH(hw);
2779
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002780 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002781 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002782 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2783 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2784 ring->count * sizeof(union ixgbe_adv_tx_desc));
2785 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2786 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002787 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002788
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002789 /*
2790 * set WTHRESH to encourage burst writeback, it should not be set
2791 * higher than 1 when ITR is 0 as it could cause false TX hangs
2792 *
2793 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2794 * to or less than the number of on chip descriptors, which is
2795 * currently 40.
2796 */
Alexander Duycke954b372012-02-08 07:49:38 +00002797 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002798 txdctl |= (1 << 16); /* WTHRESH = 1 */
2799 else
2800 txdctl |= (8 << 16); /* WTHRESH = 8 */
2801
Alexander Duycke954b372012-02-08 07:49:38 +00002802 /*
2803 * Setting PTHRESH to 32 both improves performance
2804 * and avoids a TX hang with DFP enabled
2805 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002806 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2807 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002808
2809 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00002810 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002811 ring->atr_sample_rate = adapter->atr_sample_rate;
2812 ring->atr_count = 0;
2813 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2814 } else {
2815 ring->atr_sample_rate = 0;
2816 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002817
John Fastabendc84d3242010-11-16 19:27:12 -08002818 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2819
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002820 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002821 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2822
2823 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2824 if (hw->mac.type == ixgbe_mac_82598EB &&
2825 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2826 return;
2827
2828 /* poll to verify queue is enabled */
2829 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002830 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002831 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2832 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2833 if (!wait_loop)
2834 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002835}
2836
Alexander Duyck120ff942010-08-19 13:34:50 +00002837static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2838{
2839 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002840 u32 rttdcs, mtqc;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002841 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002842
2843 if (hw->mac.type == ixgbe_mac_82598EB)
2844 return;
2845
2846 /* disable the arbiter while setting MTQC */
2847 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2848 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2849 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2850
2851 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002852 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
2853 mtqc = IXGBE_MTQC_VT_ENA;
2854 if (tcs > 4)
2855 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2856 else if (tcs > 1)
2857 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2858 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
2859 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002860 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002861 mtqc |= IXGBE_MTQC_64VF;
2862 } else {
2863 if (tcs > 4)
2864 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2865 else if (tcs > 1)
2866 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2867 else
2868 mtqc = IXGBE_MTQC_64Q_1PB;
2869 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00002870
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002871 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00002872
Alexander Duyck671c0ad2012-05-18 06:34:02 +00002873 /* Enable Security TX Buffer IFG for multiple pb */
2874 if (tcs) {
2875 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2876 sectx |= IXGBE_SECTX_DCB;
2877 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00002878 }
2879
2880 /* re-enable the arbiter */
2881 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2882 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2883}
2884
Auke Kok9a799d72007-09-15 14:07:45 -07002885/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002886 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002887 * @adapter: board private structure
2888 *
2889 * Configure the Tx unit of the MAC after a reset.
2890 **/
2891static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2892{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002893 struct ixgbe_hw *hw = &adapter->hw;
2894 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002895 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002896
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002897 ixgbe_setup_mtqc(adapter);
2898
2899 if (hw->mac.type != ixgbe_mac_82598EB) {
2900 /* DMATXCTL.EN must be before Tx queues are enabled */
2901 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2902 dmatxctl |= IXGBE_DMATXCTL_TE;
2903 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2904 }
2905
Auke Kok9a799d72007-09-15 14:07:45 -07002906 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002907 for (i = 0; i < adapter->num_tx_queues; i++)
2908 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002909}
2910
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00002911static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
2912 struct ixgbe_ring *ring)
2913{
2914 struct ixgbe_hw *hw = &adapter->hw;
2915 u8 reg_idx = ring->reg_idx;
2916 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2917
2918 srrctl |= IXGBE_SRRCTL_DROP_EN;
2919
2920 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2921}
2922
2923static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
2924 struct ixgbe_ring *ring)
2925{
2926 struct ixgbe_hw *hw = &adapter->hw;
2927 u8 reg_idx = ring->reg_idx;
2928 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
2929
2930 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
2931
2932 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
2933}
2934
2935#ifdef CONFIG_IXGBE_DCB
2936void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2937#else
2938static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
2939#endif
2940{
2941 int i;
2942 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
2943
2944 if (adapter->ixgbe_ieee_pfc)
2945 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
2946
2947 /*
2948 * We should set the drop enable bit if:
2949 * SR-IOV is enabled
2950 * or
2951 * Number of Rx queues > 1 and flow control is disabled
2952 *
2953 * This allows us to avoid head of line blocking for security
2954 * and performance reasons.
2955 */
2956 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
2957 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
2958 for (i = 0; i < adapter->num_rx_queues; i++)
2959 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
2960 } else {
2961 for (i = 0; i < adapter->num_rx_queues; i++)
2962 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
2963 }
2964}
2965
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002966#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002967
Yi Zoua6616b42009-08-06 13:05:23 +00002968static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002969 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002970{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002971 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002972 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002973 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002974
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002975 if (hw->mac.type == ixgbe_mac_82598EB) {
2976 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
2977
2978 /*
2979 * if VMDq is not active we must program one srrctl register
2980 * per RSS queue since we have enabled RDRXCTL.MVMEN
2981 */
2982 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002983 }
2984
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002985 /* configure header buffer length, needed for RSC */
2986 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002987
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002988 /* configure the packet buffer length */
Alexander Duyckf8003262012-03-03 02:35:52 +00002989 srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002990
2991 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00002992 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002993
Alexander Duyck45e9baa2012-05-05 05:30:59 +00002994 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002995}
2996
Alexander Duyck05abb122010-08-19 13:35:41 +00002997static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002998{
Alexander Duyck05abb122010-08-19 13:35:41 +00002999 struct ixgbe_hw *hw = &adapter->hw;
3000 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00003001 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
3002 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00003003 u32 mrqc = 0, reta = 0;
3004 u32 rxcsum;
3005 int i, j;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003006 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
John Fastabend86b4db32011-04-26 07:26:19 +00003007
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003008 /*
3009 * Program table for at least 2 queues w/ SR-IOV so that VFs can
3010 * make full use of any rings they may have. We will use the
3011 * PSRTYPE register to control how many rings we use within the PF.
3012 */
3013 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
3014 rss_i = 2;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003015
Alexander Duyck05abb122010-08-19 13:35:41 +00003016 /* Fill out hash function seeds */
3017 for (i = 0; i < 10; i++)
3018 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003019
Alexander Duyck05abb122010-08-19 13:35:41 +00003020 /* Fill out redirection table */
3021 for (i = 0, j = 0; i < 128; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003022 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003023 j = 0;
3024 /* reta = 4-byte sliding window of
3025 * 0x00..(indices-1)(indices-1)00..etc. */
3026 reta = (reta << 8) | (j * 0x11);
3027 if ((i & 3) == 3)
3028 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3029 }
3030
3031 /* Disable indicating checksum in descriptor, enables RSS hash */
3032 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3033 rxcsum |= IXGBE_RXCSUM_PCSD;
3034 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3035
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003036 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003037 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003038 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003039 } else {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003040 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003041
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003042 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3043 if (tcs > 4)
3044 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3045 else if (tcs > 1)
3046 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
3047 else if (adapter->ring_feature[RING_F_RSS].indices == 4)
3048 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3049 else
3050 mrqc = IXGBE_MRQC_VMDQRSS64EN;
3051 } else {
3052 if (tcs > 4)
3053 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3054 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003055 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3056 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003057 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003058 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003059 }
3060
Alexander Duyck05abb122010-08-19 13:35:41 +00003061 /* Perform hash on these packet types */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003062 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3063 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3064 IXGBE_MRQC_RSS_FIELD_IPV6 |
3065 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003066
Alexander Duyckef6afc02012-02-08 07:51:53 +00003067 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
3068 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
3069 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
3070 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
3071
Alexander Duyck05abb122010-08-19 13:35:41 +00003072 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003073}
3074
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003075/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003076 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3077 * @adapter: address of board private structure
3078 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003079 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003080static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003081 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003082{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003083 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003084 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003085 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003086
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003087 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003088 return;
3089
Alexander Duyck73670962010-08-19 13:38:34 +00003090 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003091 rscctrl |= IXGBE_RSCCTL_RSCEN;
3092 /*
3093 * we must limit the number of descriptors so that the
3094 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003095 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003096 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003097 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003098 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003099}
3100
Alexander Duyck9e10e042010-08-19 13:40:06 +00003101#define IXGBE_MAX_RX_DESC_POLL 10
3102static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3103 struct ixgbe_ring *ring)
3104{
3105 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003106 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3107 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003108 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003109
3110 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3111 if (hw->mac.type == ixgbe_mac_82598EB &&
3112 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3113 return;
3114
3115 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003116 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003117 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3118 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3119
3120 if (!wait_loop) {
3121 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3122 "the polling period\n", reg_idx);
3123 }
3124}
3125
Yi Zou2d39d572011-01-06 14:29:56 +00003126void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3127 struct ixgbe_ring *ring)
3128{
3129 struct ixgbe_hw *hw = &adapter->hw;
3130 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3131 u32 rxdctl;
3132 u8 reg_idx = ring->reg_idx;
3133
3134 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3135 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3136
3137 /* write value back with RXDCTL.ENABLE bit cleared */
3138 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3139
3140 if (hw->mac.type == ixgbe_mac_82598EB &&
3141 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3142 return;
3143
3144 /* the hardware may take up to 100us to really disable the rx queue */
3145 do {
3146 udelay(10);
3147 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3148 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3149
3150 if (!wait_loop) {
3151 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3152 "the polling period\n", reg_idx);
3153 }
3154}
3155
Alexander Duyck84418e32010-08-19 13:40:54 +00003156void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3157 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003158{
3159 struct ixgbe_hw *hw = &adapter->hw;
3160 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003161 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003162 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003163
Alexander Duyck9e10e042010-08-19 13:40:06 +00003164 /* disable queue to avoid issues while updating state */
3165 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003166 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003167
Alexander Duyckacd37172010-08-19 13:36:05 +00003168 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3169 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3170 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3171 ring->count * sizeof(union ixgbe_adv_rx_desc));
3172 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3173 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003174 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003175
3176 ixgbe_configure_srrctl(adapter, ring);
3177 ixgbe_configure_rscctl(adapter, ring);
3178
3179 if (hw->mac.type == ixgbe_mac_82598EB) {
3180 /*
3181 * enable cache line friendly hardware writes:
3182 * PTHRESH=32 descriptors (half the internal cache),
3183 * this also removes ugly rx_no_buffer_count increment
3184 * HTHRESH=4 descriptors (to minimize latency on fetch)
3185 * WTHRESH=8 burst writeback up to two cache lines
3186 */
3187 rxdctl &= ~0x3FFFFF;
3188 rxdctl |= 0x080420;
3189 }
3190
3191 /* enable receive descriptor ring */
3192 rxdctl |= IXGBE_RXDCTL_ENABLE;
3193 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3194
3195 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003196 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003197}
3198
Alexander Duyck48654522010-08-19 13:36:27 +00003199static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3200{
3201 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003202 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
Alexander Duyck48654522010-08-19 13:36:27 +00003203 int p;
3204
3205 /* PSRTYPE must be initialized in non 82598 adapters */
3206 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003207 IXGBE_PSRTYPE_UDPHDR |
3208 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003209 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003210 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003211
3212 if (hw->mac.type == ixgbe_mac_82598EB)
3213 return;
3214
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003215 if (rss_i > 3)
3216 psrtype |= 2 << 29;
3217 else if (rss_i > 1)
3218 psrtype |= 1 << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00003219
3220 for (p = 0; p < adapter->num_rx_pools; p++)
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003221 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(p)),
Alexander Duyck48654522010-08-19 13:36:27 +00003222 psrtype);
3223}
3224
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003225static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3226{
3227 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003228 u32 reg_offset, vf_shift;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003229 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003230 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003231
3232 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3233 return;
3234
3235 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00003236 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
3237 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003238 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00003239 vmdctl |= IXGBE_VT_CTL_REPLEN;
3240 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003241
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003242 vf_shift = VMDQ_P(0) % 32;
3243 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003244
3245 /* Enable only the PF's pool for Tx/Rx */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003246 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
3247 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
3248 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
3249 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003250
3251 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003252 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003253
3254 /*
3255 * Set up VF register offsets for selected VT Mode,
3256 * i.e. 32 or 64 VFs for SR-IOV
3257 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00003258 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
3259 case IXGBE_82599_VMDQ_8Q_MASK:
3260 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
3261 break;
3262 case IXGBE_82599_VMDQ_4Q_MASK:
3263 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
3264 break;
3265 default:
3266 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
3267 break;
3268 }
3269
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003270 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3271
Alexander Duyck435b19f2012-05-18 06:34:08 +00003272
Greg Rosea985b6c32010-11-18 03:02:52 +00003273 /* Enable MAC Anti-Spoofing */
Alexander Duyck435b19f2012-05-18 06:34:08 +00003274 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003275 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003276 /* For VFs that have spoof checking turned off */
3277 for (i = 0; i < adapter->num_vfs; i++) {
3278 if (!adapter->vfinfo[i].spoofchk_enabled)
3279 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3280 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003281}
3282
Alexander Duyck477de6e2010-08-19 13:38:11 +00003283static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003284{
Auke Kok9a799d72007-09-15 14:07:45 -07003285 struct ixgbe_hw *hw = &adapter->hw;
3286 struct net_device *netdev = adapter->netdev;
3287 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003288 struct ixgbe_ring *rx_ring;
3289 int i;
3290 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003291
Alexander Duyck477de6e2010-08-19 13:38:11 +00003292#ifdef IXGBE_FCOE
3293 /* adjust max frame to be able to do baby jumbo for FCoE */
3294 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3295 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3296 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3297
3298#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00003299
3300 /* adjust max frame to be at least the size of a standard frame */
3301 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
3302 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
3303
Alexander Duyck477de6e2010-08-19 13:38:11 +00003304 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3305 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3306 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3307 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3308
3309 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003310 }
3311
Auke Kok9a799d72007-09-15 14:07:45 -07003312 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003313 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3314 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003315 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3316
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003317 /*
3318 * Setup the HW Rx Head and Tail Descriptor Pointers and
3319 * the Base and Length of the Rx Descriptor Ring
3320 */
Auke Kok9a799d72007-09-15 14:07:45 -07003321 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003322 rx_ring = adapter->rx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003323 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3324 set_ring_rsc_enabled(rx_ring);
3325 else
3326 clear_ring_rsc_enabled(rx_ring);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003327 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003328}
3329
Alexander Duyck73670962010-08-19 13:38:34 +00003330static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3331{
3332 struct ixgbe_hw *hw = &adapter->hw;
3333 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3334
3335 switch (hw->mac.type) {
3336 case ixgbe_mac_82598EB:
3337 /*
3338 * For VMDq support of different descriptor types or
3339 * buffer sizes through the use of multiple SRRCTL
3340 * registers, RDRXCTL.MVMEN must be set to 1
3341 *
3342 * also, the manual doesn't mention it clearly but DCA hints
3343 * will only use queue 0's tags unless this bit is set. Side
3344 * effects of setting this bit are only that SRRCTL must be
3345 * fully programmed [0..15]
3346 */
3347 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3348 break;
3349 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003350 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003351 /* Disable RSC for ACK packets */
3352 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3353 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3354 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3355 /* hardware requires some bits to be set by default */
3356 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3357 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3358 break;
3359 default:
3360 /* We should do nothing since we don't know this hardware */
3361 return;
3362 }
3363
3364 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3365}
3366
Alexander Duyck477de6e2010-08-19 13:38:11 +00003367/**
3368 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3369 * @adapter: board private structure
3370 *
3371 * Configure the Rx unit of the MAC after a reset.
3372 **/
3373static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3374{
3375 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003376 int i;
3377 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003378
3379 /* disable receives while setting up the descriptors */
3380 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3381 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3382
3383 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003384 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003385
Alexander Duyck9e10e042010-08-19 13:40:06 +00003386 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003387 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003388
Alexander Duyck477de6e2010-08-19 13:38:11 +00003389 /* set_rx_buffer_len must be called before ring initialization */
3390 ixgbe_set_rx_buffer_len(adapter);
3391
3392 /*
3393 * Setup the HW Rx Head and Tail Descriptor Pointers and
3394 * the Base and Length of the Rx Descriptor Ring
3395 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003396 for (i = 0; i < adapter->num_rx_queues; i++)
3397 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003398
Alexander Duyck9e10e042010-08-19 13:40:06 +00003399 /* disable drop enable for 82598 parts */
3400 if (hw->mac.type == ixgbe_mac_82598EB)
3401 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3402
3403 /* enable all receives */
3404 rxctrl |= IXGBE_RXCTRL_RXEN;
3405 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003406}
3407
Jiri Pirko8e586132011-12-08 19:52:37 -05003408static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003409{
3410 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003411 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003412
3413 /* add VID to filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003414 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003415 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003416
3417 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003418}
3419
Jiri Pirko8e586132011-12-08 19:52:37 -05003420static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003421{
3422 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003423 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003424
Auke Kok9a799d72007-09-15 14:07:45 -07003425 /* remove VID from filter table */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003426 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003427 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003428
3429 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003430}
3431
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003432/**
3433 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3434 * @adapter: driver data
3435 */
3436static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3437{
3438 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003439 u32 vlnctrl;
3440
3441 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3442 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3443 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3444}
3445
3446/**
3447 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3448 * @adapter: driver data
3449 */
3450static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3451{
3452 struct ixgbe_hw *hw = &adapter->hw;
3453 u32 vlnctrl;
3454
3455 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3456 vlnctrl |= IXGBE_VLNCTRL_VFE;
3457 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3458 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3459}
3460
3461/**
3462 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3463 * @adapter: driver data
3464 */
3465static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3466{
3467 struct ixgbe_hw *hw = &adapter->hw;
3468 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003469 int i, j;
3470
3471 switch (hw->mac.type) {
3472 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003473 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3474 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003475 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3476 break;
3477 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003478 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003479 for (i = 0; i < adapter->num_rx_queues; i++) {
3480 j = adapter->rx_ring[i]->reg_idx;
3481 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3482 vlnctrl &= ~IXGBE_RXDCTL_VME;
3483 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3484 }
3485 break;
3486 default:
3487 break;
3488 }
3489}
3490
3491/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003492 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003493 * @adapter: driver data
3494 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003495static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003496{
3497 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003498 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003499 int i, j;
3500
3501 switch (hw->mac.type) {
3502 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003503 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3504 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003505 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3506 break;
3507 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003508 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003509 for (i = 0; i < adapter->num_rx_queues; i++) {
3510 j = adapter->rx_ring[i]->reg_idx;
3511 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3512 vlnctrl |= IXGBE_RXDCTL_VME;
3513 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3514 }
3515 break;
3516 default:
3517 break;
3518 }
3519}
3520
Auke Kok9a799d72007-09-15 14:07:45 -07003521static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3522{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003523 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003524
Jesse Grossf62bbb52010-10-20 13:56:10 +00003525 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3526
3527 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3528 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003529}
3530
3531/**
Alexander Duyck28500622010-06-15 09:25:48 +00003532 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3533 * @netdev: network interface device structure
3534 *
3535 * Writes unicast address list to the RAR table.
3536 * Returns: -ENOMEM on failure/insufficient address space
3537 * 0 on no addresses written
3538 * X on writing X addresses to the RAR table
3539 **/
3540static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3541{
3542 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3543 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend95447462012-05-31 12:42:26 +00003544 unsigned int rar_entries = hw->mac.num_rar_entries - 1;
Alexander Duyck28500622010-06-15 09:25:48 +00003545 int count = 0;
3546
John Fastabend95447462012-05-31 12:42:26 +00003547 /* In SR-IOV mode significantly less RAR entries are available */
3548 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3549 rar_entries = IXGBE_MAX_PF_MACVLANS - 1;
3550
Alexander Duyck28500622010-06-15 09:25:48 +00003551 /* return ENOMEM indicating insufficient memory for addresses */
3552 if (netdev_uc_count(netdev) > rar_entries)
3553 return -ENOMEM;
3554
John Fastabend95447462012-05-31 12:42:26 +00003555 if (!netdev_uc_empty(netdev)) {
Alexander Duyck28500622010-06-15 09:25:48 +00003556 struct netdev_hw_addr *ha;
3557 /* return error if we do not support writing to RAR table */
3558 if (!hw->mac.ops.set_rar)
3559 return -ENOMEM;
3560
3561 netdev_for_each_uc_addr(ha, netdev) {
3562 if (!rar_entries)
3563 break;
3564 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003565 VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck28500622010-06-15 09:25:48 +00003566 count++;
3567 }
3568 }
3569 /* write the addresses in reverse order to avoid write combining */
3570 for (; rar_entries > 0 ; rar_entries--)
3571 hw->mac.ops.clear_rar(hw, rar_entries);
3572
3573 return count;
3574}
3575
3576/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003577 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003578 * @netdev: network interface device structure
3579 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003580 * The set_rx_method entry point is called whenever the unicast/multicast
3581 * address list or the network interface flags are updated. This routine is
3582 * responsible for configuring the hardware for proper unicast, multicast and
3583 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003584 **/
Greg Rose7f870472010-01-09 02:25:29 +00003585void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003586{
3587 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3588 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003589 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3590 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003591
3592 /* Check for Promiscuous and All Multicast modes */
3593
3594 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3595
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003596 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00003597 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003598 fctrl |= IXGBE_FCTRL_BAM;
3599 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3600 fctrl |= IXGBE_FCTRL_PMCF;
3601
Alexander Duyck28500622010-06-15 09:25:48 +00003602 /* clear the bits we are changing the status of */
3603 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3604
Auke Kok9a799d72007-09-15 14:07:45 -07003605 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003606 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003607 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003608 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003609 /* don't hardware filter vlans in promisc mode */
3610 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003611 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003612 if (netdev->flags & IFF_ALLMULTI) {
3613 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003614 vmolr |= IXGBE_VMOLR_MPE;
3615 } else {
3616 /*
3617 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003618 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003619 * that we can at least receive multicast traffic
3620 */
3621 hw->mac.ops.update_mc_addr_list(hw, netdev);
3622 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003623 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003624 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003625 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00003626 }
3627
3628 /*
3629 * Write addresses to available RAR registers, if there is not
3630 * sufficient space to store all the addresses then enable
3631 * unicast promiscuous mode
3632 */
3633 count = ixgbe_write_uc_addr_list(netdev);
3634 if (count < 0) {
3635 fctrl |= IXGBE_FCTRL_UPE;
3636 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003637 }
3638
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003639 if (adapter->num_vfs)
Alexander Duyck28500622010-06-15 09:25:48 +00003640 ixgbe_restore_vf_multicasts(adapter);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003641
3642 if (hw->mac.type != ixgbe_mac_82598EB) {
3643 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00003644 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3645 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00003646 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003647 }
3648
Ben Greear3f2d1c02012-03-08 08:28:41 +00003649 /* This is useful for sniffing bad packets. */
3650 if (adapter->netdev->features & NETIF_F_RXALL) {
3651 /* UPE and MPE will be handled by normal PROMISC logic
3652 * in e1000e_set_rx_mode */
3653 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
3654 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
3655 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
3656
3657 fctrl &= ~(IXGBE_FCTRL_DPF);
3658 /* NOTE: VLAN filtering is disabled by setting PROMISC */
3659 }
3660
Auke Kok9a799d72007-09-15 14:07:45 -07003661 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003662
3663 if (netdev->features & NETIF_F_HW_VLAN_RX)
3664 ixgbe_vlan_strip_enable(adapter);
3665 else
3666 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003667}
3668
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003669static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3670{
3671 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003672
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003673 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3674 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003675}
3676
3677static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3678{
3679 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003680
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003681 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
3682 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003683}
3684
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003685#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003686/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08003687 * ixgbe_configure_dcb - Configure DCB hardware
3688 * @adapter: ixgbe adapter struct
3689 *
3690 * This is called by the driver on open to configure the DCB hardware.
3691 * This is also called by the gennetlink interface when reconfiguring
3692 * the DCB state.
3693 */
3694static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3695{
3696 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003697 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003698
Alexander Duyck67ebd792010-08-19 13:34:04 +00003699 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3700 if (hw->mac.type == ixgbe_mac_82598EB)
3701 netif_set_gso_max_size(adapter->netdev, 65536);
3702 return;
3703 }
3704
3705 if (hw->mac.type == ixgbe_mac_82598EB)
3706 netif_set_gso_max_size(adapter->netdev, 32768);
3707
John Fastabendb1208182011-10-15 05:00:10 +00003708#ifdef IXGBE_FCOE
3709 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3710 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3711#endif
3712
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003713 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003714 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003715 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3716 DCB_TX_CONFIG);
3717 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3718 DCB_RX_CONFIG);
3719 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003720 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3721 ixgbe_dcb_hw_ets(&adapter->hw,
3722 adapter->ixgbe_ieee_ets,
3723 max_frame);
3724 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3725 adapter->ixgbe_ieee_pfc->pfc_en,
3726 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003727 }
John Fastabend8187cd42011-02-23 05:58:08 +00003728
3729 /* Enable RSS Hash per TC */
3730 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00003731 u32 msb = 0;
3732 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003733
Alexander Duyckd411a932012-06-30 00:14:01 +00003734 while (rss_i) {
3735 msb++;
3736 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00003737 }
Alexander Duyckd411a932012-06-30 00:14:01 +00003738
Alexander Duyck4ae63732012-06-22 06:46:33 +00003739 /* write msb to all 8 TCs in one write */
3740 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00003741 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003742}
John Fastabend9da712d2011-08-23 03:14:22 +00003743#endif
3744
3745/* Additional bittime to account for IXGBE framing */
3746#define IXGBE_ETH_FRAMING 20
3747
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003748/**
John Fastabend9da712d2011-08-23 03:14:22 +00003749 * ixgbe_hpbthresh - calculate high water mark for flow control
3750 *
3751 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003752 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003753 */
3754static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3755{
3756 struct ixgbe_hw *hw = &adapter->hw;
3757 struct net_device *dev = adapter->netdev;
3758 int link, tc, kb, marker;
3759 u32 dv_id, rx_pba;
3760
3761 /* Calculate max LAN frame size */
3762 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3763
3764#ifdef IXGBE_FCOE
3765 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00003766 if ((dev->features & NETIF_F_FCOE_MTU) &&
3767 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
3768 (pb == ixgbe_fcoe_get_tc(adapter)))
3769 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003770
3771#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003772 /* Calculate delay value for device */
3773 switch (hw->mac.type) {
3774 case ixgbe_mac_X540:
3775 dv_id = IXGBE_DV_X540(link, tc);
3776 break;
3777 default:
3778 dv_id = IXGBE_DV(link, tc);
3779 break;
3780 }
3781
3782 /* Loopback switch introduces additional latency */
3783 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3784 dv_id += IXGBE_B2BT(tc);
3785
3786 /* Delay value is calculated in bit times convert to KB */
3787 kb = IXGBE_BT2KB(dv_id);
3788 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3789
3790 marker = rx_pba - kb;
3791
3792 /* It is possible that the packet buffer is not large enough
3793 * to provide required headroom. In this case throw an error
3794 * to user and a do the best we can.
3795 */
3796 if (marker < 0) {
3797 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3798 "headroom to support flow control."
3799 "Decrease MTU or number of traffic classes\n", pb);
3800 marker = tc + 1;
3801 }
3802
3803 return marker;
3804}
3805
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003806/**
John Fastabend9da712d2011-08-23 03:14:22 +00003807 * ixgbe_lpbthresh - calculate low water mark for for flow control
3808 *
3809 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003810 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00003811 */
3812static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3813{
3814 struct ixgbe_hw *hw = &adapter->hw;
3815 struct net_device *dev = adapter->netdev;
3816 int tc;
3817 u32 dv_id;
3818
3819 /* Calculate max LAN frame size */
3820 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3821
3822 /* Calculate delay value for device */
3823 switch (hw->mac.type) {
3824 case ixgbe_mac_X540:
3825 dv_id = IXGBE_LOW_DV_X540(tc);
3826 break;
3827 default:
3828 dv_id = IXGBE_LOW_DV(tc);
3829 break;
3830 }
3831
3832 /* Delay value is calculated in bit times convert to KB */
3833 return IXGBE_BT2KB(dv_id);
3834}
3835
3836/*
3837 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3838 */
3839static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3840{
3841 struct ixgbe_hw *hw = &adapter->hw;
3842 int num_tc = netdev_get_num_tc(adapter->netdev);
3843 int i;
3844
3845 if (!num_tc)
3846 num_tc = 1;
3847
3848 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3849
3850 for (i = 0; i < num_tc; i++) {
3851 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3852
3853 /* Low water marks must not be larger than high water marks */
3854 if (hw->fc.low_water > hw->fc.high_water[i])
3855 hw->fc.low_water = 0;
3856 }
3857}
John Fastabend80605c652011-05-02 12:34:10 +00003858
3859static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3860{
John Fastabend80605c652011-05-02 12:34:10 +00003861 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003862 int hdrm;
3863 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003864
3865 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3866 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003867 hdrm = 32 << adapter->fdir_pballoc;
3868 else
3869 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003870
Alexander Duyckf7e10272011-07-21 00:40:35 +00003871 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003872 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003873}
3874
Alexander Duycke4911d52011-05-11 07:18:52 +00003875static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3876{
3877 struct ixgbe_hw *hw = &adapter->hw;
3878 struct hlist_node *node, *node2;
3879 struct ixgbe_fdir_filter *filter;
3880
3881 spin_lock(&adapter->fdir_perfect_lock);
3882
3883 if (!hlist_empty(&adapter->fdir_filter_list))
3884 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3885
3886 hlist_for_each_entry_safe(filter, node, node2,
3887 &adapter->fdir_filter_list, fdir_node) {
3888 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003889 &filter->filter,
3890 filter->sw_idx,
3891 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3892 IXGBE_FDIR_DROP_QUEUE :
3893 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003894 }
3895
3896 spin_unlock(&adapter->fdir_perfect_lock);
3897}
3898
Auke Kok9a799d72007-09-15 14:07:45 -07003899static void ixgbe_configure(struct ixgbe_adapter *adapter)
3900{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003901 struct ixgbe_hw *hw = &adapter->hw;
3902
John Fastabend80605c652011-05-02 12:34:10 +00003903 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003904#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003905 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003906#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00003907 /*
3908 * We must restore virtualization before VLANs or else
3909 * the VLVF registers will not be populated
3910 */
3911 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003912
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003913 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003914 ixgbe_restore_vlan(adapter);
3915
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003916 switch (hw->mac.type) {
3917 case ixgbe_mac_82599EB:
3918 case ixgbe_mac_X540:
3919 hw->mac.ops.disable_rx_buff(hw);
3920 break;
3921 default:
3922 break;
3923 }
3924
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003925 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003926 ixgbe_init_fdir_signature_82599(&adapter->hw,
3927 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003928 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3929 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3930 adapter->fdir_pballoc);
3931 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003932 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003933
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003934 switch (hw->mac.type) {
3935 case ixgbe_mac_82599EB:
3936 case ixgbe_mac_X540:
3937 hw->mac.ops.enable_rx_buff(hw);
3938 break;
3939 default:
3940 break;
3941 }
3942
Alexander Duyck7c8ae652012-05-05 05:32:47 +00003943#ifdef IXGBE_FCOE
3944 /* configure FCoE L2 filters, redirection table, and Rx control */
3945 ixgbe_configure_fcoe(adapter);
3946
3947#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07003948 ixgbe_configure_tx(adapter);
3949 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003950}
3951
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003952static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3953{
3954 switch (hw->phy.type) {
3955 case ixgbe_phy_sfp_avago:
3956 case ixgbe_phy_sfp_ftl:
3957 case ixgbe_phy_sfp_intel:
3958 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003959 case ixgbe_phy_sfp_passive_tyco:
3960 case ixgbe_phy_sfp_passive_unknown:
3961 case ixgbe_phy_sfp_active_unknown:
3962 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003963 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003964 case ixgbe_phy_nl:
3965 if (hw->mac.type == ixgbe_mac_82598EB)
3966 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003967 default:
3968 return false;
3969 }
3970}
3971
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003972/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003973 * ixgbe_sfp_link_config - set up SFP+ link
3974 * @adapter: pointer to private adapter struct
3975 **/
3976static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3977{
Alexander Duyck70864002011-04-27 09:13:56 +00003978 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003979 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003980 * is that an SFP was inserted/removed after the reset
3981 * but before SFP detection was enabled. As such the best
3982 * solution is to just start searching as soon as we start
3983 */
3984 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3985 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003986
Alexander Duyck70864002011-04-27 09:13:56 +00003987 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003988}
3989
3990/**
3991 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003992 * @hw: pointer to private hardware struct
3993 *
3994 * Returns 0 on success, negative on failure
3995 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003996static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003997{
3998 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003999 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004000 u32 ret = IXGBE_ERR_LINK_SETUP;
4001
4002 if (hw->mac.ops.check_link)
4003 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
4004
4005 if (ret)
4006 goto link_cfg_out;
4007
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00004008 autoneg = hw->phy.autoneg_advertised;
4009 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00004010 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
4011 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004012 if (ret)
4013 goto link_cfg_out;
4014
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00004015 if (hw->mac.ops.setup_link)
4016 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08004017link_cfg_out:
4018 return ret;
4019}
4020
Alexander Duycka34bcff2010-08-19 13:39:20 +00004021static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004022{
Auke Kok9a799d72007-09-15 14:07:45 -07004023 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004024 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004025
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004026 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00004027 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
4028 IXGBE_GPIE_OCD;
4029 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004030 /*
4031 * use EIAM to auto-mask when MSI-X interrupt is asserted
4032 * this saves a register write for every interrupt
4033 */
4034 switch (hw->mac.type) {
4035 case ixgbe_mac_82598EB:
4036 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
4037 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004038 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004039 case ixgbe_mac_X540:
4040 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00004041 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
4042 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
4043 break;
4044 }
4045 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004046 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
4047 * specifically only auto mask tx and rx interrupts */
4048 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004049 }
4050
Alexander Duycka34bcff2010-08-19 13:39:20 +00004051 /* XXX: to interrupt immediately for EICS writes, enable this */
4052 /* gpie |= IXGBE_GPIE_EIMEN; */
4053
4054 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
4055 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00004056
4057 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4058 case IXGBE_82599_VMDQ_8Q_MASK:
4059 gpie |= IXGBE_GPIE_VTMODE_16;
4060 break;
4061 case IXGBE_82599_VMDQ_4Q_MASK:
4062 gpie |= IXGBE_GPIE_VTMODE_32;
4063 break;
4064 default:
4065 gpie |= IXGBE_GPIE_VTMODE_64;
4066 break;
4067 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004068 }
4069
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004070 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00004071 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
4072 switch (adapter->hw.mac.type) {
4073 case ixgbe_mac_82599EB:
4074 gpie |= IXGBE_SDP0_GPIEN;
4075 break;
4076 case ixgbe_mac_X540:
4077 gpie |= IXGBE_EIMS_TS;
4078 break;
4079 default:
4080 break;
4081 }
4082 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00004083
Alexander Duycka34bcff2010-08-19 13:39:20 +00004084 /* Enable fan failure interrupt */
4085 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004086 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07004087
Don Skidmore2698b202011-04-13 07:01:52 +00004088 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004089 gpie |= IXGBE_SDP1_GPIEN;
4090 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00004091 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00004092
4093 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
4094}
4095
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004096static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00004097{
4098 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004099 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00004100 u32 ctrl_ext;
4101
4102 ixgbe_get_hw_control(adapter);
4103 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004104
Auke Kok9a799d72007-09-15 14:07:45 -07004105 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4106 ixgbe_configure_msix(adapter);
4107 else
4108 ixgbe_configure_msi_and_legacy(adapter);
4109
Emil Tantilovec74a472012-09-20 03:33:56 +00004110 /* enable the optics for 82599 SFP+ fiber */
4111 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00004112 hw->mac.ops.enable_tx_laser(hw);
4113
Auke Kok9a799d72007-09-15 14:07:45 -07004114 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004115 ixgbe_napi_enable_all(adapter);
4116
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08004117 if (ixgbe_is_sfp(hw)) {
4118 ixgbe_sfp_link_config(adapter);
4119 } else {
4120 err = ixgbe_non_sfp_link_config(hw);
4121 if (err)
4122 e_err(probe, "link_config FAILED %d\n", err);
4123 }
4124
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004125 /* clear any pending interrupts, may auto mask */
4126 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00004127 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07004128
PJ Waskiewicze8e26352009-02-27 15:45:05 +00004129 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00004130 * If this adapter has a fan, check to see if we had a failure
4131 * before we enabled the interrupt.
4132 */
4133 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
4134 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
4135 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00004136 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00004137 }
4138
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004139 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00004140 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08004141
Auke Kok9a799d72007-09-15 14:07:45 -07004142 /* bring the link up in the watchdog, this could race with our first
4143 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004144 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
4145 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004146 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004147
4148 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4149 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4150 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4151 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07004152}
4153
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004154void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4155{
4156 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004157 /* put off any impending NetWatchDogTimeout */
4158 adapter->netdev->trans_start = jiffies;
4159
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004160 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004161 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004162 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004163 /*
4164 * If SR-IOV enabled then wait a bit before bringing the adapter
4165 * back up to give the VFs time to respond to the reset. The
4166 * two second wait is based upon the watchdog timer cycle in
4167 * the VF driver.
4168 */
4169 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4170 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004171 ixgbe_up(adapter);
4172 clear_bit(__IXGBE_RESETTING, &adapter->state);
4173}
4174
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004175void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004176{
4177 /* hardware has been reset, we need to reload some things */
4178 ixgbe_configure(adapter);
4179
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004180 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004181}
4182
4183void ixgbe_reset(struct ixgbe_adapter *adapter)
4184{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004185 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004186 int err;
4187
Alexander Duyck70864002011-04-27 09:13:56 +00004188 /* lock SFP init bit to prevent race conditions with the watchdog */
4189 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4190 usleep_range(1000, 2000);
4191
4192 /* clear all SFP and link config related flags while holding SFP_INIT */
4193 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4194 IXGBE_FLAG2_SFP_NEEDS_RESET);
4195 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4196
Don Skidmore8ca783a2009-05-26 20:40:47 -07004197 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004198 switch (err) {
4199 case 0:
4200 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004201 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004202 break;
4203 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004204 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004205 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004206 case IXGBE_ERR_EEPROM_VERSION:
4207 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004208 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004209 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004210 "your hardware. If you are experiencing problems "
4211 "please contact your Intel or hardware "
4212 "representative who provided you with this "
4213 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004214 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004215 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004216 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004217 }
Auke Kok9a799d72007-09-15 14:07:45 -07004218
Alexander Duyck70864002011-04-27 09:13:56 +00004219 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4220
Auke Kok9a799d72007-09-15 14:07:45 -07004221 /* reprogram the RAR[0] in case user changed it. */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004222 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00004223
4224 /* update SAN MAC vmdq pool selection */
4225 if (hw->mac.san_mac_rar_index)
4226 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00004227
Jacob Keller1a71ab22012-08-25 03:54:19 +00004228 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
4229 ixgbe_ptp_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004230}
4231
Auke Kok9a799d72007-09-15 14:07:45 -07004232/**
4233 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004234 * @rx_ring: ring to free buffers from
4235 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004236static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004237{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004238 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004239 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004240 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004241
Alexander Duyck84418e32010-08-19 13:40:54 +00004242 /* ring already cleared, nothing to do */
4243 if (!rx_ring->rx_buffer_info)
4244 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004245
Alexander Duyck84418e32010-08-19 13:40:54 +00004246 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004247 for (i = 0; i < rx_ring->count; i++) {
Alexander Duyckf8003262012-03-03 02:35:52 +00004248 struct ixgbe_rx_buffer *rx_buffer;
Auke Kok9a799d72007-09-15 14:07:45 -07004249
Alexander Duyckf8003262012-03-03 02:35:52 +00004250 rx_buffer = &rx_ring->rx_buffer_info[i];
4251 if (rx_buffer->skb) {
4252 struct sk_buff *skb = rx_buffer->skb;
4253 if (IXGBE_CB(skb)->page_released) {
4254 dma_unmap_page(dev,
4255 IXGBE_CB(skb)->dma,
4256 ixgbe_rx_bufsz(rx_ring),
4257 DMA_FROM_DEVICE);
4258 IXGBE_CB(skb)->page_released = false;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004259 }
4260 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004261 }
Alexander Duyckf8003262012-03-03 02:35:52 +00004262 rx_buffer->skb = NULL;
4263 if (rx_buffer->dma)
4264 dma_unmap_page(dev, rx_buffer->dma,
4265 ixgbe_rx_pg_size(rx_ring),
4266 DMA_FROM_DEVICE);
4267 rx_buffer->dma = 0;
4268 if (rx_buffer->page)
Alexander Duyckdd411ec2012-04-06 04:24:50 +00004269 __free_pages(rx_buffer->page,
4270 ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00004271 rx_buffer->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07004272 }
4273
4274 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4275 memset(rx_ring->rx_buffer_info, 0, size);
4276
4277 /* Zero out the descriptor ring */
4278 memset(rx_ring->desc, 0, rx_ring->size);
4279
Alexander Duyckf8003262012-03-03 02:35:52 +00004280 rx_ring->next_to_alloc = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004281 rx_ring->next_to_clean = 0;
4282 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004283}
4284
4285/**
4286 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004287 * @tx_ring: ring to be cleaned
4288 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004289static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004290{
4291 struct ixgbe_tx_buffer *tx_buffer_info;
4292 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004293 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004294
Alexander Duyck84418e32010-08-19 13:40:54 +00004295 /* ring already cleared, nothing to do */
4296 if (!tx_ring->tx_buffer_info)
4297 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004298
Alexander Duyck84418e32010-08-19 13:40:54 +00004299 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004300 for (i = 0; i < tx_ring->count; i++) {
4301 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004302 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004303 }
4304
John Fastabenddad8a3b2012-04-23 12:22:39 +00004305 netdev_tx_reset_queue(txring_txq(tx_ring));
4306
Auke Kok9a799d72007-09-15 14:07:45 -07004307 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4308 memset(tx_ring->tx_buffer_info, 0, size);
4309
4310 /* Zero out the descriptor ring */
4311 memset(tx_ring->desc, 0, tx_ring->size);
4312
4313 tx_ring->next_to_use = 0;
4314 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004315}
4316
4317/**
Auke Kok9a799d72007-09-15 14:07:45 -07004318 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4319 * @adapter: board private structure
4320 **/
4321static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4322{
4323 int i;
4324
4325 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004326 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004327}
4328
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004329/**
4330 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4331 * @adapter: board private structure
4332 **/
4333static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4334{
4335 int i;
4336
4337 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004338 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004339}
4340
Alexander Duycke4911d52011-05-11 07:18:52 +00004341static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4342{
4343 struct hlist_node *node, *node2;
4344 struct ixgbe_fdir_filter *filter;
4345
4346 spin_lock(&adapter->fdir_perfect_lock);
4347
4348 hlist_for_each_entry_safe(filter, node, node2,
4349 &adapter->fdir_filter_list, fdir_node) {
4350 hlist_del(&filter->fdir_node);
4351 kfree(filter);
4352 }
4353 adapter->fdir_filter_count = 0;
4354
4355 spin_unlock(&adapter->fdir_perfect_lock);
4356}
4357
Auke Kok9a799d72007-09-15 14:07:45 -07004358void ixgbe_down(struct ixgbe_adapter *adapter)
4359{
4360 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004361 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004362 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004363 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004364
4365 /* signal that we are down to the interrupt handler */
4366 set_bit(__IXGBE_DOWN, &adapter->state);
4367
4368 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004369 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4370 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004371
Yi Zou2d39d572011-01-06 14:29:56 +00004372 /* disable all enabled rx queues */
4373 for (i = 0; i < adapter->num_rx_queues; i++)
4374 /* this call also flushes the previous write */
4375 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4376
Don Skidmore032b4322011-03-18 09:32:53 +00004377 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004378
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004379 netif_tx_stop_all_queues(netdev);
4380
Alexander Duyck70864002011-04-27 09:13:56 +00004381 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004382 netif_carrier_off(netdev);
4383 netif_tx_disable(netdev);
4384
4385 ixgbe_irq_disable(adapter);
4386
4387 ixgbe_napi_disable_all(adapter);
4388
Alexander Duyckd034acf2011-04-27 09:25:34 +00004389 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4390 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004391 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4392
4393 del_timer_sync(&adapter->service_timer);
4394
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004395 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004396 /* Clear EITR Select mapping */
4397 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4398
4399 /* Mark all the VFs as inactive */
4400 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004401 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004402
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004403 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004404 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004405
Auke Kok9a799d72007-09-15 14:07:45 -07004406 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004407 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004408 }
4409
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004410 /* disable transmits in the hardware now that interrupts are off */
4411 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004412 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004413 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004414 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004415
4416 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004417 switch (hw->mac.type) {
4418 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004419 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004420 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004421 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4422 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004423 break;
4424 default:
4425 break;
4426 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004427
Paul Larson6f4a0e42008-06-24 17:00:56 -07004428 if (!pci_channel_offline(adapter->pdev))
4429 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004430
Emil Tantilovec74a472012-09-20 03:33:56 +00004431 /* power down the optics for 82599 SFP+ fiber */
4432 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00004433 hw->mac.ops.disable_tx_laser(hw);
4434
Auke Kok9a799d72007-09-15 14:07:45 -07004435 ixgbe_clean_all_tx_rings(adapter);
4436 ixgbe_clean_all_rx_rings(adapter);
4437
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004438#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004439 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004440 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004441#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004442}
4443
Auke Kok9a799d72007-09-15 14:07:45 -07004444/**
Auke Kok9a799d72007-09-15 14:07:45 -07004445 * ixgbe_tx_timeout - Respond to a Tx Hang
4446 * @netdev: network interface device structure
4447 **/
4448static void ixgbe_tx_timeout(struct net_device *netdev)
4449{
4450 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4451
4452 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004453 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004454}
4455
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004456/**
Auke Kok9a799d72007-09-15 14:07:45 -07004457 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
4458 * @adapter: board private structure to initialize
4459 *
4460 * ixgbe_sw_init initializes the Adapter private data structure.
4461 * Fields are initialized based on PCI device information and
4462 * OS network device settings (MTU size).
4463 **/
4464static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
4465{
4466 struct ixgbe_hw *hw = &adapter->hw;
4467 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004468 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004469#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08004470 int j;
4471 struct tc_configuration *tc;
4472#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004473
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004474 /* PCI config space info */
4475
4476 hw->vendor_id = pdev->vendor;
4477 hw->device_id = pdev->device;
4478 hw->revision_id = pdev->revision;
4479 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4480 hw->subsystem_device_id = pdev->subsystem_device;
4481
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004482 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004483 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00004484 adapter->ring_feature[RING_F_RSS].limit = rss;
Alexander Duyckbd508172010-11-16 19:27:03 -08004485 switch (hw->mac.type) {
4486 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00004487 if (hw->device_id == IXGBE_DEV_ID_82598AT)
4488 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004489 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08004490 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08004491 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00004492 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
4493 case ixgbe_mac_82599EB:
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004494 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00004495 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
4496 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004497 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
4498 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004499 /* Flow Director hash filters enabled */
Alexander Duyck45b9f502011-01-06 14:29:59 +00004500 adapter->atr_sample_rate = 20;
Alexander Duyckc0876632012-05-10 00:01:46 +00004501 adapter->ring_feature[RING_F_FDIR].limit =
Joe Perchese8e9f692010-09-07 21:34:53 +00004502 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00004503 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00004504#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00004505 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
4506 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
Yi Zou61a0f422009-12-03 11:32:22 +00004507#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00004508 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00004509 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00004510#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00004511#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08004512 break;
4513 default:
4514 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004515 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08004516
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004517#ifdef IXGBE_FCOE
4518 /* FCoE support exists, always init the FCoE lock */
4519 spin_lock_init(&adapter->fcoe.lock);
4520
4521#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00004522 /* n-tuple support exists, always init our spinlock */
4523 spin_lock_init(&adapter->fdir_perfect_lock);
4524
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004525#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00004526 switch (hw->mac.type) {
4527 case ixgbe_mac_X540:
4528 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
4529 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
4530 break;
4531 default:
4532 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
4533 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
4534 break;
4535 }
4536
Alexander Duyck2f90b862008-11-20 20:52:10 -08004537 /* Configure DCB traffic classes */
4538 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
4539 tc = &adapter->dcb_cfg.tc_config[j];
4540 tc->path[DCB_TX_CONFIG].bwg_id = 0;
4541 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
4542 tc->path[DCB_RX_CONFIG].bwg_id = 0;
4543 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
4544 tc->dcb_pfc = pfc_disabled;
4545 }
John Fastabend4de2a022011-09-27 03:52:01 +00004546
4547 /* Initialize default user to priority mapping, UPx->TC0 */
4548 tc = &adapter->dcb_cfg.tc_config[0];
4549 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
4550 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
4551
Alexander Duyck2f90b862008-11-20 20:52:10 -08004552 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
4553 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00004554 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08004555 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00004556 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
John Fastabendf525c6d22012-04-18 22:42:27 +00004557 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
4558 sizeof(adapter->temp_dcb_cfg));
Alexander Duyck2f90b862008-11-20 20:52:10 -08004559
4560#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004561
4562 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00004563 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00004564 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00004565 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07004566 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
4567 hw->fc.send_xon = true;
Jacob Kellerdb2adc22012-10-24 07:26:02 +00004568 hw->fc.disable_fc_autoneg =
4569 (ixgbe_device_supports_autoneg_fc(hw) == 0) ? false : true;
Auke Kok9a799d72007-09-15 14:07:45 -07004570
Alexander Duyck99d74482012-05-09 08:09:25 +00004571#ifdef CONFIG_PCI_IOV
4572 /* assign number of SR-IOV VFs */
4573 if (hw->mac.type != ixgbe_mac_82598EB)
4574 adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
4575
4576#endif
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004577 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004578 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004579 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004580
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07004581 /* set default ring sizes */
4582 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
4583 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
4584
Alexander Duyckbd198052011-06-11 01:45:08 +00004585 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00004586 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00004587
Auke Kok9a799d72007-09-15 14:07:45 -07004588 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004589 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004590 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004591 return -EIO;
4592 }
4593
Auke Kok9a799d72007-09-15 14:07:45 -07004594 set_bit(__IXGBE_DOWN, &adapter->state);
4595
4596 return 0;
4597}
4598
4599/**
4600 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004601 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004602 *
4603 * Return 0 on success, negative on failure
4604 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004605int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004606{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004607 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004608 int orig_node = dev_to_node(dev);
4609 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07004610 int size;
4611
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004612 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004613
4614 if (tx_ring->q_vector)
4615 numa_node = tx_ring->q_vector->numa_node;
4616
4617 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004618 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004619 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004620 if (!tx_ring->tx_buffer_info)
4621 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004622
4623 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08004624 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004625 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004626
Alexander Duyckde88eee2012-02-08 07:49:59 +00004627 set_dev_node(dev, numa_node);
4628 tx_ring->desc = dma_alloc_coherent(dev,
4629 tx_ring->size,
4630 &tx_ring->dma,
4631 GFP_KERNEL);
4632 set_dev_node(dev, orig_node);
4633 if (!tx_ring->desc)
4634 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
4635 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004636 if (!tx_ring->desc)
4637 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004638
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004639 tx_ring->next_to_use = 0;
4640 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004641 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004642
4643err:
4644 vfree(tx_ring->tx_buffer_info);
4645 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004646 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07004647 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004648}
4649
4650/**
Alexander Duyck69888672008-09-11 20:05:39 -07004651 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
4652 * @adapter: board private structure
4653 *
4654 * If this function returns with an error, then it's possible one or
4655 * more of the rings is populated (while the rest are not). It is the
4656 * callers duty to clean those orphaned rings.
4657 *
4658 * Return 0 on success, negative on failure
4659 **/
4660static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
4661{
4662 int i, err = 0;
4663
4664 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004665 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004666 if (!err)
4667 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004668
Emil Tantilov396e7992010-07-01 20:05:12 +00004669 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004670 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07004671 }
4672
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004673 return 0;
4674err_setup_tx:
4675 /* rewind the index freeing the rings as we go */
4676 while (i--)
4677 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004678 return err;
4679}
4680
4681/**
Auke Kok9a799d72007-09-15 14:07:45 -07004682 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004683 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07004684 *
4685 * Returns 0 on success, negative on failure
4686 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004687int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004688{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004689 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004690 int orig_node = dev_to_node(dev);
4691 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004692 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07004693
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004694 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00004695
4696 if (rx_ring->q_vector)
4697 numa_node = rx_ring->q_vector->numa_node;
4698
4699 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004700 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00004701 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004702 if (!rx_ring->rx_buffer_info)
4703 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004704
Auke Kok9a799d72007-09-15 14:07:45 -07004705 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004706 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
4707 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07004708
Alexander Duyckde88eee2012-02-08 07:49:59 +00004709 set_dev_node(dev, numa_node);
4710 rx_ring->desc = dma_alloc_coherent(dev,
4711 rx_ring->size,
4712 &rx_ring->dma,
4713 GFP_KERNEL);
4714 set_dev_node(dev, orig_node);
4715 if (!rx_ring->desc)
4716 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
4717 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004718 if (!rx_ring->desc)
4719 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07004720
Jesse Brandeburg3a581072008-08-26 04:27:08 -07004721 rx_ring->next_to_clean = 0;
4722 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004723
4724 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004725err:
4726 vfree(rx_ring->rx_buffer_info);
4727 rx_ring->rx_buffer_info = NULL;
4728 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004729 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07004730}
4731
4732/**
Alexander Duyck69888672008-09-11 20:05:39 -07004733 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
4734 * @adapter: board private structure
4735 *
4736 * If this function returns with an error, then it's possible one or
4737 * more of the rings is populated (while the rest are not). It is the
4738 * callers duty to clean those orphaned rings.
4739 *
4740 * Return 0 on success, negative on failure
4741 **/
Alexander Duyck69888672008-09-11 20:05:39 -07004742static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
4743{
4744 int i, err = 0;
4745
4746 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004747 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004748 if (!err)
4749 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004750
Emil Tantilov396e7992010-07-01 20:05:12 +00004751 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004752 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07004753 }
4754
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004755#ifdef IXGBE_FCOE
4756 err = ixgbe_setup_fcoe_ddp_resources(adapter);
4757 if (!err)
4758#endif
4759 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004760err_setup_rx:
4761 /* rewind the index freeing the rings as we go */
4762 while (i--)
4763 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07004764 return err;
4765}
4766
4767/**
Auke Kok9a799d72007-09-15 14:07:45 -07004768 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004769 * @tx_ring: Tx descriptor ring for a specific queue
4770 *
4771 * Free all transmit software resources
4772 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004773void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004774{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004775 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004776
4777 vfree(tx_ring->tx_buffer_info);
4778 tx_ring->tx_buffer_info = NULL;
4779
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004780 /* if not set, then don't free */
4781 if (!tx_ring->desc)
4782 return;
4783
4784 dma_free_coherent(tx_ring->dev, tx_ring->size,
4785 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004786
4787 tx_ring->desc = NULL;
4788}
4789
4790/**
4791 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
4792 * @adapter: board private structure
4793 *
4794 * Free all transmit software resources
4795 **/
4796static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
4797{
4798 int i;
4799
4800 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004801 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004802 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004803}
4804
4805/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07004806 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07004807 * @rx_ring: ring to clean the resources from
4808 *
4809 * Free all receive software resources
4810 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004811void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004812{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004813 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004814
4815 vfree(rx_ring->rx_buffer_info);
4816 rx_ring->rx_buffer_info = NULL;
4817
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004818 /* if not set, then don't free */
4819 if (!rx_ring->desc)
4820 return;
4821
4822 dma_free_coherent(rx_ring->dev, rx_ring->size,
4823 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07004824
4825 rx_ring->desc = NULL;
4826}
4827
4828/**
4829 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
4830 * @adapter: board private structure
4831 *
4832 * Free all receive software resources
4833 **/
4834static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
4835{
4836 int i;
4837
Alexander Duyck7c8ae652012-05-05 05:32:47 +00004838#ifdef IXGBE_FCOE
4839 ixgbe_free_fcoe_ddp_resources(adapter);
4840
4841#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004842 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004843 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004844 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004845}
4846
4847/**
Auke Kok9a799d72007-09-15 14:07:45 -07004848 * ixgbe_change_mtu - Change the Maximum Transfer Unit
4849 * @netdev: network interface device structure
4850 * @new_mtu: new value for maximum frame size
4851 *
4852 * Returns 0 on success, negative on failure
4853 **/
4854static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
4855{
4856 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4857 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
4858
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07004859 /* MTU < 68 is an error and causes problems on some kernels */
Alexander Duyck655309e2012-02-08 07:50:35 +00004860 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
4861 return -EINVAL;
4862
4863 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00004864 * For 82599EB we cannot allow legacy VFs to enable their receive
4865 * paths when MTU greater than 1500 is configured. So display a
4866 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00004867 */
4868 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
4869 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
4870 (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
Alexander Duyck872844d2012-08-15 02:10:43 +00004871 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07004872
Emil Tantilov396e7992010-07-01 20:05:12 +00004873 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00004874
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004875 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07004876 netdev->mtu = new_mtu;
4877
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004878 if (netif_running(netdev))
4879 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004880
4881 return 0;
4882}
4883
4884/**
4885 * ixgbe_open - Called when a network interface is made active
4886 * @netdev: network interface device structure
4887 *
4888 * Returns 0 on success, negative value on failure
4889 *
4890 * The open entry point is called when a network interface is made
4891 * active by the system (IFF_UP). At this point all resources needed
4892 * for transmit and receive operations are allocated, the interrupt
4893 * handler is registered with the OS, the watchdog timer is started,
4894 * and the stack is notified that the interface is ready.
4895 **/
4896static int ixgbe_open(struct net_device *netdev)
4897{
4898 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4899 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07004900
Auke Kok4bebfaa2008-02-11 09:26:01 -08004901 /* disallow open during test */
4902 if (test_bit(__IXGBE_TESTING, &adapter->state))
4903 return -EBUSY;
4904
Jesse Brandeburg54386462009-04-17 20:44:27 +00004905 netif_carrier_off(netdev);
4906
Auke Kok9a799d72007-09-15 14:07:45 -07004907 /* allocate transmit descriptors */
4908 err = ixgbe_setup_all_tx_resources(adapter);
4909 if (err)
4910 goto err_setup_tx;
4911
Auke Kok9a799d72007-09-15 14:07:45 -07004912 /* allocate receive descriptors */
4913 err = ixgbe_setup_all_rx_resources(adapter);
4914 if (err)
4915 goto err_setup_rx;
4916
4917 ixgbe_configure(adapter);
4918
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004919 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004920 if (err)
4921 goto err_req_irq;
4922
Alexander Duyckac802f52012-07-12 05:52:53 +00004923 /* Notify the stack of the actual queue counts. */
4924 err = netif_set_real_num_tx_queues(netdev,
4925 adapter->num_rx_pools > 1 ? 1 :
4926 adapter->num_tx_queues);
4927 if (err)
4928 goto err_set_queues;
4929
4930
4931 err = netif_set_real_num_rx_queues(netdev,
4932 adapter->num_rx_pools > 1 ? 1 :
4933 adapter->num_rx_queues);
4934 if (err)
4935 goto err_set_queues;
4936
Jacob Keller1a71ab22012-08-25 03:54:19 +00004937 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00004938
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004939 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004940
4941 return 0;
4942
Alexander Duyckac802f52012-07-12 05:52:53 +00004943err_set_queues:
4944 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004945err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004946 ixgbe_free_all_rx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004947err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00004948 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00004949err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07004950 ixgbe_reset(adapter);
4951
4952 return err;
4953}
4954
4955/**
4956 * ixgbe_close - Disables a network interface
4957 * @netdev: network interface device structure
4958 *
4959 * Returns 0, this is not allowed to fail
4960 *
4961 * The close entry point is called when an interface is de-activated
4962 * by the OS. The hardware is still under the drivers control, but
4963 * needs to be disabled. A global MAC reset is issued to stop the
4964 * hardware, and all transmit and receive resources are freed.
4965 **/
4966static int ixgbe_close(struct net_device *netdev)
4967{
4968 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07004969
Jacob Keller1a71ab22012-08-25 03:54:19 +00004970 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00004971
Auke Kok9a799d72007-09-15 14:07:45 -07004972 ixgbe_down(adapter);
4973 ixgbe_free_irq(adapter);
4974
Alexander Duycke4911d52011-05-11 07:18:52 +00004975 ixgbe_fdir_filter_exit(adapter);
4976
Auke Kok9a799d72007-09-15 14:07:45 -07004977 ixgbe_free_all_tx_resources(adapter);
4978 ixgbe_free_all_rx_resources(adapter);
4979
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08004980 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004981
4982 return 0;
4983}
4984
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004985#ifdef CONFIG_PM
4986static int ixgbe_resume(struct pci_dev *pdev)
4987{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08004988 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
4989 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07004990 u32 err;
4991
4992 pci_set_power_state(pdev, PCI_D0);
4993 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08004994 /*
4995 * pci_restore_state clears dev->state_saved so call
4996 * pci_save_state to restore it.
4997 */
4998 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00004999
5000 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005001 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005002 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005003 return err;
5004 }
5005 pci_set_master(pdev);
5006
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005007 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005008
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005009 ixgbe_reset(adapter);
5010
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005011 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5012
Alexander Duyckac802f52012-07-12 05:52:53 +00005013 rtnl_lock();
5014 err = ixgbe_init_interrupt_scheme(adapter);
5015 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005016 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00005017
5018 rtnl_unlock();
5019
5020 if (err)
5021 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005022
5023 netif_device_attach(netdev);
5024
5025 return 0;
5026}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005027#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005028
5029static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005030{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005031 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5032 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005033 struct ixgbe_hw *hw = &adapter->hw;
5034 u32 ctrl, fctrl;
5035 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005036#ifdef CONFIG_PM
5037 int retval = 0;
5038#endif
5039
5040 netif_device_detach(netdev);
5041
5042 if (netif_running(netdev)) {
Don Skidmoreab6039a2012-03-17 05:51:52 +00005043 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005044 ixgbe_down(adapter);
5045 ixgbe_free_irq(adapter);
5046 ixgbe_free_all_tx_resources(adapter);
5047 ixgbe_free_all_rx_resources(adapter);
Don Skidmoreab6039a2012-03-17 05:51:52 +00005048 rtnl_unlock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005049 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005050
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005051 ixgbe_clear_interrupt_scheme(adapter);
5052
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005053#ifdef CONFIG_PM
5054 retval = pci_save_state(pdev);
5055 if (retval)
5056 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005057
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005058#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005059 if (wufc) {
5060 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005061
Emil Tantilovec74a472012-09-20 03:33:56 +00005062 /* enable the optics for 82599 SFP+ fiber as we can WoL */
5063 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00005064 hw->mac.ops.enable_tx_laser(hw);
5065
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005066 /* turn on all-multi mode if wake on multicast is enabled */
5067 if (wufc & IXGBE_WUFC_MC) {
5068 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5069 fctrl |= IXGBE_FCTRL_MPE;
5070 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5071 }
5072
5073 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5074 ctrl |= IXGBE_CTRL_GIO_DIS;
5075 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5076
5077 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5078 } else {
5079 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5080 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5081 }
5082
Alexander Duyckbd508172010-11-16 19:27:03 -08005083 switch (hw->mac.type) {
5084 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005085 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005086 break;
5087 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005088 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005089 pci_wake_from_d3(pdev, !!wufc);
5090 break;
5091 default:
5092 break;
5093 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005094
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005095 *enable_wake = !!wufc;
5096
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005097 ixgbe_release_hw_control(adapter);
5098
5099 pci_disable_device(pdev);
5100
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005101 return 0;
5102}
5103
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005104#ifdef CONFIG_PM
5105static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5106{
5107 int retval;
5108 bool wake;
5109
5110 retval = __ixgbe_shutdown(pdev, &wake);
5111 if (retval)
5112 return retval;
5113
5114 if (wake) {
5115 pci_prepare_to_sleep(pdev);
5116 } else {
5117 pci_wake_from_d3(pdev, false);
5118 pci_set_power_state(pdev, PCI_D3hot);
5119 }
5120
5121 return 0;
5122}
5123#endif /* CONFIG_PM */
5124
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005125static void ixgbe_shutdown(struct pci_dev *pdev)
5126{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005127 bool wake;
5128
5129 __ixgbe_shutdown(pdev, &wake);
5130
5131 if (system_state == SYSTEM_POWER_OFF) {
5132 pci_wake_from_d3(pdev, wake);
5133 pci_set_power_state(pdev, PCI_D3hot);
5134 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005135}
5136
5137/**
Auke Kok9a799d72007-09-15 14:07:45 -07005138 * ixgbe_update_stats - Update the board statistics counters.
5139 * @adapter: board private structure
5140 **/
5141void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5142{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005143 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005144 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005145 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005146 u64 total_mpc = 0;
5147 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005148 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5149 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005150 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005151
Don Skidmored08935c2010-06-11 13:20:29 +00005152 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5153 test_bit(__IXGBE_RESETTING, &adapter->state))
5154 return;
5155
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005156 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005157 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005158 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005159 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005160 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5161 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005162 }
5163 adapter->rsc_total_count = rsc_count;
5164 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005165 }
5166
Alexander Duyck5b7da512010-11-16 19:26:50 -08005167 for (i = 0; i < adapter->num_rx_queues; i++) {
5168 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5169 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5170 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5171 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005172 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005173 bytes += rx_ring->stats.bytes;
5174 packets += rx_ring->stats.packets;
5175 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005176 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005177 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5178 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005179 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005180 netdev->stats.rx_bytes = bytes;
5181 netdev->stats.rx_packets = packets;
5182
5183 bytes = 0;
5184 packets = 0;
5185 /* gather some stats to the adapter struct that are per queue */
5186 for (i = 0; i < adapter->num_tx_queues; i++) {
5187 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5188 restart_queue += tx_ring->tx_stats.restart_queue;
5189 tx_busy += tx_ring->tx_stats.tx_busy;
5190 bytes += tx_ring->stats.bytes;
5191 packets += tx_ring->stats.packets;
5192 }
5193 adapter->restart_queue = restart_queue;
5194 adapter->tx_busy = tx_busy;
5195 netdev->stats.tx_bytes = bytes;
5196 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005197
Joe Perches7ca647b2010-09-07 21:35:40 +00005198 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005199
5200 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005201 for (i = 0; i < 8; i++) {
5202 /* for packet buffers not used, the register should read 0 */
5203 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5204 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005205 hwstats->mpc[i] += mpc;
5206 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005207 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5208 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005209 switch (hw->mac.type) {
5210 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005211 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5212 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5213 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005214 hwstats->pxonrxc[i] +=
5215 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005216 break;
5217 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005218 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005219 hwstats->pxonrxc[i] +=
5220 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005221 break;
5222 default:
5223 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005224 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005225 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005226
5227 /*16 register reads */
5228 for (i = 0; i < 16; i++) {
5229 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5230 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5231 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5232 (hw->mac.type == ixgbe_mac_X540)) {
5233 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5234 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5235 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5236 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5237 }
5238 }
5239
Joe Perches7ca647b2010-09-07 21:35:40 +00005240 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005241 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005242 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005243
John Fastabendc84d3242010-11-16 19:27:12 -08005244 ixgbe_update_xoff_received(adapter);
5245
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005246 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005247 switch (hw->mac.type) {
5248 case ixgbe_mac_82598EB:
5249 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005250 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5251 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5252 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5253 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005254 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005255 /* OS2BMC stats are X540 only*/
5256 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5257 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5258 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5259 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5260 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00005261 for (i = 0; i < 16; i++)
5262 adapter->hw_rx_no_dma_resources +=
5263 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005264 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005265 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005266 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005267 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005268 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005269 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005270 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005271 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5272 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005273#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005274 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5275 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5276 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5277 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5278 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5279 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005280 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005281 if (adapter->fcoe.ddp_pool) {
5282 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5283 struct ixgbe_fcoe_ddp_pool *ddp_pool;
5284 unsigned int cpu;
5285 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005286 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005287 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
5288 noddp += ddp_pool->noddp;
5289 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005290 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00005291 hwstats->fcoe_noddp = noddp;
5292 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005293 }
Yi Zou6d455222009-05-13 13:12:16 +00005294#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005295 break;
5296 default:
5297 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005298 }
Auke Kok9a799d72007-09-15 14:07:45 -07005299 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005300 hwstats->bprc += bprc;
5301 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005302 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005303 hwstats->mprc -= bprc;
5304 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5305 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5306 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5307 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5308 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5309 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5310 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5311 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005312 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005313 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005314 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005315 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005316 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5317 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005318 /*
5319 * 82598 errata - tx of flow control packets is included in tx counters
5320 */
5321 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005322 hwstats->gptc -= xon_off_tot;
5323 hwstats->mptc -= xon_off_tot;
5324 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5325 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5326 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5327 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5328 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5329 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5330 hwstats->ptc64 -= xon_off_tot;
5331 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5332 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5333 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5334 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5335 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5336 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005337
5338 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005339 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005340
5341 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005342 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005343 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005344 netdev->stats.rx_length_errors = hwstats->rlec;
5345 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005346 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005347}
5348
5349/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005350 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005351 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005352 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005353static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005354{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005355 struct ixgbe_hw *hw = &adapter->hw;
5356 int i;
5357
Alexander Duyckd034acf2011-04-27 09:25:34 +00005358 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5359 return;
5360
5361 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5362
5363 /* if interface is down do nothing */
5364 if (test_bit(__IXGBE_DOWN, &adapter->state))
5365 return;
5366
5367 /* do nothing if we are not using signature filters */
5368 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5369 return;
5370
5371 adapter->fdir_overflow++;
5372
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005373 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5374 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005375 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005376 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005377 /* re-enable flow director interrupts */
5378 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005379 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005380 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005381 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005382 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005383}
5384
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005385/**
5386 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005387 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005388 *
5389 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005390 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005391 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005392 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005393 */
5394static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5395{
Auke Kok9a799d72007-09-15 14:07:45 -07005396 struct ixgbe_hw *hw = &adapter->hw;
5397 u64 eics = 0;
5398 int i;
5399
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005400 /* If we're down or resetting, just bail */
5401 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5402 test_bit(__IXGBE_RESETTING, &adapter->state))
5403 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005404
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005405 /* Force detection of hung controller */
5406 if (netif_carrier_ok(adapter->netdev)) {
5407 for (i = 0; i < adapter->num_tx_queues; i++)
5408 set_check_for_tx_hang(adapter->tx_ring[i]);
5409 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005410
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005411 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005412 /*
5413 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005414 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005415 * would set *both* EIMS and EICS for any bit in EIAM
5416 */
5417 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5418 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005419 } else {
5420 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00005421 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005422 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00005423 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005424 eics |= ((u64)1 << i);
5425 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005426 }
5427
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005428 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005429 ixgbe_irq_rearm_queues(adapter, eics);
5430
Alexander Duyckfe49f042009-06-04 16:00:09 +00005431}
5432
5433/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005434 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005435 * @adapter: pointer to the device adapter structure
5436 * @link_speed: pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005437 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005438static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005439{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005440 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005441 u32 link_speed = adapter->link_speed;
5442 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00005443 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005444
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005445 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5446 return;
5447
5448 if (hw->mac.ops.check_link) {
5449 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005450 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005451 /* always assume link is up, if no check link function */
5452 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5453 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005454 }
Alexander Duyck041441d2012-04-19 17:48:48 +00005455
5456 if (adapter->ixgbe_ieee_pfc)
5457 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
5458
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005459 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00005460 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00005461 ixgbe_set_rx_drop_en(adapter);
5462 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005463
5464 if (link_up ||
5465 time_after(jiffies, (adapter->link_check_timeout +
5466 IXGBE_TRY_LINK_TIMEOUT))) {
5467 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5468 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5469 IXGBE_WRITE_FLUSH(hw);
5470 }
5471
5472 adapter->link_up = link_up;
5473 adapter->link_speed = link_speed;
5474}
5475
Alexander Duyck107d3012012-10-02 00:17:03 +00005476static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
5477{
5478#ifdef CONFIG_IXGBE_DCB
5479 struct net_device *netdev = adapter->netdev;
5480 struct dcb_app app = {
5481 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
5482 .protocol = 0,
5483 };
5484 u8 up = 0;
5485
5486 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
5487 up = dcb_ieee_getapp_mask(netdev, &app);
5488
5489 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
5490#endif
5491}
5492
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005493/**
5494 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5495 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005496 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005497 **/
5498static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5499{
5500 struct net_device *netdev = adapter->netdev;
5501 struct ixgbe_hw *hw = &adapter->hw;
5502 u32 link_speed = adapter->link_speed;
5503 bool flow_rx, flow_tx;
5504
5505 /* only continue if link was previously down */
5506 if (netif_carrier_ok(netdev))
5507 return;
5508
5509 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5510
5511 switch (hw->mac.type) {
5512 case ixgbe_mac_82598EB: {
5513 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5514 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5515 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5516 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5517 }
5518 break;
5519 case ixgbe_mac_X540:
5520 case ixgbe_mac_82599EB: {
5521 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5522 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5523 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5524 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5525 }
5526 break;
5527 default:
5528 flow_tx = false;
5529 flow_rx = false;
5530 break;
5531 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005532
Jacob Keller1a71ab22012-08-25 03:54:19 +00005533 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5534 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005535
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005536 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5537 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5538 "10 Gbps" :
5539 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5540 "1 Gbps" :
5541 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
5542 "100 Mbps" :
5543 "unknown speed"))),
5544 ((flow_rx && flow_tx) ? "RX/TX" :
5545 (flow_rx ? "RX" :
5546 (flow_tx ? "TX" : "None"))));
5547
5548 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005549 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005550
Alexander Duyck107d3012012-10-02 00:17:03 +00005551 /* update the default user priority for VFs */
5552 ixgbe_update_default_up(adapter);
5553
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005554 /* ping all the active vfs to let them know link has changed */
5555 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005556}
5557
5558/**
5559 * ixgbe_watchdog_link_is_down - update netif_carrier status and
5560 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005561 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005562 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00005563static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005564{
5565 struct net_device *netdev = adapter->netdev;
5566 struct ixgbe_hw *hw = &adapter->hw;
5567
5568 adapter->link_up = false;
5569 adapter->link_speed = 0;
5570
5571 /* only continue if link was up previously */
5572 if (!netif_carrier_ok(netdev))
5573 return;
5574
5575 /* poll for SFP+ cable when link is down */
5576 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
5577 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
5578
Jacob Keller1a71ab22012-08-25 03:54:19 +00005579 if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
5580 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005581
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005582 e_info(drv, "NIC Link is Down\n");
5583 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00005584
5585 /* ping all the active vfs to let them know link has changed */
5586 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005587}
5588
5589/**
5590 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005591 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005592 **/
5593static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
5594{
5595 int i;
5596 int some_tx_pending = 0;
5597
5598 if (!netif_carrier_ok(adapter->netdev)) {
5599 for (i = 0; i < adapter->num_tx_queues; i++) {
5600 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5601 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
5602 some_tx_pending = 1;
5603 break;
5604 }
5605 }
5606
5607 if (some_tx_pending) {
5608 /* We've lost link, so the controller stops DMA,
5609 * but we've got queued Tx work that's never going
5610 * to get done, so reset controller to flush Tx.
5611 * (Do the reset outside of interrupt context).
5612 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005613 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005614 }
5615 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005616}
5617
Greg Rosea985b6c32010-11-18 03:02:52 +00005618static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
5619{
5620 u32 ssvpc;
5621
Greg Rose0584d992012-08-08 00:00:58 +00005622 /* Do not perform spoof check for 82598 or if not in IOV mode */
5623 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
5624 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00005625 return;
5626
5627 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
5628
5629 /*
5630 * ssvpc register is cleared on read, if zero then no
5631 * spoofed packets in the last interval.
5632 */
5633 if (!ssvpc)
5634 return;
5635
Emil Tantilovd6ea0752012-08-08 06:28:37 +00005636 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00005637}
5638
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005639/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005640 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005641 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005642 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005643static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005644{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005645 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00005646 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5647 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005648 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005649
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005650 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00005651
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005652 if (adapter->link_up)
5653 ixgbe_watchdog_link_is_up(adapter);
5654 else
5655 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00005656
Greg Rosea985b6c32010-11-18 03:02:52 +00005657 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005658 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005659
5660 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005661}
5662
Alexander Duyck70864002011-04-27 09:13:56 +00005663/**
5664 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005665 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005666 **/
5667static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
5668{
5669 struct ixgbe_hw *hw = &adapter->hw;
5670 s32 err;
5671
5672 /* not searching for SFP so there is nothing to do here */
5673 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
5674 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5675 return;
5676
5677 /* someone else is in init, wait until next service event */
5678 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5679 return;
5680
5681 err = hw->phy.ops.identify_sfp(hw);
5682 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5683 goto sfp_out;
5684
5685 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
5686 /* If no cable is present, then we need to reset
5687 * the next time we find a good cable. */
5688 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
5689 }
5690
5691 /* exit on error */
5692 if (err)
5693 goto sfp_out;
5694
5695 /* exit if reset not needed */
5696 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
5697 goto sfp_out;
5698
5699 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
5700
5701 /*
5702 * A module may be identified correctly, but the EEPROM may not have
5703 * support for that module. setup_sfp() will fail in that case, so
5704 * we should not allow that module to load.
5705 */
5706 if (hw->mac.type == ixgbe_mac_82598EB)
5707 err = hw->phy.ops.reset(hw);
5708 else
5709 err = hw->mac.ops.setup_sfp(hw);
5710
5711 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
5712 goto sfp_out;
5713
5714 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
5715 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
5716
5717sfp_out:
5718 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5719
5720 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
5721 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
5722 e_dev_err("failed to initialize because an unsupported "
5723 "SFP+ module type was detected.\n");
5724 e_dev_err("Reload the driver after installing a "
5725 "supported module.\n");
5726 unregister_netdev(adapter->netdev);
5727 }
5728}
5729
5730/**
5731 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005732 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00005733 **/
5734static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
5735{
5736 struct ixgbe_hw *hw = &adapter->hw;
5737 u32 autoneg;
5738 bool negotiation;
5739
5740 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
5741 return;
5742
5743 /* someone else is in init, wait until next service event */
5744 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5745 return;
5746
5747 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5748
5749 autoneg = hw->phy.autoneg_advertised;
5750 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
5751 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00005752 if (hw->mac.ops.setup_link)
5753 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
5754
5755 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5756 adapter->link_check_timeout = jiffies;
5757 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
5758}
5759
Greg Rose83c61fa2011-09-07 05:59:35 +00005760#ifdef CONFIG_PCI_IOV
5761static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
5762{
5763 int vf;
5764 struct ixgbe_hw *hw = &adapter->hw;
5765 struct net_device *netdev = adapter->netdev;
5766 u32 gpc;
5767 u32 ciaa, ciad;
5768
5769 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
5770 if (gpc) /* If incrementing then no need for the check below */
5771 return;
5772 /*
5773 * Check to see if a bad DMA write target from an errant or
5774 * malicious VF has caused a PCIe error. If so then we can
5775 * issue a VFLR to the offending VF(s) and then resume without
5776 * requesting a full slot reset.
5777 */
5778
5779 for (vf = 0; vf < adapter->num_vfs; vf++) {
5780 ciaa = (vf << 16) | 0x80000000;
5781 /* 32 bit read so align, we really want status at offset 6 */
5782 ciaa |= PCI_COMMAND;
5783 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5784 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
5785 ciaa &= 0x7FFFFFFF;
5786 /* disable debug mode asap after reading data */
5787 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5788 /* Get the upper 16 bits which will be the PCI status reg */
5789 ciad >>= 16;
5790 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
5791 netdev_err(netdev, "VF %d Hung DMA\n", vf);
5792 /* Issue VFLR */
5793 ciaa = (vf << 16) | 0x80000000;
5794 ciaa |= 0xA8;
5795 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5796 ciad = 0x00008000; /* VFLR */
5797 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
5798 ciaa &= 0x7FFFFFFF;
5799 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
5800 }
5801 }
5802}
5803
5804#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005805/**
5806 * ixgbe_service_timer - Timer Call-back
5807 * @data: pointer to adapter cast into an unsigned long
5808 **/
5809static void ixgbe_service_timer(unsigned long data)
5810{
5811 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5812 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00005813 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00005814
5815 /* poll faster when waiting for link */
5816 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
5817 next_event_offset = HZ / 10;
5818 else
5819 next_event_offset = HZ * 2;
5820
Greg Rose83c61fa2011-09-07 05:59:35 +00005821#ifdef CONFIG_PCI_IOV
Alexander Duyck6bb78cf2012-02-08 07:51:22 +00005822 /*
5823 * don't bother with SR-IOV VF DMA hang check if there are
5824 * no VFs or the link is down
5825 */
5826 if (!adapter->num_vfs ||
5827 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5828 goto normal_timer_service;
5829
5830 /* If we have VFs allocated then we must check for DMA hangs */
5831 ixgbe_check_for_bad_vf(adapter);
5832 next_event_offset = HZ / 50;
5833 adapter->timer_event_accumulator++;
5834
5835 if (adapter->timer_event_accumulator >= 100)
5836 adapter->timer_event_accumulator = 0;
5837 else
5838 ready = false;
5839
5840normal_timer_service:
Greg Rose83c61fa2011-09-07 05:59:35 +00005841#endif
Alexander Duyck70864002011-04-27 09:13:56 +00005842 /* Reset the timer */
5843 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
5844
Greg Rose83c61fa2011-09-07 05:59:35 +00005845 if (ready)
5846 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005847}
5848
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005849static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
5850{
5851 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
5852 return;
5853
5854 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
5855
5856 /* If we're already down or resetting, just bail */
5857 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5858 test_bit(__IXGBE_RESETTING, &adapter->state))
5859 return;
5860
5861 ixgbe_dump(adapter);
5862 netdev_err(adapter->netdev, "Reset adapter\n");
5863 adapter->tx_timeout_count++;
5864
5865 ixgbe_reinit_locked(adapter);
5866}
5867
Alexander Duyck70864002011-04-27 09:13:56 +00005868/**
5869 * ixgbe_service_task - manages and runs subtasks
5870 * @work: pointer to work_struct containing our data
5871 **/
5872static void ixgbe_service_task(struct work_struct *work)
5873{
5874 struct ixgbe_adapter *adapter = container_of(work,
5875 struct ixgbe_adapter,
5876 service_task);
5877
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005878 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005879 ixgbe_sfp_detection_subtask(adapter);
5880 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00005881 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005882 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00005883 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005884 ixgbe_check_hang_subtask(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00005885 ixgbe_ptp_overflow_check(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00005886
5887 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005888}
5889
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005890static int ixgbe_tso(struct ixgbe_ring *tx_ring,
5891 struct ixgbe_tx_buffer *first,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005892 u8 *hdr_len)
Alexander Duyck897ab152011-05-27 05:31:47 +00005893{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005894 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005895 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07005896 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07005897
Alexander Duyck897ab152011-05-27 05:31:47 +00005898 if (!skb_is_gso(skb))
5899 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005900
Alexander Duyck897ab152011-05-27 05:31:47 +00005901 if (skb_header_cloned(skb)) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00005902 int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
Alexander Duyck897ab152011-05-27 05:31:47 +00005903 if (err)
5904 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00005905 }
5906
Alexander Duyck897ab152011-05-27 05:31:47 +00005907 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5908 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
5909
Alexander Duyck244e27a2012-02-08 07:51:11 +00005910 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005911 struct iphdr *iph = ip_hdr(skb);
5912 iph->tot_len = 0;
5913 iph->check = 0;
5914 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
5915 iph->daddr, 0,
5916 IPPROTO_TCP,
5917 0);
5918 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005919 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5920 IXGBE_TX_FLAGS_CSUM |
5921 IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00005922 } else if (skb_is_gso_v6(skb)) {
5923 ipv6_hdr(skb)->payload_len = 0;
5924 tcp_hdr(skb)->check =
5925 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
5926 &ipv6_hdr(skb)->daddr,
5927 0, IPPROTO_TCP, 0);
Alexander Duyck244e27a2012-02-08 07:51:11 +00005928 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
5929 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00005930 }
5931
Alexander Duyck091a6242012-02-08 07:51:01 +00005932 /* compute header lengths */
Alexander Duyck897ab152011-05-27 05:31:47 +00005933 l4len = tcp_hdrlen(skb);
5934 *hdr_len = skb_transport_offset(skb) + l4len;
5935
Alexander Duyck091a6242012-02-08 07:51:01 +00005936 /* update gso size and bytecount with header size */
5937 first->gso_segs = skb_shinfo(skb)->gso_segs;
5938 first->bytecount += (first->gso_segs - 1) * *hdr_len;
5939
Alexander Duyck897ab152011-05-27 05:31:47 +00005940 /* mss_l4len_id: use 1 as index for TSO */
5941 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
5942 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
5943 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
5944
5945 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
5946 vlan_macip_lens = skb_network_header_len(skb);
5947 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005948 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00005949
5950 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00005951 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00005952
5953 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00005954}
5955
Alexander Duyck244e27a2012-02-08 07:51:11 +00005956static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
5957 struct ixgbe_tx_buffer *first)
Auke Kok9a799d72007-09-15 14:07:45 -07005958{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00005959 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00005960 u32 vlan_macip_lens = 0;
5961 u32 mss_l4len_idx = 0;
5962 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005963
Alexander Duyck897ab152011-05-27 05:31:47 +00005964 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck62748b72012-07-20 08:09:01 +00005965 if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN)) {
5966 if (unlikely(skb->no_fcs))
5967 first->tx_flags |= IXGBE_TX_FLAGS_NO_IFCS;
5968 if (!(first->tx_flags & IXGBE_TX_FLAGS_TXSW))
5969 return;
5970 }
Alexander Duyck897ab152011-05-27 05:31:47 +00005971 } else {
5972 u8 l4_hdr = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00005973 switch (first->protocol) {
Alexander Duyck897ab152011-05-27 05:31:47 +00005974 case __constant_htons(ETH_P_IP):
5975 vlan_macip_lens |= skb_network_header_len(skb);
5976 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
5977 l4_hdr = ip_hdr(skb)->protocol;
5978 break;
5979 case __constant_htons(ETH_P_IPV6):
5980 vlan_macip_lens |= skb_network_header_len(skb);
5981 l4_hdr = ipv6_hdr(skb)->nexthdr;
5982 break;
5983 default:
5984 if (unlikely(net_ratelimit())) {
5985 dev_warn(tx_ring->dev,
5986 "partial checksum but proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00005987 first->protocol);
Alexander Duyck897ab152011-05-27 05:31:47 +00005988 }
5989 break;
5990 }
Auke Kok9a799d72007-09-15 14:07:45 -07005991
Alexander Duyck897ab152011-05-27 05:31:47 +00005992 switch (l4_hdr) {
5993 case IPPROTO_TCP:
5994 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
5995 mss_l4len_idx = tcp_hdrlen(skb) <<
5996 IXGBE_ADVTXD_L4LEN_SHIFT;
5997 break;
5998 case IPPROTO_SCTP:
5999 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6000 mss_l4len_idx = sizeof(struct sctphdr) <<
6001 IXGBE_ADVTXD_L4LEN_SHIFT;
6002 break;
6003 case IPPROTO_UDP:
6004 mss_l4len_idx = sizeof(struct udphdr) <<
6005 IXGBE_ADVTXD_L4LEN_SHIFT;
6006 break;
6007 default:
6008 if (unlikely(net_ratelimit())) {
6009 dev_warn(tx_ring->dev,
6010 "partial checksum but l4 proto=%x!\n",
Alexander Duyck244e27a2012-02-08 07:51:11 +00006011 l4_hdr);
Alexander Duyck897ab152011-05-27 05:31:47 +00006012 }
6013 break;
6014 }
Alexander Duyck244e27a2012-02-08 07:51:11 +00006015
6016 /* update TX checksum flag */
6017 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006018 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006019
Alexander Duyck244e27a2012-02-08 07:51:11 +00006020 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck897ab152011-05-27 05:31:47 +00006021 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006022 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006023
6024 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6025 type_tucmd, mss_l4len_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07006026}
6027
Alexander Duyckd3d00232011-07-15 02:31:25 +00006028static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6029{
6030 /* set type for advanced descriptor with frame checksum insertion */
6031 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
Alexander Duyckd3d00232011-07-15 02:31:25 +00006032 IXGBE_ADVTXD_DCMD_DEXT);
6033
6034 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006035 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006036 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6037
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006038 if (tx_flags & IXGBE_TX_FLAGS_TSTAMP)
6039 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_MAC_TSTAMP);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006040
Alexander Duyckd3d00232011-07-15 02:31:25 +00006041 /* set segmentation enable bits for TSO/FSO */
6042#ifdef IXGBE_FCOE
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006043 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FSO))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006044#else
6045 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6046#endif
6047 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6048
Alexander Duyck62748b72012-07-20 08:09:01 +00006049 /* insert frame checksum */
6050 if (!(tx_flags & IXGBE_TX_FLAGS_NO_IFCS))
6051 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_IFCS);
6052
Alexander Duyckd3d00232011-07-15 02:31:25 +00006053 return cmd_type;
6054}
6055
Alexander Duyck729739b2012-02-08 07:51:06 +00006056static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
6057 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006058{
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006059 __le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006060
6061 /* enable L4 checksum for TSO and TX checksum offload */
6062 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6063 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6064
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006065 /* enble IPv4 checksum for TSO */
6066 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6067 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006068
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006069 /* use index 1 context for TSO/FSO/FCOE */
6070#ifdef IXGBE_FCOE
6071 if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_FCOE))
6072#else
6073 if (tx_flags & IXGBE_TX_FLAGS_TSO)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006074#endif
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006075 olinfo_status |= cpu_to_le32(1 << IXGBE_ADVTXD_IDX_SHIFT);
6076
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006077 /*
6078 * Check Context must be set if Tx switch is enabled, which it
6079 * always is for case where virtual functions are running
6080 */
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006081#ifdef IXGBE_FCOE
6082 if (tx_flags & (IXGBE_TX_FLAGS_TXSW | IXGBE_TX_FLAGS_FCOE))
6083#else
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006084 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
Alexander Duyck93f5b3c2012-02-08 07:50:45 +00006085#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006086 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6087
Alexander Duyck729739b2012-02-08 07:51:06 +00006088 tx_desc->read.olinfo_status = olinfo_status;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006089}
6090
6091#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6092 IXGBE_TXD_CMD_RS)
6093
6094static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006095 struct ixgbe_tx_buffer *first,
Alexander Duyckd3d00232011-07-15 02:31:25 +00006096 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006097{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006098 dma_addr_t dma;
Alexander Duyck729739b2012-02-08 07:51:06 +00006099 struct sk_buff *skb = first->skb;
6100 struct ixgbe_tx_buffer *tx_buffer;
6101 union ixgbe_adv_tx_desc *tx_desc;
6102 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006103 unsigned int data_len = skb->data_len;
6104 unsigned int size = skb_headlen(skb);
Alexander Duyck729739b2012-02-08 07:51:06 +00006105 unsigned int paylen = skb->len - hdr_len;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006106 u32 tx_flags = first->tx_flags;
Alexander Duyck729739b2012-02-08 07:51:06 +00006107 __le32 cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006108 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07006109
Alexander Duyck729739b2012-02-08 07:51:06 +00006110 tx_desc = IXGBE_TX_DESC(tx_ring, i);
6111
6112 ixgbe_tx_olinfo_status(tx_desc, tx_flags, paylen);
6113 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6114
Alexander Duyckd3d00232011-07-15 02:31:25 +00006115#ifdef IXGBE_FCOE
6116 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006117 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006118 size -= sizeof(struct fcoe_crc_eof) - data_len;
6119 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00006120 } else {
6121 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006122 }
Auke Kok9a799d72007-09-15 14:07:45 -07006123 }
6124
Alexander Duyckd3d00232011-07-15 02:31:25 +00006125#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00006126 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
6127 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006128 goto dma_error;
6129
Alexander Duyck729739b2012-02-08 07:51:06 +00006130 /* record length, and DMA address */
6131 dma_unmap_len_set(first, len, size);
6132 dma_unmap_addr_set(first, dma, dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006133
Alexander Duyck729739b2012-02-08 07:51:06 +00006134 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006135
6136 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006137 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00006138 tx_desc->read.cmd_type_len =
6139 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006140
Alexander Duyckd3d00232011-07-15 02:31:25 +00006141 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00006142 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006143 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006144 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006145 i = 0;
6146 }
Alexander Duyck729739b2012-02-08 07:51:06 +00006147
6148 dma += IXGBE_MAX_DATA_PER_TXD;
6149 size -= IXGBE_MAX_DATA_PER_TXD;
6150
6151 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6152 tx_desc->read.olinfo_status = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006153 }
6154
Alexander Duyck729739b2012-02-08 07:51:06 +00006155 if (likely(!data_len))
6156 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006157
Alexander Duyckd3d00232011-07-15 02:31:25 +00006158 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006159
Alexander Duyck729739b2012-02-08 07:51:06 +00006160 i++;
6161 tx_desc++;
6162 if (i == tx_ring->count) {
6163 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
6164 i = 0;
6165 }
Auke Kok9a799d72007-09-15 14:07:45 -07006166
Alexander Duyckd3d00232011-07-15 02:31:25 +00006167#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006168 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006169#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006170 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006171#endif
6172 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006173
Alexander Duyck729739b2012-02-08 07:51:06 +00006174 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
6175 DMA_TO_DEVICE);
6176 if (dma_mapping_error(tx_ring->dev, dma))
Alexander Duyckd3d00232011-07-15 02:31:25 +00006177 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006178
Alexander Duyck729739b2012-02-08 07:51:06 +00006179 tx_buffer = &tx_ring->tx_buffer_info[i];
6180 dma_unmap_len_set(tx_buffer, len, size);
6181 dma_unmap_addr_set(tx_buffer, dma, dma);
6182
6183 tx_desc->read.buffer_addr = cpu_to_le64(dma);
6184 tx_desc->read.olinfo_status = 0;
6185
6186 frag++;
Auke Kok9a799d72007-09-15 14:07:45 -07006187 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006188
Alexander Duyck729739b2012-02-08 07:51:06 +00006189 /* write last descriptor with RS and EOP bits */
6190 cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD);
6191 tx_desc->read.cmd_type_len = cmd_type;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006192
Alexander Duyck091a6242012-02-08 07:51:01 +00006193 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006194
Alexander Duyckd3d00232011-07-15 02:31:25 +00006195 /* set the timestamp */
6196 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006197
6198 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00006199 * Force memory writes to complete before letting h/w know there
6200 * are new descriptors to fetch. (Only applicable for weak-ordered
6201 * memory model archs, such as IA-64).
6202 *
6203 * We also need this memory barrier to make certain all of the
6204 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07006205 */
6206 wmb();
6207
Alexander Duyckd3d00232011-07-15 02:31:25 +00006208 /* set next_to_watch value indicating a packet is present */
6209 first->next_to_watch = tx_desc;
6210
Alexander Duyck729739b2012-02-08 07:51:06 +00006211 i++;
6212 if (i == tx_ring->count)
6213 i = 0;
6214
6215 tx_ring->next_to_use = i;
6216
Alexander Duyckd3d00232011-07-15 02:31:25 +00006217 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006218 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006219
6220 return;
6221dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00006222 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00006223
6224 /* clear dma mappings for failed tx_buffer_info map */
6225 for (;;) {
Alexander Duyck729739b2012-02-08 07:51:06 +00006226 tx_buffer = &tx_ring->tx_buffer_info[i];
6227 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
6228 if (tx_buffer == first)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006229 break;
6230 if (i == 0)
6231 i = tx_ring->count;
6232 i--;
6233 }
6234
Alexander Duyckd3d00232011-07-15 02:31:25 +00006235 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006236}
6237
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006238static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00006239 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006240{
Alexander Duyck69830522011-01-06 14:29:58 +00006241 struct ixgbe_q_vector *q_vector = ring->q_vector;
6242 union ixgbe_atr_hash_dword input = { .dword = 0 };
6243 union ixgbe_atr_hash_dword common = { .dword = 0 };
6244 union {
6245 unsigned char *network;
6246 struct iphdr *ipv4;
6247 struct ipv6hdr *ipv6;
6248 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006249 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006250 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006251
Alexander Duyck69830522011-01-06 14:29:58 +00006252 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6253 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006254 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006255
Alexander Duyck69830522011-01-06 14:29:58 +00006256 /* do nothing if sampling is disabled */
6257 if (!ring->atr_sample_rate)
6258 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006259
Alexander Duyck69830522011-01-06 14:29:58 +00006260 ring->atr_count++;
6261
6262 /* snag network header to get L4 type and address */
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006263 hdr.network = skb_network_header(first->skb);
Alexander Duyck69830522011-01-06 14:29:58 +00006264
6265 /* Currently only IPv4/IPv6 with TCP is supported */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006266 if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006267 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
Alexander Duyck244e27a2012-02-08 07:51:11 +00006268 (first->protocol != __constant_htons(ETH_P_IP) ||
Alexander Duyck69830522011-01-06 14:29:58 +00006269 hdr.ipv4->protocol != IPPROTO_TCP))
6270 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006271
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006272 th = tcp_hdr(first->skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006273
Alexander Duyck66f32a82011-06-29 05:43:22 +00006274 /* skip this packet since it is invalid or the socket is closing */
6275 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006276 return;
6277
6278 /* sample on all syn packets or once every atr sample count */
6279 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6280 return;
6281
6282 /* reset sample count */
6283 ring->atr_count = 0;
6284
Alexander Duyck244e27a2012-02-08 07:51:11 +00006285 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00006286
6287 /*
6288 * src and dst are inverted, think how the receiver sees them
6289 *
6290 * The input is broken into two sections, a non-compressed section
6291 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6292 * is XORed together and stored in the compressed dword.
6293 */
6294 input.formatted.vlan_id = vlan_id;
6295
6296 /*
6297 * since src port and flex bytes occupy the same word XOR them together
6298 * and write the value to source port portion of compressed dword
6299 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006300 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006301 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6302 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00006303 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00006304 common.port.dst ^= th->source;
6305
Alexander Duyck244e27a2012-02-08 07:51:11 +00006306 if (first->protocol == __constant_htons(ETH_P_IP)) {
Alexander Duyck69830522011-01-06 14:29:58 +00006307 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6308 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6309 } else {
6310 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6311 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6312 hdr.ipv6->saddr.s6_addr32[1] ^
6313 hdr.ipv6->saddr.s6_addr32[2] ^
6314 hdr.ipv6->saddr.s6_addr32[3] ^
6315 hdr.ipv6->daddr.s6_addr32[0] ^
6316 hdr.ipv6->daddr.s6_addr32[1] ^
6317 hdr.ipv6->daddr.s6_addr32[2] ^
6318 hdr.ipv6->daddr.s6_addr32[3];
6319 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006320
6321 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006322 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6323 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006324}
6325
Alexander Duyck63544e92011-05-27 05:31:42 +00006326static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006327{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006328 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006329 /* Herbert's original patch had:
6330 * smp_mb__after_netif_stop_queue();
6331 * but since that doesn't exist yet, just open code it. */
6332 smp_mb();
6333
6334 /* We need to check again in a case another CPU has just
6335 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006336 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006337 return -EBUSY;
6338
6339 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006340 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006341 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006342 return 0;
6343}
6344
Alexander Duyck82d4e462011-06-11 01:44:58 +00006345static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006346{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006347 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006348 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006349 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006350}
6351
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006352static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6353{
6354 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006355 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6356 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006357#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006358 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006359
John Fastabende5b64632011-03-08 03:44:52 +00006360 if (((protocol == htons(ETH_P_FCOE)) ||
6361 (protocol == htons(ETH_P_FIP))) &&
6362 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyckc0876632012-05-10 00:01:46 +00006363 struct ixgbe_ring_feature *f;
6364
6365 f = &adapter->ring_feature[RING_F_FCOE];
6366
6367 while (txq >= f->indices)
6368 txq -= f->indices;
Alexander Duycke4b317e2012-05-05 05:30:53 +00006369 txq += adapter->ring_feature[RING_F_FCOE].offset;
Alexander Duyckc0876632012-05-10 00:01:46 +00006370
John Fastabende5b64632011-03-08 03:44:52 +00006371 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006372 }
6373#endif
6374
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006375 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6376 while (unlikely(txq >= dev->real_num_tx_queues))
6377 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006378 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006379 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006380
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006381 return skb_tx_hash(dev, skb);
6382}
6383
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006384netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006385 struct ixgbe_adapter *adapter,
6386 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006387{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006388 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006389 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006390 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006391#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6392 unsigned short f;
6393#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006394 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006395 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006396 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006397
Alexander Duycka535c302011-05-27 05:31:52 +00006398 /*
6399 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00006400 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00006401 * + 2 desc gap to keep tail from touching head,
6402 * + 1 desc for context descriptor,
6403 * otherwise try next time
6404 */
6405#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6406 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6407 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6408#else
6409 count += skb_shinfo(skb)->nr_frags;
6410#endif
6411 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6412 tx_ring->tx_stats.tx_busy++;
6413 return NETDEV_TX_BUSY;
6414 }
6415
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006416 /* record the location of the first descriptor for this packet */
6417 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6418 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00006419 first->bytecount = skb->len;
6420 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006421
Alexander Duyck66f32a82011-06-29 05:43:22 +00006422 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006423 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006424 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6425 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6426 /* else if it is a SW VLAN check the next protocol and store the tag */
6427 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6428 struct vlan_hdr *vhdr, _vhdr;
6429 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6430 if (!vhdr)
6431 goto out_drop;
6432
6433 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006434 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
6435 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006436 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006437 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006438
Jacob Kelleraa7bd462012-05-04 01:55:23 +00006439 skb_tx_timestamp(skb);
6440
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006441 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
6442 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
6443 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
6444 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006445
Alexander Duyck9e0c5642012-02-08 07:49:33 +00006446#ifdef CONFIG_PCI_IOV
6447 /*
6448 * Use the l2switch_enable flag - would be false if the DMA
6449 * Tx switch had been disabled.
6450 */
6451 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6452 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6453
6454#endif
John Fastabend32701dc2011-09-27 03:51:56 +00006455 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006456 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006457 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6458 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006459 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00006460 tx_flags |= (skb->priority & 0x7) <<
6461 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006462 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6463 struct vlan_ethhdr *vhdr;
6464 if (skb_header_cloned(skb) &&
6465 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6466 goto out_drop;
6467 vhdr = (struct vlan_ethhdr *)skb->data;
6468 vhdr->h_vlan_TCI = htons(tx_flags >>
6469 IXGBE_TX_FLAGS_VLAN_SHIFT);
6470 } else {
6471 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6472 }
6473 }
Alexander Duycka535c302011-05-27 05:31:52 +00006474
Alexander Duyck244e27a2012-02-08 07:51:11 +00006475 /* record initial flags and protocol */
6476 first->tx_flags = tx_flags;
6477 first->protocol = protocol;
6478
Yi Zoueacd73f2009-05-13 13:11:06 +00006479#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006480 /* setup tx offload for FCoE */
6481 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00006482 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00006483 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00006484 if (tso < 0)
6485 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07006486
Alexander Duyck66f32a82011-06-29 05:43:22 +00006487 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006488 }
Auke Kok9a799d72007-09-15 14:07:45 -07006489
Auke Kok9a799d72007-09-15 14:07:45 -07006490#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006491 tso = ixgbe_tso(tx_ring, first, &hdr_len);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006492 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006493 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00006494 else if (!tso)
6495 ixgbe_tx_csum(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006496
6497 /* add the ATR filter if ATR is on */
6498 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00006499 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00006500
6501#ifdef IXGBE_FCOE
6502xmit_fcoe:
6503#endif /* IXGBE_FCOE */
Alexander Duyck244e27a2012-02-08 07:51:11 +00006504 ixgbe_tx_map(tx_ring, first, hdr_len);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006505
6506 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006507
6508 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006509
6510out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00006511 dev_kfree_skb_any(first->skb);
6512 first->skb = NULL;
6513
Alexander Duyck897ab152011-05-27 05:31:47 +00006514 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006515}
6516
Alexander Duycka50c29d2012-02-08 07:50:40 +00006517static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
6518 struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006519{
6520 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006521 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07006522
Alexander Duycka50c29d2012-02-08 07:50:40 +00006523 /*
6524 * The minimum packet size for olinfo paylen is 17 so pad the skb
6525 * in order to meet this minimum size requirement.
6526 */
Stephen Hemmingerf73332f2012-06-21 02:15:10 +00006527 if (unlikely(skb->len < 17)) {
6528 if (skb_pad(skb, 17 - skb->len))
Alexander Duycka50c29d2012-02-08 07:50:40 +00006529 return NETDEV_TX_OK;
6530 skb->len = 17;
Tushar Dave71a49f72012-09-14 04:24:49 +00006531 skb_set_tail_pointer(skb, 17);
Alexander Duycka50c29d2012-02-08 07:50:40 +00006532 }
6533
Auke Kok9a799d72007-09-15 14:07:45 -07006534 tx_ring = adapter->tx_ring[skb->queue_mapping];
6535 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6536}
6537
6538/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006539 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Auke Kok9a799d72007-09-15 14:07:45 -07006540 * @netdev: network interface device structure
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006541 * @p: pointer to an address structure
6542 *
Auke Kok9a799d72007-09-15 14:07:45 -07006543 * Returns 0 on success, negative on failure
6544 **/
6545static int ixgbe_set_mac(struct net_device *netdev, void *p)
6546{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006547 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6548 struct ixgbe_hw *hw = &adapter->hw;
6549 struct sockaddr *addr = p;
6550
6551 if (!is_valid_ether_addr(addr->sa_data))
6552 return -EADDRNOTAVAIL;
6553
6554 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6555 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6556
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00006557 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006558
6559 return 0;
6560}
6561
Ben Hutchings6b73e102009-04-29 08:08:58 +00006562static int
6563ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6564{
6565 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6566 struct ixgbe_hw *hw = &adapter->hw;
6567 u16 value;
6568 int rc;
6569
6570 if (prtad != hw->phy.mdio.prtad)
6571 return -EINVAL;
6572 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6573 if (!rc)
6574 rc = value;
6575 return rc;
6576}
6577
6578static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6579 u16 addr, u16 value)
6580{
6581 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6582 struct ixgbe_hw *hw = &adapter->hw;
6583
6584 if (prtad != hw->phy.mdio.prtad)
6585 return -EINVAL;
6586 return hw->phy.ops.write_reg(hw, addr, devad, value);
6587}
6588
6589static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6590{
6591 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6592
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006593 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006594 case SIOCSHWTSTAMP:
6595 return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00006596 default:
6597 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6598 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00006599}
6600
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006601/**
6602 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006603 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006604 * @netdev: network interface device structure
6605 *
6606 * Returns non-zero on failure
6607 **/
6608static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6609{
6610 int err = 0;
6611 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006612 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006613
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006614 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006615 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006616 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006617 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00006618
6619 /* update SAN MAC vmdq pool selection */
6620 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006621 }
6622 return err;
6623}
6624
6625/**
6626 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006627 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006628 * @netdev: network interface device structure
6629 *
6630 * Returns non-zero on failure
6631 **/
6632static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6633{
6634 int err = 0;
6635 struct ixgbe_adapter *adapter = netdev_priv(dev);
6636 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6637
6638 if (is_valid_ether_addr(mac->san_addr)) {
6639 rtnl_lock();
6640 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6641 rtnl_unlock();
6642 }
6643 return err;
6644}
6645
Auke Kok9a799d72007-09-15 14:07:45 -07006646#ifdef CONFIG_NET_POLL_CONTROLLER
6647/*
6648 * Polling 'interrupt' - used by things like netconsole to send skbs
6649 * without having to re-enable interrupts. It's not called while
6650 * the interrupt routine is executing.
6651 */
6652static void ixgbe_netpoll(struct net_device *netdev)
6653{
6654 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006655 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006656
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006657 /* if interface is down do nothing */
6658 if (test_bit(__IXGBE_DOWN, &adapter->state))
6659 return;
6660
Auke Kok9a799d72007-09-15 14:07:45 -07006661 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006662 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006663 for (i = 0; i < adapter->num_q_vectors; i++)
6664 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006665 } else {
6666 ixgbe_intr(adapter->pdev->irq, netdev);
6667 }
Auke Kok9a799d72007-09-15 14:07:45 -07006668 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07006669}
Auke Kok9a799d72007-09-15 14:07:45 -07006670
Alexander Duyck581330b2012-02-08 07:51:47 +00006671#endif
Eric Dumazetde1036b2010-10-20 23:00:04 +00006672static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6673 struct rtnl_link_stats64 *stats)
6674{
6675 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6676 int i;
6677
Eric Dumazet1a515022010-11-16 19:26:42 -08006678 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006679 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006680 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006681 u64 bytes, packets;
6682 unsigned int start;
6683
Eric Dumazet1a515022010-11-16 19:26:42 -08006684 if (ring) {
6685 do {
6686 start = u64_stats_fetch_begin_bh(&ring->syncp);
6687 packets = ring->stats.packets;
6688 bytes = ring->stats.bytes;
6689 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6690 stats->rx_packets += packets;
6691 stats->rx_bytes += bytes;
6692 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00006693 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00006694
6695 for (i = 0; i < adapter->num_tx_queues; i++) {
6696 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
6697 u64 bytes, packets;
6698 unsigned int start;
6699
6700 if (ring) {
6701 do {
6702 start = u64_stats_fetch_begin_bh(&ring->syncp);
6703 packets = ring->stats.packets;
6704 bytes = ring->stats.bytes;
6705 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6706 stats->tx_packets += packets;
6707 stats->tx_bytes += bytes;
6708 }
6709 }
Eric Dumazet1a515022010-11-16 19:26:42 -08006710 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006711 /* following stats updated by ixgbe_watchdog_task() */
6712 stats->multicast = netdev->stats.multicast;
6713 stats->rx_errors = netdev->stats.rx_errors;
6714 stats->rx_length_errors = netdev->stats.rx_length_errors;
6715 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
6716 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
6717 return stats;
6718}
6719
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006720#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006721/**
6722 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
6723 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00006724 * @tc: number of traffic classes currently enabled
6725 *
6726 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
6727 * 802.1Q priority maps to a packet buffer that exists.
6728 */
6729static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
6730{
6731 struct ixgbe_hw *hw = &adapter->hw;
6732 u32 reg, rsave;
6733 int i;
6734
6735 /* 82598 have a static priority to TC mapping that can not
6736 * be changed so no validation is needed.
6737 */
6738 if (hw->mac.type == ixgbe_mac_82598EB)
6739 return;
6740
6741 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
6742 rsave = reg;
6743
6744 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
6745 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
6746
6747 /* If up2tc is out of bounds default to zero */
6748 if (up2tc > tc)
6749 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
6750 }
6751
6752 if (reg != rsave)
6753 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
6754
6755 return;
6756}
6757
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006758/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00006759 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
6760 * @adapter: Pointer to adapter struct
6761 *
6762 * Populate the netdev user priority to tc map
6763 */
6764static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
6765{
6766 struct net_device *dev = adapter->netdev;
6767 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
6768 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
6769 u8 prio;
6770
6771 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
6772 u8 tc = 0;
6773
6774 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
6775 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
6776 else if (ets)
6777 tc = ets->prio_tc[prio];
6778
6779 netdev_set_prio_tc_map(dev, prio, tc);
6780 }
6781}
6782
6783/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006784 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00006785 *
6786 * @netdev: net device to configure
6787 * @tc: number of traffic classes to enable
6788 */
6789int ixgbe_setup_tc(struct net_device *dev, u8 tc)
6790{
John Fastabend8b1c0b22011-05-03 02:26:48 +00006791 struct ixgbe_adapter *adapter = netdev_priv(dev);
6792 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00006793
John Fastabend8b1c0b22011-05-03 02:26:48 +00006794 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00006795 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
Alexander Duyck581330b2012-02-08 07:51:47 +00006796 (hw->mac.type == ixgbe_mac_82598EB &&
6797 tc < MAX_TRAFFIC_CLASS))
John Fastabend8b1c0b22011-05-03 02:26:48 +00006798 return -EINVAL;
6799
6800 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006801 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00006802 * hardware is not flexible enough to do this dynamically.
6803 */
6804 if (netif_running(dev))
6805 ixgbe_close(dev);
6806 ixgbe_clear_interrupt_scheme(adapter);
6807
John Fastabende7589ea2011-07-18 22:38:36 +00006808 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006809 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006810 ixgbe_set_prio_tc_map(adapter);
6811
John Fastabende7589ea2011-07-18 22:38:36 +00006812 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006813
Alexander Duyck943561d2012-05-09 22:14:44 -07006814 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
6815 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006816 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07006817 }
John Fastabende7589ea2011-07-18 22:38:36 +00006818 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00006819 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00006820
Alexander Duyck943561d2012-05-09 22:14:44 -07006821 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6822 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00006823
6824 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00006825
6826 adapter->temp_dcb_cfg.pfc_mode_enable = false;
6827 adapter->dcb_cfg.pfc_mode_enable = false;
6828 }
6829
John Fastabend8b1c0b22011-05-03 02:26:48 +00006830 ixgbe_init_interrupt_scheme(adapter);
6831 ixgbe_validate_rtr(adapter, tc);
6832 if (netif_running(dev))
6833 ixgbe_open(dev);
6834
6835 return 0;
6836}
Eric Dumazetde1036b2010-10-20 23:00:04 +00006837
Jeff Kirsher8af3c332012-02-18 07:08:14 +00006838#endif /* CONFIG_IXGBE_DCB */
Don Skidmore082757a2011-07-21 05:55:00 +00006839void ixgbe_do_reset(struct net_device *netdev)
6840{
6841 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6842
6843 if (netif_running(netdev))
6844 ixgbe_reinit_locked(adapter);
6845 else
6846 ixgbe_reset(adapter);
6847}
6848
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006849static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006850 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006851{
6852 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6853
Don Skidmore082757a2011-07-21 05:55:00 +00006854 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006855 if (!(features & NETIF_F_RXCSUM))
6856 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00006857
Alexander Duyck567d2de2012-02-11 07:18:57 +00006858 /* Turn off LRO if not RSC capable */
6859 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
6860 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00006861
Alexander Duyck567d2de2012-02-11 07:18:57 +00006862 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00006863}
6864
Michał Mirosławc8f44af2011-11-15 15:29:55 +00006865static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00006866 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00006867{
6868 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00006869 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00006870 bool need_reset = false;
6871
Don Skidmore082757a2011-07-21 05:55:00 +00006872 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00006873 if (!(features & NETIF_F_LRO)) {
6874 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00006875 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00006876 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
6877 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
6878 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
6879 if (adapter->rx_itr_setting == 1 ||
6880 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
6881 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
6882 need_reset = true;
6883 } else if ((changed ^ features) & NETIF_F_LRO) {
6884 e_info(probe, "rx-usecs set too low, "
6885 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00006886 }
6887 }
6888
6889 /*
6890 * Check if Flow Director n-tuple support was enabled or disabled. If
6891 * the state changed, we need to reset.
6892 */
Alexander Duyck39cb6812012-06-06 05:38:20 +00006893 switch (features & NETIF_F_NTUPLE) {
6894 case NETIF_F_NTUPLE:
Alexander Duyck567d2de2012-02-11 07:18:57 +00006895 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00006896 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
6897 need_reset = true;
6898
Alexander Duyck567d2de2012-02-11 07:18:57 +00006899 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
6900 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
Alexander Duyck39cb6812012-06-06 05:38:20 +00006901 break;
6902 default:
6903 /* turn off perfect filters, enable ATR and reset */
6904 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
6905 need_reset = true;
6906
6907 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
6908
6909 /* We cannot enable ATR if SR-IOV is enabled */
6910 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6911 break;
6912
6913 /* We cannot enable ATR if we have 2 or more traffic classes */
6914 if (netdev_get_num_tc(netdev) > 1)
6915 break;
6916
6917 /* We cannot enable ATR if RSS is disabled */
6918 if (adapter->ring_feature[RING_F_RSS].limit <= 1)
6919 break;
6920
6921 /* A sample rate of 0 indicates ATR disabled */
6922 if (!adapter->atr_sample_rate)
6923 break;
6924
6925 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
6926 break;
Don Skidmore082757a2011-07-21 05:55:00 +00006927 }
6928
John Fastabend146d4cc2012-05-15 05:59:26 +00006929 if (features & NETIF_F_HW_VLAN_RX)
6930 ixgbe_vlan_strip_enable(adapter);
6931 else
6932 ixgbe_vlan_strip_disable(adapter);
6933
Ben Greear3f2d1c02012-03-08 08:28:41 +00006934 if (changed & NETIF_F_RXALL)
6935 need_reset = true;
6936
Alexander Duyck567d2de2012-02-11 07:18:57 +00006937 netdev->features = features;
Don Skidmore082757a2011-07-21 05:55:00 +00006938 if (need_reset)
6939 ixgbe_do_reset(netdev);
6940
6941 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00006942}
6943
stephen hemmingeredc7d572012-10-01 12:32:33 +00006944static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006945 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00006946 const unsigned char *addr,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006947 u16 flags)
6948{
6949 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend95447462012-05-31 12:42:26 +00006950 int err;
6951
6952 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
6953 return -EOPNOTSUPP;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006954
John Fastabendb1ac1ef2012-11-01 05:00:44 +00006955 /* Hardware does not support aging addresses so if a
6956 * ndm_state is given only allow permanent addresses
6957 */
6958 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006959 pr_info("%s: FDB only supports static addresses\n",
6960 ixgbe_driver_name);
6961 return -EINVAL;
6962 }
6963
Ben Hutchings46acc462012-11-01 09:11:11 +00006964 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
John Fastabend95447462012-05-31 12:42:26 +00006965 u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS;
6966
6967 if (netdev_uc_count(dev) < rar_uc_entries)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006968 err = dev_uc_add_excl(dev, addr);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006969 else
John Fastabend95447462012-05-31 12:42:26 +00006970 err = -ENOMEM;
6971 } else if (is_multicast_ether_addr(addr)) {
6972 err = dev_mc_add_excl(dev, addr);
6973 } else {
6974 err = -EINVAL;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006975 }
6976
6977 /* Only return duplicate errors if NLM_F_EXCL is set */
6978 if (err == -EEXIST && !(flags & NLM_F_EXCL))
6979 err = 0;
6980
6981 return err;
6982}
6983
6984static int ixgbe_ndo_fdb_del(struct ndmsg *ndm,
6985 struct net_device *dev,
stephen hemminger6b6e2722012-09-17 10:03:26 +00006986 const unsigned char *addr)
John Fastabend0f4b0ad2012-04-15 06:44:19 +00006987{
6988 struct ixgbe_adapter *adapter = netdev_priv(dev);
6989 int err = -EOPNOTSUPP;
6990
6991 if (ndm->ndm_state & NUD_PERMANENT) {
6992 pr_info("%s: FDB only supports static addresses\n",
6993 ixgbe_driver_name);
6994 return -EINVAL;
6995 }
6996
6997 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
6998 if (is_unicast_ether_addr(addr))
6999 err = dev_uc_del(dev, addr);
7000 else if (is_multicast_ether_addr(addr))
7001 err = dev_mc_del(dev, addr);
7002 else
7003 err = -EINVAL;
7004 }
7005
7006 return err;
7007}
7008
7009static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,
7010 struct netlink_callback *cb,
7011 struct net_device *dev,
7012 int idx)
7013{
7014 struct ixgbe_adapter *adapter = netdev_priv(dev);
7015
7016 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7017 idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
7018
7019 return idx;
7020}
7021
John Fastabend815cccb2012-10-24 08:13:09 +00007022static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7023 struct nlmsghdr *nlh)
7024{
7025 struct ixgbe_adapter *adapter = netdev_priv(dev);
7026 struct nlattr *attr, *br_spec;
7027 int rem;
7028
7029 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7030 return -EOPNOTSUPP;
7031
7032 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7033
7034 nla_for_each_nested(attr, br_spec, rem) {
7035 __u16 mode;
7036 u32 reg = 0;
7037
7038 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7039 continue;
7040
7041 mode = nla_get_u16(attr);
7042 if (mode == BRIDGE_MODE_VEPA)
7043 reg = 0;
7044 else if (mode == BRIDGE_MODE_VEB)
7045 reg = IXGBE_PFDTXGSWC_VT_LBEN;
7046 else
7047 return -EINVAL;
7048
7049 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg);
7050
7051 e_info(drv, "enabling bridge mode: %s\n",
7052 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
7053 }
7054
7055 return 0;
7056}
7057
7058static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
7059 struct net_device *dev)
7060{
7061 struct ixgbe_adapter *adapter = netdev_priv(dev);
7062 u16 mode;
7063
7064 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
7065 return 0;
7066
7067 if (IXGBE_READ_REG(&adapter->hw, IXGBE_PFDTXGSWC) & 1)
7068 mode = BRIDGE_MODE_VEB;
7069 else
7070 mode = BRIDGE_MODE_VEPA;
7071
7072 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
7073}
7074
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007075static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007076 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007077 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007078 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007079 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +00007080 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007081 .ndo_validate_addr = eth_validate_addr,
7082 .ndo_set_mac_address = ixgbe_set_mac,
7083 .ndo_change_mtu = ixgbe_change_mtu,
7084 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007085 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7086 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007087 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007088 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7089 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7090 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +00007091 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007092 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007093 .ndo_get_stats64 = ixgbe_get_stats64,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007094#ifdef CONFIG_IXGBE_DCB
John Fastabend24095aa2011-02-23 05:58:03 +00007095 .ndo_setup_tc = ixgbe_setup_tc,
Jeff Kirsher8af3c332012-02-18 07:08:14 +00007096#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007097#ifdef CONFIG_NET_POLL_CONTROLLER
7098 .ndo_poll_controller = ixgbe_netpoll,
7099#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007100#ifdef IXGBE_FCOE
7101 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007102 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007103 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007104 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7105 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007106 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007107 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007108#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007109 .ndo_set_features = ixgbe_set_features,
7110 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00007111 .ndo_fdb_add = ixgbe_ndo_fdb_add,
7112 .ndo_fdb_del = ixgbe_ndo_fdb_del,
7113 .ndo_fdb_dump = ixgbe_ndo_fdb_dump,
John Fastabend815cccb2012-10-24 08:13:09 +00007114 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
7115 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007116};
7117
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007118/**
Jacob Keller8e2813f2012-04-21 06:05:40 +00007119 * ixgbe_wol_supported - Check whether device supports WoL
7120 * @hw: hw specific details
7121 * @device_id: the device ID
7122 * @subdev_id: the subsystem device ID
7123 *
7124 * This function is used by probe and ethtool to determine
7125 * which devices have WoL support
7126 *
7127 **/
7128int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
7129 u16 subdevice_id)
7130{
7131 struct ixgbe_hw *hw = &adapter->hw;
7132 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7133 int is_wol_supported = 0;
7134
7135 switch (device_id) {
7136 case IXGBE_DEV_ID_82599_SFP:
7137 /* Only these subdevices could supports WOL */
7138 switch (subdevice_id) {
7139 case IXGBE_SUBDEV_ID_82599_560FLR:
7140 /* only support first port */
7141 if (hw->bus.func != 0)
7142 break;
7143 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +00007144 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +00007145 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007146 is_wol_supported = 1;
7147 break;
7148 }
7149 break;
7150 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7151 /* All except this subdevice support WOL */
7152 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7153 is_wol_supported = 1;
7154 break;
7155 case IXGBE_DEV_ID_82599_KX4:
7156 is_wol_supported = 1;
7157 break;
7158 case IXGBE_DEV_ID_X540T:
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +00007159 case IXGBE_DEV_ID_X540T1:
Jacob Keller8e2813f2012-04-21 06:05:40 +00007160 /* check eeprom to see if enabled wol */
7161 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7162 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7163 (hw->bus.func == 0))) {
7164 is_wol_supported = 1;
7165 }
7166 break;
7167 }
7168
7169 return is_wol_supported;
7170}
7171
7172/**
Auke Kok9a799d72007-09-15 14:07:45 -07007173 * ixgbe_probe - Device Initialization Routine
7174 * @pdev: PCI device information struct
7175 * @ent: entry in ixgbe_pci_tbl
7176 *
7177 * Returns 0 on success, negative on failure
7178 *
7179 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7180 * The OS initialization, configuring of the adapter private structure,
7181 * and a hardware reset occur.
7182 **/
7183static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007184 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007185{
7186 struct net_device *netdev;
7187 struct ixgbe_adapter *adapter = NULL;
7188 struct ixgbe_hw *hw;
7189 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007190 static int cards_found;
7191 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007192 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007193 unsigned int indices = num_possible_cpus();
John Fastabend3f4a6f02012-06-05 05:58:52 +00007194 unsigned int dcb_max = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00007195#ifdef IXGBE_FCOE
7196 u16 device_caps;
7197#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007198 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007199
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007200 /* Catch broken hardware that put the wrong VF device ID in
7201 * the PCIe SR-IOV capability.
7202 */
7203 if (pdev->is_virtfn) {
7204 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7205 pci_name(pdev), pdev->vendor, pdev->device);
7206 return -EINVAL;
7207 }
7208
gouji-new9ce77662009-05-06 10:44:45 +00007209 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007210 if (err)
7211 return err;
7212
Nick Nunley1b507732010-04-27 13:10:27 +00007213 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7214 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007215 pci_using_dac = 1;
7216 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007217 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007218 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007219 err = dma_set_coherent_mask(&pdev->dev,
7220 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007221 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007222 dev_err(&pdev->dev,
7223 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007224 goto err_dma;
7225 }
7226 }
7227 pci_using_dac = 0;
7228 }
7229
gouji-new9ce77662009-05-06 10:44:45 +00007230 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007231 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007232 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007233 dev_err(&pdev->dev,
7234 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007235 goto err_pci_reg;
7236 }
7237
Frans Pop19d5afd2009-10-02 10:04:12 -07007238 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007239
Auke Kok9a799d72007-09-15 14:07:45 -07007240 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007241 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007242
John Fastabende901acd2011-04-26 07:26:08 +00007243#ifdef CONFIG_IXGBE_DCB
John Fastabend3f4a6f02012-06-05 05:58:52 +00007244 if (ii->mac == ixgbe_mac_82598EB)
7245 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7246 IXGBE_MAX_RSS_INDICES);
7247 else
7248 dcb_max = min_t(unsigned int, indices * MAX_TRAFFIC_CLASS,
7249 IXGBE_MAX_FDIR_INDICES);
John Fastabende901acd2011-04-26 07:26:08 +00007250#endif
7251
John Fastabendc85a2612010-02-25 23:15:21 +00007252 if (ii->mac == ixgbe_mac_82598EB)
7253 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7254 else
7255 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7256
John Fastabende901acd2011-04-26 07:26:08 +00007257#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007258 indices += min_t(unsigned int, num_possible_cpus(),
7259 IXGBE_MAX_FCOE_INDICES);
7260#endif
John Fastabend3f4a6f02012-06-05 05:58:52 +00007261 indices = max_t(unsigned int, dcb_max, indices);
John Fastabendc85a2612010-02-25 23:15:21 +00007262 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007263 if (!netdev) {
7264 err = -ENOMEM;
7265 goto err_alloc_etherdev;
7266 }
7267
Auke Kok9a799d72007-09-15 14:07:45 -07007268 SET_NETDEV_DEV(netdev, &pdev->dev);
7269
Auke Kok9a799d72007-09-15 14:07:45 -07007270 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007271 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007272
7273 adapter->netdev = netdev;
7274 adapter->pdev = pdev;
7275 hw = &adapter->hw;
7276 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +00007277 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -07007278
Jeff Kirsher05857982008-09-11 19:57:00 -07007279 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007280 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007281 if (!hw->hw_addr) {
7282 err = -EIO;
7283 goto err_ioremap;
7284 }
7285
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007286 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007287 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007288 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007289 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007290
Auke Kok9a799d72007-09-15 14:07:45 -07007291 adapter->bd_number = cards_found;
7292
Auke Kok9a799d72007-09-15 14:07:45 -07007293 /* Setup hw api */
7294 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007295 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007296
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007297 /* EEPROM */
7298 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7299 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7300 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7301 if (!(eec & (1 << 8)))
7302 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7303
7304 /* PHY */
7305 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007306 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007307 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7308 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7309 hw->phy.mdio.mmds = 0;
7310 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7311 hw->phy.mdio.dev = netdev;
7312 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7313 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007314
Don Skidmore8ca783a2009-05-26 20:40:47 -07007315 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007316
7317 /* setup the private structure */
7318 err = ixgbe_sw_init(adapter);
7319 if (err)
7320 goto err_sw_init;
7321
Don Skidmoree86bff02010-02-11 04:14:08 +00007322 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007323 switch (adapter->hw.mac.type) {
7324 case ixgbe_mac_82599EB:
7325 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007326 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007327 break;
7328 default:
7329 break;
7330 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007331
Don Skidmorebf069c92009-05-07 10:39:54 +00007332 /*
7333 * If there is a fan on this device and it has failed log the
7334 * failure.
7335 */
7336 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7337 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7338 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007339 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007340 }
7341
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007342 if (allow_unsupported_sfp)
7343 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7344
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007345 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007346 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007347 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007348 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007349 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7350 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007351 err = 0;
7352 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007353 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007354 "module type was detected.\n");
7355 e_dev_err("Reload the driver after installing a supported "
7356 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007357 goto err_sw_init;
7358 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007359 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007360 goto err_sw_init;
7361 }
7362
Alexander Duyck99d74482012-05-09 08:09:25 +00007363#ifdef CONFIG_PCI_IOV
7364 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007365
Alexander Duyck99d74482012-05-09 08:09:25 +00007366#endif
Emil Tantilov396e7992010-07-01 20:05:12 +00007367 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007368 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007369 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007370 NETIF_F_HW_VLAN_TX |
7371 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007372 NETIF_F_HW_VLAN_FILTER |
7373 NETIF_F_TSO |
7374 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007375 NETIF_F_RXHASH |
7376 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007377
Don Skidmore082757a2011-07-21 05:55:00 +00007378 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007379
Don Skidmore58be7662011-04-12 09:42:11 +00007380 switch (adapter->hw.mac.type) {
7381 case ixgbe_mac_82599EB:
7382 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007383 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007384 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7385 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007386 break;
7387 default:
7388 break;
7389 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007390
Ben Greear3f2d1c02012-03-08 08:28:41 +00007391 netdev->hw_features |= NETIF_F_RXALL;
7392
Jeff Kirsherad31c402008-06-05 04:05:30 -07007393 netdev->vlan_features |= NETIF_F_TSO;
7394 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007395 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007396 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007397 netdev->vlan_features |= NETIF_F_SG;
7398
Jiri Pirko01789342011-08-16 06:29:00 +00007399 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +00007400 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +00007401
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007402#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007403 netdev->dcbnl_ops = &dcbnl_ops;
7404#endif
7405
Yi Zoueacd73f2009-05-13 13:11:06 +00007406#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007407 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007408 if (hw->mac.ops.get_device_caps) {
7409 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007410 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7411 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007412 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007413
7414 adapter->ring_feature[RING_F_FCOE].limit = IXGBE_FCRETA_SIZE;
7415
Alexander Duycka58915c2012-05-25 06:38:18 +00007416 netdev->features |= NETIF_F_FSO |
7417 NETIF_F_FCOE_CRC;
7418
Alexander Duyck7c8ae652012-05-05 05:32:47 +00007419 netdev->vlan_features |= NETIF_F_FSO |
7420 NETIF_F_FCOE_CRC |
7421 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +00007422 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007423#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007424 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007425 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007426 netdev->vlan_features |= NETIF_F_HIGHDMA;
7427 }
Auke Kok9a799d72007-09-15 14:07:45 -07007428
Don Skidmore082757a2011-07-21 05:55:00 +00007429 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7430 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007431 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007432 netdev->features |= NETIF_F_LRO;
7433
Auke Kok9a799d72007-09-15 14:07:45 -07007434 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007435 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007436 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007437 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007438 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007439 }
7440
7441 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7442 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7443
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007444 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007445 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007446 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +00007447 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007448 }
7449
Alexander Duyck70864002011-04-27 09:13:56 +00007450 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
Alexander Duyck581330b2012-02-08 07:51:47 +00007451 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007452
Alexander Duyck70864002011-04-27 09:13:56 +00007453 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7454 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007455
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007456 err = ixgbe_init_interrupt_scheme(adapter);
7457 if (err)
7458 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007459
Jacob Keller8e2813f2012-04-21 06:05:40 +00007460 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007461 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +00007462 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7463 if (ixgbe_wol_supported(adapter, pdev->device, pdev->subsystem_device))
Andy Gospodarek9417c462011-07-16 07:31:33 +00007464 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007465
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007466 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7467
Emil Tantilov15e52092011-09-29 05:01:29 +00007468 /* save off EEPROM version number */
7469 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7470 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7471
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007472 /* pick up the PCI bus settings for reporting later */
7473 hw->mac.ops.get_bus_info(hw);
7474
Auke Kok9a799d72007-09-15 14:07:45 -07007475 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007476 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007477 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7478 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007479 "Unknown"),
7480 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7481 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7482 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7483 "Unknown"),
7484 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007485
7486 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7487 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007488 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007489 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007490 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007491 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007492 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007493 else
Don Skidmore289700db2010-12-03 03:32:58 +00007494 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7495 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007496
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007497 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007498 e_dev_warn("PCI-Express bandwidth available for this card is "
7499 "not sufficient for optimal performance.\n");
7500 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7501 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007502 }
7503
Auke Kok9a799d72007-09-15 14:07:45 -07007504 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007505 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007506 if (err == IXGBE_ERR_EEPROM_VERSION) {
7507 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007508 e_dev_warn("This device is a pre-production adapter/LOM. "
7509 "Please be aware there may be issues associated "
7510 "with your hardware. If you are experiencing "
7511 "problems please contact your Intel or hardware "
7512 "representative who provided you with this "
7513 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007514 }
Auke Kok9a799d72007-09-15 14:07:45 -07007515 strcpy(netdev->name, "eth%d");
7516 err = register_netdev(netdev);
7517 if (err)
7518 goto err_register;
7519
Emil Tantilovec74a472012-09-20 03:33:56 +00007520 /* power down the optics for 82599 SFP+ fiber */
7521 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007522 hw->mac.ops.disable_tx_laser(hw);
7523
Jesse Brandeburg54386462009-04-17 20:44:27 +00007524 /* carrier off reporting is important to ethtool even BEFORE open */
7525 netif_carrier_off(netdev);
7526
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007527#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007528 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007529 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007530 ixgbe_setup_dca(adapter);
7531 }
7532#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007533 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007534 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007535 for (i = 0; i < adapter->num_vfs; i++)
7536 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7537 }
7538
Jacob Keller2466dd92011-09-08 03:50:54 +00007539 /* firmware requires driver version to be 0xFFFFFFFF
7540 * since os does not support feature
7541 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007542 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007543 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7544 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007545
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007546 /* add san mac addr to netdev */
7547 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007548
Neerav Parikhea818752012-01-04 20:23:40 +00007549 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007550 cards_found++;
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007551
Don Skidmore12109822012-05-04 06:07:08 +00007552#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007553 if (ixgbe_sysfs_init(adapter))
7554 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +00007555#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007556
Catherine Sullivan00949162012-08-10 01:59:10 +00007557#ifdef CONFIG_DEBUG_FS
7558 ixgbe_dbg_adapter_init(adapter);
7559#endif /* CONFIG_DEBUG_FS */
7560
Auke Kok9a799d72007-09-15 14:07:45 -07007561 return 0;
7562
7563err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007564 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007565 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007566err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +00007567 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007568 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007569 iounmap(hw->hw_addr);
7570err_ioremap:
7571 free_netdev(netdev);
7572err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007573 pci_release_selected_regions(pdev,
7574 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007575err_pci_reg:
7576err_dma:
7577 pci_disable_device(pdev);
7578 return err;
7579}
7580
7581/**
7582 * ixgbe_remove - Device Removal Routine
7583 * @pdev: PCI device information struct
7584 *
7585 * ixgbe_remove is called by the PCI subsystem to alert the driver
7586 * that it should release a PCI device. The could be caused by a
7587 * Hot-Plug event, or because the driver is going to be removed from
7588 * memory.
7589 **/
7590static void __devexit ixgbe_remove(struct pci_dev *pdev)
7591{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007592 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7593 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007594
Catherine Sullivan00949162012-08-10 01:59:10 +00007595#ifdef CONFIG_DEBUG_FS
7596 ixgbe_dbg_adapter_exit(adapter);
7597#endif /*CONFIG_DEBUG_FS */
7598
Auke Kok9a799d72007-09-15 14:07:45 -07007599 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007600 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007601
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007602
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007603#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007604 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7605 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7606 dca_remove_requester(&pdev->dev);
7607 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7608 }
7609
7610#endif
Don Skidmore12109822012-05-04 06:07:08 +00007611#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007612 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +00007613#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +00007614
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007615 /* remove the added san mac */
7616 ixgbe_del_sanmac_netdev(netdev);
7617
Donald Skidmorec4900be2008-11-20 21:11:42 -08007618 if (netdev->reg_state == NETREG_REGISTERED)
7619 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007620
Alexander Duyck92971272012-05-23 02:58:40 +00007621 ixgbe_disable_sriov(adapter);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007622
Alexander Duyck7a921c92009-05-06 10:43:28 +00007623 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007624
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007625 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007626
Alexander Duyck2b1588c2012-03-17 02:39:16 +00007627#ifdef CONFIG_DCB
7628 kfree(adapter->ixgbe_ieee_pfc);
7629 kfree(adapter->ixgbe_ieee_ets);
7630
7631#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007632 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007633 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007634 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007635
Emil Tantilov849c4542010-06-03 16:53:41 +00007636 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007637
Auke Kok9a799d72007-09-15 14:07:45 -07007638 free_netdev(netdev);
7639
Frans Pop19d5afd2009-10-02 10:04:12 -07007640 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007641
Auke Kok9a799d72007-09-15 14:07:45 -07007642 pci_disable_device(pdev);
7643}
7644
7645/**
7646 * ixgbe_io_error_detected - called when PCI error is detected
7647 * @pdev: Pointer to PCI device
7648 * @state: The current pci connection state
7649 *
7650 * This function is called after a PCI bus error affecting
7651 * this device has been detected.
7652 */
7653static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007654 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007655{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007656 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7657 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007658
Greg Rose83c61fa2011-09-07 05:59:35 +00007659#ifdef CONFIG_PCI_IOV
7660 struct pci_dev *bdev, *vfdev;
7661 u32 dw0, dw1, dw2, dw3;
7662 int vf, pos;
7663 u16 req_id, pf_func;
7664
7665 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7666 adapter->num_vfs == 0)
7667 goto skip_bad_vf_detection;
7668
7669 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +08007670 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +00007671 bdev = bdev->bus->self;
7672
7673 if (!bdev)
7674 goto skip_bad_vf_detection;
7675
7676 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
7677 if (!pos)
7678 goto skip_bad_vf_detection;
7679
7680 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
7681 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
7682 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
7683 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
7684
7685 req_id = dw1 >> 16;
7686 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
7687 if (!(req_id & 0x0080))
7688 goto skip_bad_vf_detection;
7689
7690 pf_func = req_id & 0x01;
7691 if ((pf_func & 1) == (pdev->devfn & 1)) {
7692 unsigned int device_id;
7693
7694 vf = (req_id & 0x7F) >> 1;
7695 e_dev_err("VF %d has caused a PCIe error\n", vf);
7696 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
7697 "%8.8x\tdw3: %8.8x\n",
7698 dw0, dw1, dw2, dw3);
7699 switch (adapter->hw.mac.type) {
7700 case ixgbe_mac_82599EB:
7701 device_id = IXGBE_82599_VF_DEVICE_ID;
7702 break;
7703 case ixgbe_mac_X540:
7704 device_id = IXGBE_X540_VF_DEVICE_ID;
7705 break;
7706 default:
7707 device_id = 0;
7708 break;
7709 }
7710
7711 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +00007712 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +00007713 while (vfdev) {
7714 if (vfdev->devfn == (req_id & 0xFF))
7715 break;
Jon Mason36e90312012-07-19 21:02:09 +00007716 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +00007717 device_id, vfdev);
7718 }
7719 /*
7720 * There's a slim chance the VF could have been hot plugged,
7721 * so if it is no longer present we don't need to issue the
7722 * VFLR. Just clean up the AER in that case.
7723 */
7724 if (vfdev) {
7725 e_dev_err("Issuing VFLR to VF %d\n", vf);
7726 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
7727 }
7728
7729 pci_cleanup_aer_uncorrect_error_status(pdev);
7730 }
7731
7732 /*
7733 * Even though the error may have occurred on the other port
7734 * we still need to increment the vf error reference count for
7735 * both ports because the I/O resume function will be called
7736 * for both of them.
7737 */
7738 adapter->vferr_refcount++;
7739
7740 return PCI_ERS_RESULT_RECOVERED;
7741
7742skip_bad_vf_detection:
7743#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07007744 netif_device_detach(netdev);
7745
Breno Leitao3044b8d2009-05-06 10:44:26 +00007746 if (state == pci_channel_io_perm_failure)
7747 return PCI_ERS_RESULT_DISCONNECT;
7748
Auke Kok9a799d72007-09-15 14:07:45 -07007749 if (netif_running(netdev))
7750 ixgbe_down(adapter);
7751 pci_disable_device(pdev);
7752
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007753 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007754 return PCI_ERS_RESULT_NEED_RESET;
7755}
7756
7757/**
7758 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7759 * @pdev: Pointer to PCI device
7760 *
7761 * Restart the card from scratch, as if from a cold-boot.
7762 */
7763static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7764{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007765 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007766 pci_ers_result_t result;
7767 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007768
gouji-new9ce77662009-05-06 10:44:45 +00007769 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007770 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007771 result = PCI_ERS_RESULT_DISCONNECT;
7772 } else {
7773 pci_set_master(pdev);
7774 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007775 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007776
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007777 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007778
7779 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007780 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007781 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007782 }
Auke Kok9a799d72007-09-15 14:07:45 -07007783
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007784 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7785 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007786 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7787 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007788 /* non-fatal, continue */
7789 }
Auke Kok9a799d72007-09-15 14:07:45 -07007790
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007791 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007792}
7793
7794/**
7795 * ixgbe_io_resume - called when traffic can start flowing again.
7796 * @pdev: Pointer to PCI device
7797 *
7798 * This callback is called when the error recovery driver tells us that
7799 * its OK to resume normal operation.
7800 */
7801static void ixgbe_io_resume(struct pci_dev *pdev)
7802{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007803 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7804 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007805
Greg Rose83c61fa2011-09-07 05:59:35 +00007806#ifdef CONFIG_PCI_IOV
7807 if (adapter->vferr_refcount) {
7808 e_info(drv, "Resuming after VF err\n");
7809 adapter->vferr_refcount--;
7810 return;
7811 }
7812
7813#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00007814 if (netif_running(netdev))
7815 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007816
7817 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007818}
7819
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07007820static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -07007821 .error_detected = ixgbe_io_error_detected,
7822 .slot_reset = ixgbe_io_slot_reset,
7823 .resume = ixgbe_io_resume,
7824};
7825
7826static struct pci_driver ixgbe_driver = {
7827 .name = ixgbe_driver_name,
7828 .id_table = ixgbe_pci_tbl,
7829 .probe = ixgbe_probe,
7830 .remove = __devexit_p(ixgbe_remove),
7831#ifdef CONFIG_PM
7832 .suspend = ixgbe_suspend,
7833 .resume = ixgbe_resume,
7834#endif
7835 .shutdown = ixgbe_shutdown,
7836 .err_handler = &ixgbe_err_handler
7837};
7838
7839/**
7840 * ixgbe_init_module - Driver Registration Routine
7841 *
7842 * ixgbe_init_module is the first routine called when the driver is
7843 * loaded. All it does is register with the PCI subsystem.
7844 **/
7845static int __init ixgbe_init_module(void)
7846{
7847 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007848 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007849 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007850
Catherine Sullivan00949162012-08-10 01:59:10 +00007851#ifdef CONFIG_DEBUG_FS
7852 ixgbe_dbg_init();
7853#endif /* CONFIG_DEBUG_FS */
7854
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007855#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007856 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007857#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007858
Auke Kok9a799d72007-09-15 14:07:45 -07007859 ret = pci_register_driver(&ixgbe_driver);
7860 return ret;
7861}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007862
Auke Kok9a799d72007-09-15 14:07:45 -07007863module_init(ixgbe_init_module);
7864
7865/**
7866 * ixgbe_exit_module - Driver Exit Cleanup Routine
7867 *
7868 * ixgbe_exit_module is called just before the driver is removed
7869 * from memory.
7870 **/
7871static void __exit ixgbe_exit_module(void)
7872{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007873#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007874 dca_unregister_notify(&dca_notifier);
7875#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007876 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +00007877
7878#ifdef CONFIG_DEBUG_FS
7879 ixgbe_dbg_exit();
7880#endif /* CONFIG_DEBUG_FS */
7881
Eric Dumazet1a515022010-11-16 19:26:42 -08007882 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007883}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007884
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007885#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007886static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007887 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007888{
7889 int ret_val;
7890
7891 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007892 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007893
7894 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7895}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007896
Alexander Duyckb4533682009-03-31 21:32:42 +00007897#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007898
Auke Kok9a799d72007-09-15 14:07:45 -07007899module_exit(ixgbe_exit_module);
7900
7901/* ixgbe_main.c */